MySQL container uses readiness probe by running mysql -h 127.0.0.1 -e ‘SELECT 1’ on the server to make sure MySQL server is still active. Open a new terminal and simulate MySQL as being unresponsive by following command.
kubectl exec mysql-2 -c mysql -- mv /usr/bin/mysql /usr/bin/mysql.off
This command renames the /usr/bin/mysql command so that readiness probe can’t find it. During the next health check, the pod should report one of it’s containers is not healthy. This can be verified by following command.
kubectl get pod mysql-2
mysql-read load balancer detects failures and takes action by not sending traffic to the failed container, @@server_id 102. You can check this by the loop running in separate window from previous section. The loop shows the following output.
Revert back to its initial state at the previous terminal.
kubectl exec mysql-2 -c mysql -- mv /usr/bin/mysql.off /usr/bin/mysql
Check the status again to see that both containers are running and healthy
kubectl get pod mysql-2
The loop in another terminal is now showing @@server_id 102 is back and all three servers are running.
Press Ctrl+C to stop watching.
To simulate a failed pod, delete mysql-2 pod by following command.
kubectl delete pod mysql-2
StatefulSet controller recognizes failed pod and creates a new one to maintain the number of replicas with them same name and link to the same PersistentVolumeClaim.
kubectl get pod -w mysql-2
Press Ctrl+C to stop watching.