cat << END > statefulSet.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-svc #无头服务内部使用必须一致
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-svc" #无头服务内部使用必须一致
replicas: 5 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
name: web
# volumeMounts:
# - name: www
# mountPath: /usr/share/nginx/html
# volumeClaimTemplates:
# - metadata:
# name: www
# spec:
# accessModes: [ "ReadWriteOnce" ]
# storageClassName: "my-storage-class"
# resources:
# requests:
# storage: 1Gi
---
# 在给一个端口外部访问
apiVersion: v1
kind: Service
metadata:
name: nginx-port
spec:
selector:
app: nginx
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
#- name: https
# port: 8443
# protocol: TCP
# targetPort: 443
type: NodePort
END
statefulSet控制器
最新推荐文章于 2024-07-21 19:38:40 发布