Create StatefulSet

This workshop has been deprecated and archived. The new Amazon EKS Workshop is now available at www.eksworkshop.com.

Introduction

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, mysql-gp2 that we created in the Define Storageclass section.

Percona Xtrabackup is used in the template to clone source MySQL server to its followers.

Create StatefulSet

Copy/Paste the following commands into your Cloud9 Terminal.

cd ${HOME}/environment/ebs_statefulset
wget https://eksworkshop.com/beginner/170_statefulset/statefulset.files/mysql-statefulset.yaml

Create the StatefulSet “mysql” by running the following command.

kubectl apply -f ${HOME}/environment/ebs_statefulset/mysql-statefulset.yaml

Watch StatefulSet

Watch the status of StatefulSet.

kubectl -n mysql rollout status statefulset mysql

It will take few minutes for pods to initialize and have StatefulSet created.


Waiting for 2 pods to be ready...
Waiting for 1 pods to be ready...
partitioned roll out complete: 2 new pods have been updated...

Open another Cloud9 Terminal and watch the progress of pods creation using the following command.

kubectl -n mysql get pods -l app=mysql --watch

You can see ordered, graceful deployment with a stable, unique name for each pod.


NAME      READY   STATUS           RESTARTS    AGE
mysql-0   0/2     Init:0/2          0          16s
mysql-0   0/2     Init:1/2          0          17s
mysql-0   0/2     PodInitializing   0          18s
mysql-0   1/2     Running           0          19s
mysql-0   2/2     Running           0          25s
mysql-1   0/2     Pending           0          0s
mysql-1   0/2     Pending           0          0s
mysql-1   0/2     Init:0/2          0          0s
mysql-1   0/2     Init:1/2          0          10s
mysql-1   0/2     PodInitializing   0          11s
mysql-1   1/2     Running           0          12s
mysql-1   2/2     Running           0          16s

Press Ctrl+C to stop watching.

Check the dynamically created PVC by following command.

kubectl -n mysql get pvc -l app=mysql

We can see data-mysql-0, and data-mysql-1 have been created with the STORAGECLASS mysql-gp2.


NAME           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
data-mysql-0   Bound    pvc-2a9bb222-3fbe-11ea-94be-0aff3e98c5a0   10Gi       RWO            mysql-gp2      22m
data-mysql-1   Bound    pvc-47076f1d-3fbe-11ea-94be-0aff3e98c5a0   10Gi       RWO            mysql-gp2      21m

And now the same information from the EC2 console.

We can see the EBS volumes have been automatically encrypted by the AWS Key Management Service (KMS)

EBS_volume