You should have an AKS cluster already running from the previous topic.
You can use the cluster to deploy an example application, WordPress.
The yaml files below are a modified version of the Kubernetes WordPress Tutorial in the Kubernetes documentation.
You will use three yaml files to deploy WordPress on your AKS cluster:
kustomization.yaml
mysql-deployment.yaml
wordpress-deployment.yaml
kustomization.yaml
with the code below:
secretGenerator:
- name: mysql-pass
literals:
- password=YourPasswordHere
resources:
- mysql-deployment.yaml
- wordpress-deployment.yaml
mysql-deployment.yaml
with the code below:
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
storageClassName: managed-csi
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:8.0.30
name: mysql
env:
- name: MYSQL_DATABASE
value: wordpressdb
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
- name: MYSQL_USER
value: mysqluser
- name: MYSQL_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-pv-claim
wordpress-deployment.yaml
with the code below:
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
loadBalancerSourceRanges: ["0.0.0.0/0"]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
storageClassName: managed-csi
resources:
requests:
storage: 20Gi
---
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:6.0.2-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
- name: WORDPRESS_DB_NAME
value: wordpressdb
- name: WORDPRESS_DB_USER
value: mysqluser
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim
Run kubectl apply
to update the configuration:
kubectl apply -k ./
The output is similar to:
secret/mysql-pass-9mftfh2cbc created
service/wordpress created
service/wordpress-mysql created
persistentvolumeclaim/mysql-pv-claim created
persistentvolumeclaim/wp-pv-claim created
deployment.apps/wordpress created
deployment.apps/wordpress-mysql created
kubectl get pvc
The output is similar to:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Bound pvc-b5ed7959-9a05-4759-a178-86f7e1393be0 20Gi RWO managed-csi 107s
wp-pv-claim Bound pvc-cb03c97b-adab-4e4f-ad91-fcfaa69b1a30 20Gi RWO managed-csi 107s
kubectl get pods
The output is similar to:
NAME READY STATUS RESTARTS AGE
wordpress-6c5db6d5d7-zznww 1/1 Running 0 5m11s
wordpress-mysql-75467487bf-zs5vk 1/1 Running 0 5m11s
kubectl get volumeattachments
The output is similar to:
NAME ATTACHER PV NODE ATTACHED AGE
csi-643e8fc7abcd16d5e98eeffcb0cff690c20aa2fb90a55c38889a570295fa07d2 disk.csi.azure.com pvc-b5ed7959-9a05-4759-a178-86f7e1393be0 aks-demopool-85935132-vmss000001 true 5m52s
csi-eecaead981dd085e638d388afaa2a325019fcda81bfcda91e867b69d41fc4482 disk.csi.azure.com pvc-cb03c97b-adab-4e4f-ad91-fcfaa69b1a30 aks-demopool-85935132-vmss000001 true 5m52s
kubectl get svc
The output is similar to:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 21m
wordpress LoadBalancer 10.0.69.21 20.10.212.247 80:31829/TCP 7m23s
wordpress-mysql ClusterIP None <none> 3306/TCP 7m22s
The IP address in the EXTERNAL-IP
column is the one to use.
The WordPress welcome screen will be displayed.
You have successfully installed WordPress on your Arm-based AKS cluster.
Run terraform destroy
to delete all resources created.
terraform destroy
Answer yes
at the prompt to destroy all resources.