This example tutorial describes how to deploy the WordPress application using vSphere Pods in the vSphere IaaS control plane environment.
The WordPress deployment includes containers for the WordPress frontend and the MySQL backend, and services for both. Secret objects are also required.
This tutorial uses a Deployment object. In production environment, you typically use StatefulSets for both WordPress and MySQL containers.
Prerequisites
- Create a one-zone Supervisor with NSX networking. Only one-zone Supervisors with NSX support vSphere Pods. See Deploy a One-Zone Supervisor with NSX Networking
- Create a namespace for deploying vSphere Pods. See Create and Configure a vSphere Namespace on the Supervisor.
- Create a storage policy, for example, vwt-storage-policy and assign it to the namespace.
- Download the vSphere Kubernetes CLI tools. See Download and Install the Kubernetes CLI Tools for vSphere.
- Create YAML files required for this tutorial and verify command line access to the files.
Category Files Storage -
Note: Make sure that the files reference correct storage class.
Secrets Services Deployments
Deploy WordPress
Use this workflow to deploy the WordPress application using vSphere Pods.
Part 1. Access Your Namespace
Use these steps to access your namespace.
Procedure
Part 2. Create WordPress PVCs
Use these commands to create WordPress PVCs.
Procedure
Part 3. Create Secrets
The public Docker Hub is the default container registry for Kubernetes. Docker Hub now limits image pulls. You need to have a paid account and add the account key to the secret YAML in the data.dockerconfigjson
field.
Procedure
Part 4. Create Services
Follow these steps to create services.
Procedure
Part 5. Create Pod Deployments
Use this task to create pod deployments.
Procedure
Part 6. Test WordPress
Follow these steps to test your WordPress deployment.
Procedure
Example YAML Files for the WordPress Deployment
Use these example YAML files when you deploy the WordPress application with vSphere Pods.
mysql-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc labels: app: wordpress spec: accessModes: - ReadWriteOnce storageClassName: vwt-storage-policy resources: requests: storage: 20Gi
wordpress-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wordpress-pvc labels: app: wordpress spec: accessModes: - ReadWriteOnce storageClassName: vwt-storage-policy resources: requests: storage: 20Gi
regcred.yaml
apiVersion: v1 kind: Secret metadata: name: regcred data: .dockerconfigjson: ewoJImF1dGhzIjog....zZG1KcE5WUmtXRUozWpc type: kubernetes.io/dockerconfigjson
mysql-pass.yaml
apiVersion: v1 data: password: YWRtaW4= #admin base64 encoded kind: Secret metadata: name: mysql-pass
mysql-service.yaml
apiVersion: v1 kind: Service metadata: name: wordpress-mysql labels: app: wordpress spec: ports: - port: 3306 selector: app: wordpress tier: mysql clusterIP: None
wordpress-service.yaml
apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 selector: app: wordpress tier: frontend type: LoadBalancer
mysql-deployment-vsphere-pod.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: wordpress-mysql labels: app: wordpress spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: wordpress tier: mysql template: metadata: labels: app: wordpress tier: mysql spec: containers: - image: mysql:5.6 name: mysql #increased resource limits required for this pod vm #default pod VM RAM is 512MB; MySQL container needs more #without extra RAM OOM error prevents deployment #extra RAM not required for Kuberentes cluster resources: limits: memory: 1024Mi cpu: 1 env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pvc imagePullSecrets: - name: regcred
wordpress-deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: wordpress labels: app: wordpress spec: selector: matchLabels: app: wordpress tier: frontend strategy: type: Recreate template: metadata: labels: app: wordpress tier: frontend spec: containers: - image: wordpress:4.8-apache name: wordpress env: - name: WORDPRESS_DB_HOST value: wordpress-mysql - name: WORDPRESS_DB_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password ports: - containerPort: 80 name: wordpress volumeMounts: - name: wordpress-persistent-storage mountPath: /var/www/html volumes: - name: wordpress-persistent-storage persistentVolumeClaim: claimName: wordpress-pvc imagePullSecrets: - name: regcred