Skip to content

mehmetmgrsl/k8s-statefulset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Run a Replicated Stateful Application

1. Preconditions

2. Deploy MySQL

  • kubectl apply -f mysql-cm.yaml # Create the ConfigMap
  • kubectl apply -f mysql-svcs.yaml # Create Services
  • kubectl apply -f mysql-statefulset.yaml # Create the StatefulSet

Check the status of PODs

>>> kubectl get pods

NAME      READY   STATUS    RESTARTS   AGE
mysql-0   2/2     Running   0          8m25s
mysql-1   2/2     Running   0          5m6s
mysql-2   2/2     Running   0          115s

Sending client traffic

  1. Send a query to writer
kubectl run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\
  mysql -h mysql-0.mysql <<EOF
CREATE DATABASE test;
CREATE TABLE test.messages (message VARCHAR(250));
INSERT INTO test.messages VALUES ('hello');
EOF
  1. Send a query to reader pool
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
  mysql -h mysql-read -e "SELECT * FROM test.messages"

+---------+
| message |
+---------+
| hello   |
+---------+

Delete PODs

kubectl delete pod mysql-1

The StatefulSet also recreates Pods if they're deleted.

The StatefulSet controller notices that no mysql-1 Pod exists anymore, and creates a new one with the same name and linked to the same PersistentVolumeClaim.

kubectl delete pod mysql-1
pod "mysql-1" deleted

kubectl get pods
NAME      READY   STATUS    RESTARTS   AGE
mysql-0   2/2     Running   0          18m
mysql-1   2/2     Running   0          37s # created again
mysql-2   2/2     Running   0          12m

Resources

  1. Run a Replicated Stateful Application
  2. Deploy a Production Database in Kubernetes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published