k8s系列(十二:实例)CoreOS:Operator,Statefulset
无状态更关注群体:cattle有状态更关注个体: petStatefulset:有状态应用副本集控制器,前身为PetSet(1.3)1.5之后为Statefulset,每个pod存储的数据不同、因此不能挂载同一个存储空间主要用于管理具有以下特性的应用程序:1、稳定且需要有唯一的网络标识符;...
无状态更关注群体:cattle
有状态更关注个体: pet
Statefulset:有状态应用副本集控制器,前身为PetSet(1.3)1.5之后为Statefulset,每个pod存储的数据不同、因此不能挂载同一个存储空间
主要用于管理具有以下特性的应用程序:
1、稳定且需要有唯一的网络标识符;
2、稳定且持久的存储设备;
3、有序、平滑地部署和扩展;
4、有序、平滑的终止和删除;
5、有序的滚动更新;一般先更新从节点再更新主节点
典型的Statefulset由三个组件组成:headless service(管理pod名称不变)、StatefulSet控制器、volumeClaimTemplate存储 卷申请模板(每个pod存储的数据不同、因此不能挂载同一个存储空间,自动生成一个 pvc绑定一个pv,实现自己专有的存储)
实例
环境准备
1、存储服务器上储备存储空间
安装nfs-utils
编辑exports
查看nfs-utils监听的端口
创建pv的yaml
[root@localhost emptydir]# cat pv-demo.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv001
labels:
name: pv001
spec:
nfs:
path: /data/volumes/v1
server: 192.168.88.106
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv002
labels:
name: pv002
spec:
nfs:
path: /data/volumes/v2
server: 192.168.88.106
accessModes: ["ReadWriteOnce"]
capacity:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv003
labels:
name: pv003
spec:
nfs:
path: /data/volumes/v3
server: 192.168.88.106
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv004
labels:
name: pv004
spec:
nfs:
path: /data/volumes/v4
server: 192.168.88.106
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv005
labels:
name: pv005
spec:
nfs:
path: /data/volumes/v5
server: 192.168.88.106
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 10Gi
创建pv
创建sts的yaml
[root@localhost statefulset]# cat sts-demo.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp
labels:
app: myapp
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: myapp-pod
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: myapp
spec:
serviceName: myapp
replicas: 3
selector:
matchLabels:
app: myapp-pod
template:
metadata:
labels:
app: myapp-pod
spec:
containers:
- name: myapp
image: hello-world:latest
ports:
- containerPort: 80
name: web
volumeMounts:
- name: myappdata
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: myappdata
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
创建sts
顺序创建完成一个创建下一个
当删除pods时pvc是不会被删除的,主要是同一个statefulset创建的就不会变
statefulset支持滚动更新,每一个pod的自己的名字是能够被解析的,名称是固定的
pod的名称为:
pvc的名字隐含了pod的名字所以每一个pvc可以持续的为一个特定的pod提供服务
扩展statefulset的pod
缩减到2个
顺序扩容倒叙缩减
statefulset升级是逆势的先更新大后更新小
partition:N( >=N的pod被更新)
打补丁设置更新策略
更新
定义statefulset参考
更多推荐
所有评论(0)