- Print
- PDF
Using WordPress
- Print
- PDF
Available in Classic
Deploy an application to a cluster using Ncloud Kubernetes Service
This document describes how to deploy WordPress to a cluster, using NAVER Cloud Platform Ncloud Kubernetes Service.
Create a cluster
- Log into NAVER Cloud Platform’s Console.
- Select Ncloud Kubernetes Service from the left menu.
- Click Create.
- Complete the steps below:
- Cluster settings
- Cluster name: Enter a name you want.
- Number of nodes: Specify this field to 1 in this guide.
- Login key setting
- Set a login key required to access a worker node.
- Final confirmation
- Confirm the settings and click Create.
- Cluster settings
- You can use the cluster when it becomes Running after several minutes.
For more information, refer to How to Use Kubernetes Service.
Connect to the cluster
Install kubectl
To connect to the created cluster, you need a CLI, kubectl
. Install kubectl for your OS, by referring to the following documents.
- Install kubectl on Linux
- Install kubectl on macOS
- Install kubectl on Windows (Powershell)
- Install kubectl on Windows (Command Prompt)
How to connect to the cluster
Download the configuration file from the cluster details.
There are two ways to connect to a cluster:
- Add the configuration file to $HOME/.kube/config.
- Add the option, --kubeconfig="configuration file", when using the kubectl command.
In this example, we’ll use the --kubeconfig="configuration file"
option. For your convenience, set the $KUBE_CONFIG
environment variable in the path where the configuration file is located. Add the path of the downloaded configuration file to "configuration file"
below.
export KUBE_CONFIG="configuration file"
Example: export KUBE_CONFIG=kubeconfig-318.yaml
Execute kubectl get nodes
to check if the result displays as many cluster nodes as you specified when creating a cluster (1 in this example).
kubectl --kubeconfig $KUBE_CONFIG get nodes
- Result
NAME STATUS ROLES AGE VERSION
nks-pool-318-w-181 Ready node 7m v1.12.7
For how to set the environment variable in Windows, refer to Configure kubeconfig environment variables.
Deploy an application
Using the kubectl command with the Kubernetes Manifest file (.yaml), let’s deploy MySQL and WordPress.
Deploy MySQL
Deploy MySQL required for WordPress, first.
Create a MySQL password secret
Execute kubectl create secret
to create a password to connect to MySQL as a secret. Enter a new password in "YOUR_PASSWORD"
below.
kubectl --kubeconfig $KUBE_CONFIG create secret generic mysql-pass --from-literal=password="YOUR_PASSWORD"
- Result
secret/mysql-pass created
Example) kubectl --kubeconfig $KUBE_CONFIG create secret generic mysql-pass --from-literal=password=1234
Deploy MySQL
To deploy MySQL, use the following manifest file. The manifest file contains PersistentVolume, PersistentVolumeClaim, Deployment, and Service, which are objects required for MySQL.
Execute kubectl apply -f
as show below to apply the manifest file to your cluster.
kubectl --kubeconfig $KUBE_CONFIG apply -f https://gist.githubusercontent.com/NaverCloudPlatformDeveloper/39e63bf8051c2af338bf4728b4336358/raw/1804b7b36eb6818fedf600c73f6b9cf9219529a0/nks-tutorial-mysql.yaml
- Result
persistentvolume/mysql-pv created
persistentvolumeclaim/mysql-pv-claim created
deployment.apps/wordpress-mysql created
service/wordpress-mysql created
When you run a live service, Cloud DB for MySQL is recommended for more stable operation.
Deploy WordPress
After creating MySQL, use the following manifest file to deploy WordPress. The manifest file contains Deployment and Service.
In the same way as MySQL, execute kubectl apply -f
to deploy WordPress.
kubectl --kubeconfig $KUBE_CONFIG apply -f https://gist.githubusercontent.com/NaverCloudPlatformDeveloper/8bb23ccd8310f05d2ef737835d4d1748/raw/d97aa174df6f31d7c4b0de5957fe67c6a2846fe3/nks-tutorial-wordpress.yaml
- Result
deployment.apps/wordpress created
service/wordpress created
Execute kubectl get service --watch
to check the deployment status of WordPress in real time.
kubectl --kubeconfig $KUBE_CONFIG get service wordpress --watch
- Result
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 172.21.5.101 <pending> 80:31864/TCP 35s
wordpress LoadBalancer 172.21.5.101 slb-1815725.n... 80:31864/TCP 40s
When EXTERNAL-IP
is changed to a real address from pending
, the service becomes available. Execute kubectl get service
to check the full address of WordPress EXTERNAL-IP
.
kubectl --kubeconfig $KUBE_CONFIG get service wordpress
- Result
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 172.21.5.101 slb-1815725.ncloudslb.com 80:31864/TCP 70s
Connect to the WordPress service’s EXTERNAL-IP (e.g.: slb-1815725.ncloudslb.com) in your web browser, and you can see the WordPress screen.
Scale pods
Get current pods
Execute kubectl get pods
to check that there are currently one mysql pod and one WordPress pod.
kubectl --kubeconfig $KUBE_CONFIG get pods
- Result
NAME READY STATUS RESTARTS AGE
wordpress-6d884d9866-lj5bl 1/1 Running 0 10m
wordpress-mysql-7977b9588d-gbtll 1/1 Running 0 11m
Scale pods
Execute kubectl scale
to increase the number of WordPress pods to 3.
kubectl --kubeconfig $KUBE_CONFIG scale deployments/wordpress --replicas=3
- Result
deployment.extensions/wordpress scaled
Check results
Execute kubectl get pods
to check if the number of WordPress pods is 3.
kubectl --kubeconfig $KUBE_CONFIG get pods
- Result
NAME READY STATUS RESTARTS AGE
wordpress-6d884d9866-2c8cl 1/1 Running 0 5s
wordpress-6d884d9866-7rxj8 1/1 Running 0 5s
wordpress-6d884d9866-lj5bl 1/1 Running 0 12m
wordpress-mysql-7977b9588d-gbtll 1/1 Running 0 14m
Update WordPress
Update the version of WordPress, from 5.2 to 5.2.2.
Check the current version
Execute kubectl get deployments -o wide
to check the version of the current WordPress image, which is 5.2.
kubectl --kubeconfig $KUBE_CONFIG get deployments wordpress -o wide
- Result
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
wordpress 3 3 3 3 55m wordpress wordpress:5.2-apache app=wordpress,tier=frontend
Update the version
Execute kubectl set image
to update the version of WordPress from 5.2 to 5.2.2.
kubectl --kubeconfig $KUBE_CONFIG set image deployments/wordpress wordpress=wordpress:5.2.2-apache
- Result
deployment.extensions/wordpress image updated
Check results
Execute kubectl get deployments -o wide -w
to check if WordPress is updated in real time.
kubectl --kubeconfig $KUBE_CONFIG get deployments wordpress -o wide -w
- Result
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
wordpress 3 3 3 3 55m wordpress wordpress:5.2-apache app=wordpress,tier=frontend
wordpress 3 3 3 3 56m wordpress wordpress:5.2.2-apache app=wordpress,tier=frontend
After a period of time, you can check that the version of the WordPress image is updated to wordpress:5.2.2-apache.