Statefulset
2023-05-16 09:44:34 阅读次数:95
简介
statefulset 管理的Pod是有序的,后缀是通过-1,-2等数字拼接而成
创建statefulset资源时,必须创建service
stafulset 管理的Pod资源,删除Pod并新建,新建的Pod和删除的Pod名称一致
statefulset具有volumeclaimtemplate这个字段,是卷申请模板,会自动创建pv、pvc
statefulset创建的Pod,具备域名: pod-name.svc-name.svc-namespace.svc.cluster.local
Yam 示例
apiVersion: v1
kind: Service
metadata:
name: nginx-test
labels:
app: redis-test
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: redis-test
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: redis-test
serviceName: "nginx-test"
replicas: 2
template:
metadata:
labels:
app: redis-test
spec:
containers:
- name: nginx
image: docker.io/library/nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html/
ports:
- containerPort: 80
name: web
volumeClaimTemplates:
- metadata:
name: www
spec:
storageClassName: "nfs"
accessModes: ['ReadWriteOnce']
resources:
requests:
storage: 1Gi
updateStrategy更新策略
apiVersion: v1
kind: Service
metadata:
name: nginx-test
labels:
app: redis-test
spec:
ports:
- port: 80
name: web
selector:
app: redis-test
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: redis-test
serviceName: "nginx-test"
updateStrategy:
rollingUpdate:
maxUnavailable: 0
partition: 1 # 针对statefulset,更新序号为1的Pod
replicas: 2
template:
metadata:
labels:
app: redis-test
spec:
containers:
- name: nginx
image: docker.io/janakiramm/myapp:v1
imagePullPolicy: IfNotPresent
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html/
ports:
- containerPort: 80
name: web
volumeClaimTemplates:
- metadata:
name: www
spec:
storageClassName: "nfs"
accessModes: ['ReadWriteOnce']
resources:
requests:
storage: 1Gi
onDelete 不会自动更新,需删除
apiVersion: v1
kind: Service
metadata:
name: nginx-test
labels:
app: redis-test
spec:
ports:
- port: 80
name: web
selector:
app: redis-test
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: redis-test
serviceName: "nginx-test"
updateStrategy:
type: OnDelete
replicas: 2
template:
metadata:
labels:
app: redis-test
spec:
containers:
- name: nginx
image: docker.io/janakiramm/myapp:v2
imagePullPolicy: IfNotPresent
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html/
ports:
- containerPort: 80
name: web
volumeClaimTemplates:
- metadata:
name: www
spec:
storageClassName: "nfs"
accessModes: ['ReadWriteOnce']
resources:
requests:
storage: 1Gi
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/u_11726705/6106537,作者:You0tech,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:CSS基础-CSS选择器
下一篇:云原生|kubernetes|kubernetes的etcd集群备份策略