资源调度 —— StatefulSet(针对部署的有状态应用)

发布时间 2023-10-13 14:48:18作者: yifanSJ

三、StatefulSet(针对部署的有状态应用

有状态很依赖本地文件、网络资源等。不像无状态应用想扩容就扩容。

一)功能

1、创建

2、扩容缩容

3、镜像更新

RollingUpdate

4、灰度发布

OnDelete

5、删除

6、删除 pvc

二)配置文件

---
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:
  serviceName: "nginx"
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi