一、简介
前面详细介绍了pod的常用控制器replicaSet、deployment和DaemonSet,参考文章
Kubernetes/K8S基础使用方法总结【四】——Pod控制器
主要用来部署无状态应用。而对于有状态应用,常用的控制器为StatefulSet,
1.对于statefulSet的使用,有以下几点要求:
- 稳定且唯一的网络标识符;
- 稳定且持久的存储;
- 有序、平滑的进行部署和扩展;
- 有序、平滑地终止和删除;
- 有序的滚动更新;
2.StatefulSet包含三个重要组件
- headless service(无头服务);
- StatefulSet控制器;
- volumeClaimTemplate(存储卷申请模板)
二、StatefulSet(简称sts)
1.创建sts实例:
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: ikubernetes/myapp:v1 ports: - containerPort: 80 name: web volumeMounts: - name: myappdata mountPath: /usr/share/nginx/html volumeClaimTemplates: - metadata: name: myappdata spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 2Gi
2. 应用并查看sts信息
如下图显示3个pod资源已创建并就绪running状态
[root@master1 yaml]# kubectl apply -f stateFullSet-demo.yaml service/myapp created statefulset.apps/myapp created [root@master1 yaml]# kubectl get sts NAME READY AGE myapp 3/3 7m27s [root@master1 yaml]# kubectl get pods NAME READY STATUS RESTARTS AGE myapp-0 1/1 Running 0 8m23s myapp-1 1/1 Running 0 108s myapp-2 1/1 Running 0 85s
3. 查看pv和pvc
如下显示被自动绑定,表示成功!
[root@master1 yaml]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pv001 3Gi RWO,RWX Retain Bound default/myappdata-myapp-2 25m pv002 3Gi RWO,RWX Retain Bound default/myappdata-myapp-0 25m pv003 3Gi RWO,RWX Retain Bound default/myappdata-myapp-1 25m [root@master1 yaml]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE myappdata-myapp-0 Bound pv002 3Gi RWO,RWX 9m12s myappdata-myapp-1 Bound pv003 3Gi RWO,RWX 2m37s myappdata-myapp-2 Bound pv001 3Gi RWO,RWX 2m14s
4.扩容
kubectl scale命令进行扩展和缩减
[root@master1 volumes]# kubectl scale sts myapp --replicas=2 statefulset.apps/myapp scaled
kubectl patch命令扩展和缩减
[root@master1 volumes]# kubectl patch sts myapp -p '{"spec":{"replicas":3}}' statefulset.apps/myapp patched
5.版本升级
您暂时无权查看此隐藏内容!
内容查看价格2.99元立即支付
注意:本站少数资源收集于网络,如涉及版权等问题请及时与站长联系,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:zhangqiongjie.com。
作者:1923002089
评论前必须登录!
注册