This blog is written by Balu Dontu and Tushar Thole from Cloud Native Applications Storage team
See Part 1 of the blog: Deploying WordPress-MySQL Application with Persistent Storage
Create deployment with Persistent Volume Claim
Create a MySql deployment
Create a MySql deployment using this resource file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# mysql-deployment.yaml apiVersion: v1 kind: Service metadata: name: wordpress-mysql labels: app: wordpress spec: ports: - port: 3306 selector: app: wordpress tier: mysql clusterIP: None --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: wordpress-mysql labels: app: wordpress spec: strategy: type: Recreate template: metadata: labels: app: wordpress tier: mysql spec: containers: - image: mysql:5.6 name: mysql env: - name: MYSQL_ROOT_PASSWORD value: mysqlpassword ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pv-claim |
Key parts here are:
- Resource defines a Deployment using
mysql
Docker image volumeMounts
define which volumes are going to be mounted./var/lib/mysql
is the directory where sqlDB Server stores all the data.volumes
define different volumes that can be used in this deployment definition. Here we are using mysql-pv-claim.
Create the Deployment as:
1 2 |
kubectl create -f mysql-deployment.yaml deployment "mysql-deployment" created. |
Create a WordPress deployment
Create a WordPress deployment using this resource file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# wordpress-deployment.yaml apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 nodePort: 30080 selector: app: wordpress tier: frontend type: NodePort --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: wordpress labels: app: wordpress spec: strategy: type: Recreate template: metadata: labels: app: wordpress tier: frontend spec: containers: - image: wordpress:4.6.1-apache name: wordpress env: - name: WORDPRESS_DB_HOST value: wordpress-mysql - name: WORDPRESS_DB_PASSWORD value: mysqlpassword ports: - containerPort: 80 name: wordpress volumeMounts: - name: wordpress-persistent-storage mountPath: /var/www/html volumes: - name: wordpress-persistent-storage persistentVolumeClaim: claimName: wp-pv-claim |
Key parts here are:
- Resource defines a Deployment using
wordpress
Docker image volumeMounts
define which volumes are going to be mounted./var/www/html
is the directory where wordpress stores all the data.volumes
define different volumes that can be used in this deployment definition. Here we are using wp-pv-claim.
Create the Deployment as:
1 2 |
kubectl create -f wordpress-deployment.yaml deployment "wordpress-deployment" created. |
Now let’s see where the WordPress pod is deployed.
1 2 |
$ kubectl describe service wordpress | grep -i node node: node4 |
1 2 |
$ kubectl describe service wordpress | grep -i NodePort NodePort: <unset> 30080/TCP |
Just enter this ‘10.160.241.61:30080’ in the browser to visit WordPress blog.
You’ll see the familiar WordPress start page:
As you can see, with just a few additional lines in your storage class YAML, vSphere Cloud Provider enables policy driven dynamic provisioning of Kubernetes persistent volumes. It exposes data services offered by the underlying storage platform such as vSAN at granularity of container volumes and provides applications a complete abstraction of storage infrastructure.
We would love to hear your feedback! We will be at DockerCon. Please drop by at booth G9 to learn more about what we have to offer.
- Contact us at [email protected] or kubernetes channel on VMware Code Slack
- Please visit vSphere documentation to learn about the latest features.
- Please check out vSphere Docker Volume Service that enables persistent storage for Docker Containers in vSphere environment.