Kubernetes Service defines a logical set of Pods and a policy by which to access them. Service can be exposed in different ways by specifying a type in the serviceSpec. StatefulSet currently requires a Headless Service to control the domain of its Pods, directly reach each Pod with stable DNS entries. By specifying “None” for the clusterIP, you can create Headless Service.
Copy/Paste the following commands into your Cloud9 Terminal.
cd ~/environment/templates wget https://eksworkshop.com/beginner/170_statefulset/services.files/mysql-services.yml
Check the configuration of mysql-services.yml by following command.
You can see the mysql service is for DNS resolution so that when pods are placed by StatefulSet controller, pods can be resolved using pod-name.mysql. mysql-read is a client service that does load balancing for all slaves.Create service mysql and mysql-read by following command
kubectl create -f ~/environment/templates/mysql-services.yml