| apiVersion: v1 |
| kind: Service |
| metadata: |
| name: nginx |
| namespace : test |
| labels: |
| app: nginx |
| spec: |
| ports: |
| - port: 80 |
| name: web |
| clusterIP: None |
| selector: |
| app: nginx |
| --- |
| apiVersion: apps/v1 |
| kind: StatefulSet |
| metadata: |
| name: web |
| namespace : test |
| spec: |
| selector: |
| matchLabels: |
| app: nginx # has to match .spec.template.metadata.labels |
| serviceName: "nginx" #声明它属于哪个Headless Service. |
| replicas: 3 # by default is 1 |
| template: |
| metadata: |
| labels: |
| app: nginx # has to match .spec.selector.matchLabels |
| spec: |
| terminationGracePeriodSeconds: 10 |
| containers: |
| - name: nginx |
| image: nginx |
| ports: |
| - containerPort: 80 |
| name: web |
| |
| |
| |