k8s灰度发布实例!

在K8S集群内,nginx:1.20有状态应用十个副本,2个副本作为灰度发布中被保存的稳定版本,更新版本为nginx:1.21副本数量为8个

在三台主机中创建html

root@server1:~# mkdir html

root@server2:~# mkdir html

root@server3:~# mkdir html

写入

root@server1:~# echo "wkz add nginx" > html/index.html

root@server2:~# echo "wkz add nginx" > html/index.html

root@server3:~# echo "wkz add nginx" > html/index.html

编辑

root@server1:~# vim nginx.yaml

添加:

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:

  updateStrategy:

    type: RollingUpdate

    rollingUpdate:

      partition: 2

  serviceName: "nginx"

  replicas: 10

  selector:

    matchLabels:

      app: nginx

  template:

    metadata:

      labels:

        app: nginx

    spec:

      containers:

      - name: nginx

        image: nginx:1.20

        ports:

        - containerPort: 80

          name: web

        volumeMounts:

        - name: www

          mountPath: /usr/share/nginx/html

      volumes:

      - name: www

        hostPath:

          path: /root/html

 

执行

root@server1:~# kubectl apply -f nginx.yaml

 

 root@server1:~# kubectl get pod -o wide

 

查看容器image版本号

root@server1:~# for p in 0 1 2 3 4 5 6 7 8 9; do kubectl get pod web-$p --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done

 root@server1:~# kubectl describe statefulsets.apps web

 

然后在server2和server3更改html内容和位置

root@server2:~# mkdir /html

root@server2:~# echo "192.168.0.141" > /html/index.html

root@server3:~# mkdir /html

root@server3:~# echo "192.168.0.142" > /html/index.html

第一台修nginx.yaml配置文件

root@server1:~# vim nginx.yaml

修改版本号和网页地址为了更好的分辨

 

执行

root@server1:~# kubectl apply -f nginx.yaml

root@server1:~# for p in 0 1 2 3 4 5 6 7 8 9; do kubectl get pod web-$p --template '{{range $i, $c := .spec.containers}}{{$c.image}}{{end}}'; echo; done

root@server1:~# kubectl get pod -o wide

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秃头的花季少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值