StatefulSet consists of serviceName, replicas, template and volumeClaimTemplates. serviceName is “mysql”, headless service we created in previous section, replicas is 3, the desired number of pod, template is the configuration of pod, volumeClaimTemplates is to claim volume for pod based on storageClassName, gp2 that we created in “Define Storageclass” section. Percona Xtrabackup is in template to clone source MySQL server to its slaves.
Copy/Paste the following commands into your Cloud9 Terminal.
cd ~/environment/templates
wget https://eksworkshop.com/beginner/170_statefulset/statefulset.files/mysql-statefulset.yml
Create statefulset “mysql” by following command.
kubectl create -f ~/environment/templates/mysql-statefulset.yml
Watch the status of statefulset.
kubectl get -w statefulset
It will take few minutes for pods to initialize and have statefulset created. DESIRED is the replicas number you define at StatefulSet.
Open another Cloud9 Terminal and watch the progress of pods creation using the following command.kubectl get pods -l app=mysql --watch
You can see ordered, graceful deployment with a stable, unique name for each pod.
Press Ctrl+C to stop watching.Check the dynamically created PVC by following command.
kubectl get pvc -l app=mysql
You can see data-mysql-0,1,2 are created by STORAGECLASS mysql-gp2.
(Optional) Check 10Gi 3 EBS volumes are created across availability zones at your AWS console.