Skip to content

Instantly share code, notes, and snippets.

@ervinb
Last active December 13, 2018 15:10
Show Gist options
  • Save ervinb/d7a13d6f369c7e6c17a795ee507b8a1e to your computer and use it in GitHub Desktop.
Save ervinb/d7a13d6f369c7e6c17a795ee507b8a1e to your computer and use it in GitHub Desktop.
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:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10 # send SIGTERM > sleep 10 > send SIGKILL
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

A StatefulSet using 3 replicas

$ kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
web-0                         1/1     Running   0          3m
web-1                         1/1     Running   0          2m
web-2                         1/1     Running   0          2m


$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                         STORAGECLASS   REASON   AGE
pvc-c684e7b4-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            Delete           Bound    default/www-web-0             standard                3m
pvc-d32f5bd5-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            Delete           Bound    default/www-web-1             standard                2m
pvc-deff2743-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            Delete           Bound    default/www-web-2             standard                2m

$ kubectl get pvc
NAME                  STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
www-web-0             Bound    pvc-c684e7b4-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            standard       3m
www-web-1             Bound    pvc-d32f5bd5-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            standard       3m
www-web-2             Bound    pvc-deff2743-f2f7-11e8-a73a-42010a9c003e   1Gi        RWO            standard       3m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment