1. apiVersion: v1
    2. kind: Service
    3. metadata:
    4. name: nginx
    5. labels:
    6. app: nginx
    7. spec:
    8. ports:
    9. - port: 80
    10. name: web
    11. selector:
    12. app: nginx
    13. type: NodePort
    14. ---
    15. apiVersion: apps/v1
    16. kind: StatefulSet
    17. metadata:
    18. name: web
    19. spec:
    20. selector:
    21. matchLabels:
    22. app: nginx # has to match .spec.template.metadata.labels
    23. serviceName: "nginx"
    24. replicas: 2 # by default is 1
    25. template:
    26. metadata:
    27. labels:
    28. app: nginx # has to match .spec.selector.matchLabels
    29. spec:
    30. restartPolicy: Always
    31. terminationGracePeriodSeconds: 10
    32. containers:
    33. - name: nginx
    34. image: k8s.gcr.io/nginx-slim:0.8
    35. livenessProbe:
    36. exec:
    37. command:
    38. - ls
    39. - /usr/share/nginx/html/lost+found
    40. initialDelaySeconds: 5
    41. periodSeconds: 5
    42. ports:
    43. - containerPort: 80
    44. name: web
    45. volumeMounts:
    46. - name: www
    47. mountPath: /usr/share/nginx/html
    48. volumeClaimTemplates:
    49. - metadata:
    50. name: www
    51. spec:
    52. accessModes: [ "ReadWriteOnce" ]
    53. storageClassName: "longhorn"
    54. resources:
    55. requests:
    56. storage: 1Gi