#----------------------------------------------------
# Creates a stateful set of 3 pods with nginx servers.
# Each pod exposes port 80
# A persistent volume is mounted to each pod
#----------------------------------------------------
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginx-set                                    # Name of the set
spec:
  selector:
     matchLabels:
        app: nginx-pod                               # selector to identify pods that belong to the set
  serviceName: nginx-svc                             # name of the service that controls the pods
  replicas: 3                                        # number of replicas
  template:
     metadata:
        labels:
          app: nginx-pod                             # pod lable - required to identify pods belong to the set
     spec:
        terminationGracePeriodSeconds: 10            # time given to a pod to terminate graceful before it will be killed
        containers:
        - name: nginx-container                      # container name
          image: nginx:latest                        # docker image for the container
          ports:
          - containerPort: 80                        # port exposed by the container
          volumeMounts:
          - name: www                                # name of the persistent volume claim template 
                                                     # (must match to the name of a template in the volumeClaimTemplate) 
            mountPath: /var/www/data            
  volumeClaimTemplates:
  - metadata:
       name: www                                     # name of the persistent volume template
       annotations:
           volume.beta.kubernetes.io/storage-class: www   # storage-class must match to the name of an existing StorageClass object 
    spec:
       accessModes: [ "ReadWriteOnce" ]              # persistent volume claim access mode (can be attached to one pod)
       resources:
          requests:
             storage: 1Gi                            # size of the persistent storage
