Professional Documents
Culture Documents
DEMO-3: StatefulSets
1. Create 2 persistent volumes for your pods to bind to
Syntax: vi pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: nginx-pv
labels:
type: local
app: nginx
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/edureka/data"
Create another persistent with same settings except with a different metadata name and hostpath
Page 1
Module 9: Container Orchestration using Kubernetes Part - II
2. Create a yaml file that contains both the nginx StatefulSet and the service required to access it
Syntax: vi state.yml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
Page 2
Module 9: Container Orchestration using Kubernetes Part - II
Now, execute the yaml file to create the service and the statefulset
3. We can check if the statefulset, service and the pods associated are creates successfully
You can notice that pods are created sequentially and are given unique ID’s which are retained
even after multiple restarts
4. Now to test if the statefulset is working as expected we will check the details of one of the pods,
delete and wait for it to get rescheduled
Page 3
Module 9: Container Orchestration using Kubernetes Part - II
We can check the details to see that the pod as retained its identity
Page 4