kubernetes云平台管理实战: 滚动升级秒级回滚(六)

时间:2022-11-05 14:21:33

一、nginx保证有两个版本

1、查看当前容器运行nginx版本

[root@k8s-master ~]# kubectl get pod  -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7w38b 1/1 Running 0 4h 172.16.10.4 k8s-node1
myweb-btflm 1/1 Running 0 4h 172.16.48.4 k8s-node2
myweb-cbt47 1/1 Running 0 4h 172.16.48.3 k8s-node2
myweb-rt3b9 1/1 Running 0 4h 172.16.10.3 k8s-node1
nginx 1/1 Running 0 6h 172.16.10.2 k8s-node1
nginx2 1/1 Running 0 5h 172.16.48.2 k8s-node2
[root@k8s-master ~]# curl -I 172.16.10.2
HTTP/1.1 200 OK
Server: nginx/1.15.8
Date: Sun, 20 Jan 2019 11:31:17 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 25 Dec 2018 09:56:47 GMT
Connection: keep-alive
ETag: "5c21fedf-264"
Accept-Ranges: bytes

2、下载nginx1.13

[root@k8s-master ~]# docker pull nginx:1.13

3、上传到私有仓库

[root@k8s-master ~]# docker tag docker.io/nginx:latest 10.0.128.0:5000/nginx:1.15
[root@k8s-master ~]# docker tag docker.io/nginx:1.13 10.0.128.0:5000/nginx:1.13
[root@k8s-master ~]# docker push 10.0.128.0:5000/nginx:1.13
The push refers to a repository [10.0.128.0:5000/nginx]
7ab428981537: Pushed
82b81d779f83: Pushed
d626a8ad97a1: Pushed
1.13: digest: sha256:e4f0474a75c510f40b37b6b7dc2516241ffa8bde5a442bde3d372c9519c84d90 size: 948
[root@k8s-master ~]# docker push 10.0.128.0:5000/nginx:1.15
The push refers to a repository [10.0.128.0:5000/nginx]
b7efe781401d: Layer already exists
c9c2a3696080: Layer already exists
7b4e562e58dc: Layer already exists
1.15: digest: sha256:e2847e35d4e0e2d459a7696538cbfea42ea2d3b8a1ee8329ba7e68694950afd3 size: 948
[root@k8s-master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest 33fbbf4a24e5 2 weeks ago 24.17 MB
10.0.128.0:5000/busybox latest 3a093384ac30 2 weeks ago 1.199 MB
docker.io/busybox latest 3a093384ac30 2 weeks ago 1.199 MB
10.0.128.0:5000/nginx 1.15 7042885a156a 3 weeks ago 109.2 MB
10.0.128.0:5000/nginx latest 7042885a156a 3 weeks ago 109.2 MB
docker.io/nginx latest 7042885a156a 3 weeks ago 109.2 MB
10.0.128.0:5000/nginx 1.13 ae513a47849c 8 months ago 108.9 MB
docker.io/nginx 1.13 ae513a47849c 8 months ago 108.9 MB
10.0.128.0:5000/pod-infrastructure latest 34d3450d733b 24 months ago 205 MB
docker.io/tianyebj/pod-infrastructure latest 34d3450d733b 24 months ago 205 MB

4、私有仓库查看

[root@k8s-master ~]# ls /opt/myregistry/docker/registry/v2/repositories/nginx/_manifests/tags/
1.13 1.15 latest

二、滚动升级

1、删除所有pod和rc

[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 5 5 5 5h NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-7w38b 1/1 Running 0 5h
po/myweb-btflm 1/1 Running 0 5h
po/myweb-cbt47 1/1 Running 0 5h
po/myweb-rt3b9 1/1 Running 0 5h
po/nginx 1/1 Running 0 6h
po/nginx2 1/1 Running 0 5h
[root@k8s-master ~]# kubectl delete pod nginx
pod "nginx" deleted

2、创建升级rc

[root@k8s-master ~]# cat myweb-rcv1.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 3
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: 10.0.128.0:5000/nginx:1.13
ports:
- containerPort: 80 [root@k8s-master ~]# cat myweb-rcv2.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb2
spec:
replicas: 3
selector:
app: myweb2
template:
metadata:
labels:
app: myweb2
spec:
containers:
- name: myweb2
image: 10.0.128.0:5000/nginx:1.15
ports:
- containerPort: 80

3、执行升级

[root@k8s-master ~]# kubectl rolling-update myweb -f myweb-rcv2.yml --update-period=20s
Created myweb2
Scaling up myweb2 from 0 to 3, scaling down myweb from 3 to 0 (keep 3 pods available, don't exceed 4 pods)
Scaling myweb2 up to 1
Scaling myweb down to 2
Scaling myweb2 up to 2
Scaling myweb down to 1
Scaling myweb2 up to 3
Scaling myweb down to 0
Update succeeded. Deleting myweb
replicationcontroller "myweb" rolling updated to "myweb2"

4、滚动升级过程

[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 2 2 2 20m
rc/myweb2 2 2 2 25s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb-hzxcp 1/1 Running 0 20m
po/myweb2-rhgq3 1/1 Running 0 5s
po/myweb2-xdtrp 1/1 Running 0 25s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 2 2 2 20m
rc/myweb2 2 2 2 28s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb-hzxcp 1/1 Running 0 20m
po/myweb2-rhgq3 1/1 Running 0 8s
po/myweb2-xdtrp 1/1 Running 0 28s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 2 2 2 20m
rc/myweb2 2 2 2 30s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb-hzxcp 1/1 Running 0 20m
po/myweb2-rhgq3 1/1 Running 0 10s
po/myweb2-xdtrp 1/1 Running 0 30s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 1 1 1 20m
rc/myweb2 2 2 2 40s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb-hzxcp 1/1 Terminating 0 20m
po/myweb2-khl9t 0/1 Pending 0 0s
po/myweb2-rhgq3 1/1 Running 0 20s
po/myweb2-xdtrp 1/1 Running 0 41s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 1 1 1 20m
rc/myweb2 3 3 3 46s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb2-khl9t 1/1 Running 0 6s
po/myweb2-rhgq3 1/1 Running 0 26s
po/myweb2-xdtrp 1/1 Running 0 46s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 1 1 1 20m
rc/myweb2 3 3 3 50s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb2-khl9t 1/1 Running 0 10s
po/myweb2-rhgq3 1/1 Running 0 30s
po/myweb2-xdtrp 1/1 Running 0 50s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 1 1 1 20m
rc/myweb2 3 3 3 53s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb2-khl9t 1/1 Running 0 13s
po/myweb2-rhgq3 1/1 Running 0 33s
po/myweb2-xdtrp 1/1 Running 0 53s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 1 1 1 20m
rc/myweb2 3 3 3 57s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb-3hg1r 1/1 Running 0 20m
po/myweb2-khl9t 1/1 Running 0 17s
po/myweb2-rhgq3 1/1 Running 0 37s
po/myweb2-xdtrp 1/1 Running 0 57s
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb 0 0 0 21m
rc/myweb2 3 3 3 1m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb2-khl9t 1/1 Running 0 23s
po/myweb2-rhgq3 1/1 Running 0 43s
po/myweb2-xdtrp 1/1 Running 0 1m
[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT READY AGE
rc/myweb2 3 3 3 1m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 21h NAME READY STATUS RESTARTS AGE
po/myweb2-khl9t 1/1 Running 0 29s
po/myweb2-rhgq3 1/1 Running 0 49s
po/myweb2-xdtrp 1/1 Running 0 1m

三、秒级回滚

1、执行回滚

[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb2-khl9t 1/1 Running 0 29m 172.16.10.2 k8s-node1
myweb2-rhgq3 1/1 Running 0 29m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 29m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl rolling-update myweb2 -f myweb-rcv1.yml --update-period=10s
Created myweb
Scaling up myweb from 0 to 3, scaling down myweb2 from 3 to 0 (keep 3 pods available, don't exceed 4 pods)
Scaling myweb up to 1
Scaling myweb2 down to 2
Scaling myweb up to 2
Scaling myweb2 down to 1
Scaling myweb up to 3
Scaling myweb2 down to 0
Update succeeded. Deleting myweb2
replicationcontroller "myweb2" rolling updated to "myweb"

2、回滚过程

[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb2-khl9t 1/1 Running 0 20m 172.16.10.2 k8s-node1
myweb2-rhgq3 1/1 Running 0 20m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 20m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-mnf7x 1/1 Running 0 4s 172.16.48.2 k8s-node2
myweb2-khl9t 1/1 Running 0 29m 172.16.10.2 k8s-node1
myweb2-rhgq3 1/1 Running 0 29m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-mnf7x 1/1 Running 0 6s 172.16.48.2 k8s-node2
myweb2-khl9t 1/1 Running 0 29m 172.16.10.2 k8s-node1
myweb2-rhgq3 1/1 Running 0 29m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-mnf7x 1/1 Running 0 7s 172.16.48.2 k8s-node2
myweb2-khl9t 1/1 Running 0 29m 172.16.10.2 k8s-node1
myweb2-rhgq3 1/1 Running 0 29m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7m76h 1/1 Running 0 2s 172.16.10.2 k8s-node1
myweb-mnf7x 1/1 Running 0 12s 172.16.48.2 k8s-node2
myweb2-rhgq3 1/1 Running 0 29m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7m76h 1/1 Running 0 5s 172.16.10.2 k8s-node1
myweb-mnf7x 1/1 Running 0 15s 172.16.48.2 k8s-node2
myweb2-rhgq3 1/1 Running 0 30m 172.16.10.3 k8s-node1
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7m76h 1/1 Running 0 11s 172.16.10.2 k8s-node1
myweb-kzq8c 0/1 ContainerCreating 0 1s <none> k8s-node2
myweb-mnf7x 1/1 Running 0 21s 172.16.48.2 k8s-node2
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7m76h 1/1 Running 0 14s 172.16.10.2 k8s-node1
myweb-kzq8c 1/1 Running 0 4s 172.16.48.4 k8s-node2
myweb-mnf7x 1/1 Running 0 24s 172.16.48.2 k8s-node2
myweb2-xdtrp 1/1 Running 0 30m 172.16.48.3 k8s-node2
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myweb-7m76h 1/1 Running 0 24s 172.16.10.2 k8s-node1
myweb-kzq8c 1/1 Running 0 14s 172.16.48.4 k8s-node2
myweb-mnf7x 1/1 Running 0 34s 172.16.48.2 k8s-node2

kubernetes云平台管理实战: 滚动升级秒级回滚(六)的更多相关文章

  1. kubernetes云平台管理实战: 高级资源deployment-滚动升级(八)

    一.通过文件创建deployment 1.创建deployment文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions ...

  2. kubernetes云平台管理实战:deployment通过标签管理pod(十)

    一.kubectl run命令拓展 1.RC创建 [root@k8s-master ~]# kubectl run web --generator=run/v1 --image=10.0.128.0: ...

  3. kubernetes云平台管理实战:如何创建deployment更好(九)

    一.文件创建带--record 1.文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions/v1beta1 kind: ...

  4. kubernetes云平台管理实战:HPA水平自动伸缩(十一)

    一.自动伸缩 1.启动 [root@k8s-master ~]# kubectl autoscale deployment nginx-deployment --max=8 --min=2 --cpu ...

  5. kubernetes云平台管理实战: 集群部署(一)

    一.环境规划 1.架构拓扑图 2.主机规划 3.软件版本 [root@k8s-master ~]# cat /etc/redhat-release CentOS Linux release 7.4.1 ...

  6. kubernetes云平台管理实战: 自动加载到负载均衡(七)

    一.如何实现外界能访问 外界访问不了 1.启动svc [root@k8s-master ~]# cat myweb-svc.yaml apiVersion: v1 kind: Service meta ...

  7. kubernetes云平台管理实战: 故障自愈实战(四)

    一.创建实验文件 [root@k8s-master ~]# cat myweb-rc.yml apiVersion: v1 kind: ReplicationController metadata: ...

  8. kubernetes云平台管理实战: 最小的资源pod(二)

    一.pod初体验 1.编辑k8s_pod.yml文件 [root@k8s-master ~]# cat k8s_pod.yml apiVersion: v1 kind: Pod metadata: n ...

  9. kubernetes云平台管理实战: 服务发现和负载均衡(五)

    一.rc控制器常用命令 1.rc控制器信息查看 [root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT ...

随机推荐

  1. Jmeter教程索引贴

    新的一年即将到来,不知不觉2015年自己在Jmeter方面总结的文章有十几篇,在此汇总一下,顺便也算是个总结吧.2016年,继续学习技术,总结,写文章. 一.基础部分: 使用Jmeter进行http接 ...

  2. Oracle - PL&sol;SQL Commands

    第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...

  3. SPOJ COT2 树上找路径上不同值的个数

    题目大意 给出多个询问u , v , 求出u-v路径上点权值不同的个数 开始做的是COT1,用主席树写过了,理解起来不难 很高兴的跑去做第二道,完全跟普通数组区间求k个不同有很大区别,完全没思路 膜拜 ...

  4. ASP&period;net MVC基础

    简单了解了下MVC的基本开发步骤后,又对MVC的语法和模版详细看看了,小小总结下 对mvc开发,首先是要对布局有个基本的认识.Razor引擎使页面元素更加清晰 简单认识下 可以加载css和js等文件, ...

  5. 三框架:使用数据源dbcp注意

    使用spring整合hibernate时间,需要使用该数据源,数据源使用apache的dbcp,使用dbcp当需要依靠pool的jar包.选择dbcp和pool当你需要注意. DBCP 2 compi ...

  6. python&sol;numpy&sol;tensorflow中,对矩阵行列操作,下标是怎么回事儿?

    Python中的list/tuple,numpy中的ndarrray与tensorflow中的tensor. 用python中list/tuple理解,仅仅是从内存角度理解一个序列数据,而非数学中标量 ...

  7. hihoCoder &num;1043 &colon; 完全背包&lpar;板子题&rpar;

    #1043 : 完全背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说之前的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的 ...

  8. Py&&num;39&semi;t&&num;39&semi;hon之csv,ini&amp&semi;序列化,反序列化

    1.csv文件简介 csv是一个被行分隔符,列分隔符划分成行和列的文本 csv不指定字符编码 行分隔符为\r\n,最后一行可以没有换行符 列分隔符常为逗号和制表符 每一行称之为record from ...

  9. ros 编程习惯

    1.设置ros的info,warning,debug,error等编写的时候要思考,何时该使用,以及在开头要使用设置rosconsole的级别来对应输出,以方便调试. 2.在使用ros_info等的时 ...

  10. 危险的浮点数float

    今天写程序又以为我见鬼了!最后查出来发现原来又是浮点数搞的鬼! 情况大致是这样的,我想要测试向量运算的速度,所以要对一个浮点数向量进行求和运算,代码如下: int vect_size=10000000 ...