滚动升级

1、错误的yml文件

[machangwei@mcwk8s-master ~]$ cat mcwHttpd.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcw-httpd
spec:
replicas: 3
selector:
matchLabels:
run: mcw-httpd
template:
metadata:
labels:
run: mcw-httpd
spec:
containers:
- name: mcw-httpd
image: httpd
ports:
- containerPort: 80
[machangwei@mcwk8s-master ~]$ vim mcwHttpd.yml
[machangwei@mcwk8s-master ~]$ cat mcwHttpd.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcw-httpd
spec:
replicas: 3
selector:
matchLabels:
run: mcw-httpd
template:
metadata:
labels:
run: mcw-httpd
spec:
containers:
- name: mcw-httpd
image: :httpd:2.2.31
ports:
- containerPort: 80
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcwHttpd.yml
deployment.apps/mcw-httpd created
[machangwei@mcwk8s-master ~]$ kubectl get deployment httpd -o wide
Error from server (NotFound): deployments.apps "httpd" not found
[machangwei@mcwk8s-master ~]$ kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 0/3 3 0 33s mcw-httpd :httpd:2.2.31 run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
mcw-httpd-6644b55f8c-62dvc 0/1 InvalidImageName 0 98s
mcw-httpd-6644b55f8c-h8pfn 0/1 InvalidImageName 0 98s
mcw-httpd-6644b55f8c-xn259 0/1 InvalidImageName 0 98s
[machangwei@mcwk8s-master ~]$

2、修改为正确的yml文件,部署deployment

[machangwei@mcwk8s-master ~]$ vim mcwHttpd.yml
[machangwei@mcwk8s-master ~]$ cat mcwHttpd.yml #其它跟以前的没变,只是镜像后面加了冒号和数字,也就是添加了版本
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcw-httpd
spec:
replicas: 3
selector:
matchLabels:
run: mcw-httpd
template:
metadata:
labels:
run: mcw-httpd
spec:
containers:
- name: mcw-httpd
image: httpd:2.2.31
ports:
- containerPort: 80
[machangwei@mcwk8s-master ~]$ kubectl delete -f mcwHttpd.yml #把以前的删除
deployment.apps "mcw-httpd" deleted
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcwHttpd.yml #部署deployment
deployment.apps/mcw-httpd created
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide #查看镜像是31的镜像
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 13s mcw-httpd httpd:2.2.31 run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get replicaset -o wide #查看副本集这里,也是31的镜像
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
mcw-httpd-6f64bbcfcf 3 3 3 40s mcw-httpd httpd:2.2.31 pod-template-hash=6f64bbcfcf,run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get pod -o wide #查看pod部署情况
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mcw-httpd-6f64bbcfcf-5nhxc 1/1 Running 0 70s 10.244.2.9 mcwk8s-node2 <none> <none>
mcw-httpd-6f64bbcfcf-s8hng 1/1 Running 0 70s 10.244.1.7 mcwk8s-node1 <none> <none>
mcw-httpd-6f64bbcfcf-t6j2f 1/1 Running 0 70s 10.244.2.8 mcwk8s-node2 <none> <none>

3、修改镜像版本号,重新部署,滚动升级

[machangwei@mcwk8s-master ~]$ vim mcwHttpd.yml
[machangwei@mcwk8s-master ~]$ cat mcwHttpd.yml #修改版本号为:2.2.32
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcw-httpd
spec:
replicas: 3
selector:
matchLabels:
run: mcw-httpd
template:
metadata:
labels:
run: mcw-httpd
spec:
containers:
- name: mcw-httpd
image: httpd:2.2.32
ports:
- containerPort: 80
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcwHttpd.yml #重新部署
deployment.apps/mcw-httpd configured
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide #查看deployment镜像已经修改,更新了一个好像是
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 1 3 6m58s mcw-httpd httpd:2.2.32 run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get replicaset -o wide #查看副本集,32是新建的副本集,镜像改为32了。这里还没有升级完,32镜像只有一个是ready,也就是刚刚升级完一个
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
mcw-httpd-6f64bbcfcf 2 2 2 7m5s mcw-httpd httpd:2.2.31 pod-template-hash=6f64bbcfcf,run=mcw-httpd
mcw-httpd-7c977464db 2 2 1 10s mcw-httpd httpd:2.2.32 pod-template-hash=7c977464db,run=mcw-httpd
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl get pod -o wide #查看pod。根据年龄查看,刚刚生成三个新的,旧的还有一个没有被删除
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mcw-httpd-6f64bbcfcf-s8hng 1/1 Terminating 0 7m16s 10.244.1.7 mcwk8s-node1 <none> <none>
mcw-httpd-7c977464db-5ctkr 1/1 Running 0 21s 10.244.1.8 mcwk8s-node1 <none> <none>
mcw-httpd-7c977464db-bfz6t 1/1 Running 0 10s 10.244.1.9 mcwk8s-node1 <none> <none>
mcw-httpd-7c977464db-gp94c 1/1 Running 0 12s 10.244.2.10 mcwk8s-node2 <none> <none>
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide #再次查看,已经升级完三个了
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 7m36s mcw-httpd httpd:2.2.32 run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get replicaset -o wide #再次查看副本集,三个副本都已经被新生成副本代替了,
#新生成的副本是 32的镜像。而且旧的副本集副本个数为0了,但是它不会删除过了九分钟都还没有删除,应该是不删的
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
mcw-httpd-6f64bbcfcf 0 0 0 7m47s mcw-httpd httpd:2.2.31 pod-template-hash=6f64bbcfcf,run=mcw-httpd
mcw-httpd-7c977464db 3 3 3 52s mcw-httpd httpd:2.2.32 pod-template-hash=7c977464db,run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl get pod -o wide #查看pod,已经只有最新生成的镜像是32版本的pod了
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mcw-httpd-7c977464db-5ctkr 1/1 Running 0 57s 10.244.1.8 mcwk8s-node1 <none> <none>
mcw-httpd-7c977464db-bfz6t 1/1 Running 0 46s 10.244.1.9 mcwk8s-node1 <none> <none>
mcw-httpd-7c977464db-gp94c 1/1 Running 0 48s 10.244.2.10 mcwk8s-node2 <none> <none>

4、查看滚动升级详情

[machangwei@mcwk8s-master ~]$ kubectl get replicaset  -o wide #查看副本集
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
mcw-httpd-6f64bbcfcf 0 0 0 21m mcw-httpd httpd:2.2.31 pod-template-hash=6f64bbcfcf,run=mcw-httpd
mcw-httpd-7c977464db 3 3 3 14m mcw-httpd httpd:2.2.32 pod-template-hash=7c977
[machangwei@mcwk8s-master ~]$ kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 19m mcw-httpd httpd:2.2.32 run=mcw-httpd
[machangwei@mcwk8s-master ~]$ kubectl describe deployment mcw-httpd
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable #副本三个被更新的
Image: httpd:2.2.32 容器镜像是32 Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 19m deployment-controller Scaled up replica set mcw-httpd-6f64bbcfcf to 3
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set mcw-httpd-7c977464db to 1
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set mcw-httpd-6f64bbcfcf to 2
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set mcw-httpd-7c977464db to 2
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set mcw-httpd-6f64bbcfcf to 1
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set mcw-httpd-7c977464db to 3
Normal ScalingReplicaSet 12m deployment-controller Scaled down replica set mcw-httpd-6f64bbcfcf to 0 每只更新替换一个pod:
mcw-httpd-6f64bbcfcf to 3 旧副本集是3个pod
mcw-httpd-7c977464db to 1 新副本集增加一个pod,总数为1
mcw-httpd-6f64bbcfcf to 2 旧副本集减少一个pod,总数为2
mcw-httpd-7c977464db to 2 新副本集增加一个pod,总数为2
mcw-httpd-6f64bbcfcf to 1 旧副本集减少一个pod,总数为1
mcw-httpd-7c977464db to 3 新副本集增加一个pod,总数为3
mcw-httpd-6f64bbcfcf to 0 旧副本集减少一个pod,总数为0 每次替换的POD数量是可以定制的。默认应该是1吧。定制的参数有两个,如:maxSurge ,maxUnavailable 来精细控制POD的替换数量

回滚

1、回滚前的模拟准备环境

模拟新建三个需要的版本。
[root@mcwk8s-node2 ~]$ docker tag httpd:latest httpd:2.4.16
[root@mcwk8s-node2 ~]$ docker tag httpd:latest httpd:2.4.17
[root@mcwk8s-node2 ~]$ docker tag httpd:latest httpd:2.4.18
创文件文件,并修改版本
[machangwei@mcwk8s-master ~]$ cp mcwHttpd.yml mcw.httpd.v1.yml
[machangwei@mcwk8s-master ~]$ cp mcwHttpd.yml mcw.httpd.v2.yml
[machangwei@mcwk8s-master ~]$ cp mcwHttpd.yml mcw.httpd.v3.yml 修改一下文件,将镜像分别修改为 16,17,18
[machangwei@mcwk8s-master ~]$ ls mcw.httpd.v1
mcw.httpd.v16.yml mcw.httpd.v17.yml mcw.httpd.v18.yml
[machangwei@mcwk8s-master ~]$ cat mcw.httpd.v16.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcw-httpd
spec:
replicas: 3
selector:
matchLabels:
run: mcw-httpd
template:
metadata:
labels:
run: mcw-httpd
spec:
containers:
- name: mcw-httpd
image: httpd:2.4.16
ports:
- containerPort: 80

2、部署并回滚

[machangwei@mcwk8s-master ~]$ ls mcw.httpd.v1 #查看所有yml配置文件
mcw.httpd.v16.yml mcw.httpd.v17.yml mcw.httpd.v18.yml
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcw.httpd.v16.yml --record #--record,将当前命令记录到revision记录中
Flag --record has been deprecated, --record will be removed in the future #这样我们就能知道每个revison对应的是哪个配置文件了
deployment.apps/mcw-httpd created
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 2m3s mcw-httpd httpd:2.4.16 run=mcw-httpd
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcw.httpd.v17.yml --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/mcw-httpd configured
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide #每次执行都被更新镜像版本了
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 2m35s mcw-httpd httpd:2.4.17 run=mcw-httpd
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl apply -f mcw.httpd.v18.yml --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/mcw-httpd configured
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 2 3 2m54s mcw-httpd httpd:2.4.18 run=mcw-httpd
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl rollout history deployment mcw-httpd #--record,将当前命令记录到revision记录中
deployment.apps/mcw-httpd
REVISION CHANGE-CAUSE #这样我们就能知道每个revison对应的是哪个配置文件了 #查看revison历史记录
1 kubectl apply --filename=mcw.httpd.v16.yml --record=true
2 kubectl apply --filename=mcw.httpd.v17.yml --record=true
3 kubectl apply --filename=mcw.httpd.v18.yml --record=true [machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl rollout undo deployment mcw-httpd --to-revision=1 #执行命令回滚到版本1。
deployment.apps/mcw-httpd rolled back
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl get deployment mcw-httpd -o wide #查看镜像已经改成版本1的了
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mcw-httpd 3/3 3 3 4m39s mcw-httpd httpd:2.4.16 run=mcw-httpd
[machangwei@mcwk8s-master ~]$
[machangwei@mcwk8s-master ~]$ kubectl rollout history deployment mcw-httpd #查看revison历史记录的变化 deployment.apps/mcw-httpd
REVISION CHANGE-CAUSE
2 kubectl apply --filename=mcw.httpd.v17.yml --record=true
3 kubectl apply --filename=mcw.httpd.v18.yml --record=true
4 kubectl apply --filename=mcw.httpd.v16.yml --record=true #revison 1 变成了revison4,我们可以通过CHANG-CAUSE
#知道每个revison的具体含义,所以要在执行kubectl 加上参数 --record
[machangwei@mcwk8s-master ~]$

kubernetes 之 Rolling Update 滚动升级的更多相关文章

  1. 使用 kubectl 执行 Rolling Update(滚动更新)

    Rolling Update滚动更新 通过使用新版本的 Pod 逐步替代旧版本的 Pod 来实现 Deployment 的更新,从而实现零停机.新的 Pod 将在具有可用资源的 Node(节点)上进行 ...

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

    一.nginx保证有两个版本 1.查看当前容器运行nginx版本 [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS REST ...

  3. Kubernetes Deployment滚动升级

    我们k8s集群使用的是1.7.7版本的,该版本中官方已经推荐使用Deployment代替Replication Controller(rc)了,Deployment继承了rc的全部功能外,还可以查看升 ...

  4. 入门Kubernetes - 滚动升级/回滚

    一.前言 上一篇文章中对yaml文件格式进行了解,并对k8s中各种主要资源通过yaml创建时的定义模板.接来下就进一步学习k8s的各种特点.并应用在示例中. 接下来先实现.Net Core Api程序 ...

  5. kubernetes之deployment滚动升级

    参考:https://blog.51cto.com/wutengfei/2116663 创建和管理多个Pod--Deployment Deployment 为 Pod 和 ReplicaSet 提供了 ...

  6. k8s滚动升级

    为了服务升级过程中提供可持续的不中断的服务,Kubernetes 提供了rolling update机制,具体配置需要修改对应服务的yaml文件 参数解析: minReadySeconds: 100 ...

  7. ASP.NET Core on K8S深入学习(5)Rolling Update

    本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 一.什么是Rolling Update? 为了服务升级过程中提供可持续的不中断 ...

  8. K8S服务滚动升级

    对于Kubernetes集群来说,一个service可能有多个pod,滚动升级(Rolling update)就是指每次更新部分Pod,而不是在同一时刻将该Service下面的所有Pod shutdo ...

  9. 在 Rolling Update 中使用 Health Check - 每天5分钟玩转 Docker 容器技术(146)

    上一节讨论了 Health Check 在 Scale Up 中的应用,Health Check 另一个重要的应用场景是 Rolling Update.试想一下下面的情况: 现有一个正常运行的多副本应 ...

  10. 在 Rolling Update 中使用 Health Check【转】

    上一节讨论了 Health Check 在 Scale Up 中的应用,Health Check 另一个重要的应用场景是 Rolling Update.试想一下下面的情况: 现有一个正常运行的多副本应 ...

随机推荐

  1. reactive stream协议详解

    目录 背景 什么是reactive stream 深入了解java版本的reactive stream Publisher Subscriber Subscription Processor JDK中 ...

  2. 在linux上使用Qt开发动态库项目,怎么只生成一个so文件

    背景: 在linux系统上,我们使用 Qt 开发动态库项目时,会默认生成四个文件:x.so  .x.so.1 .x.so.1.0.x.so.1.0.0 四个文件,只有一个真实的so库,剩下的三个都是链 ...

  3. Python操作临时文件---tempfile

    # 使用标准库中 tempfile 下的 TemporaryFile,NamedTemporaryFile # TemporaryFile(mode='w+b', bufsize=1, suffix= ...

  4. 高可用之战:Redis Sentinal(哨兵模式)

    ★ Redis24篇集合 1 背景 在我们的<Redis高可用之战:主从架构>篇章中,介绍了Redis的主从架构模式,可以有效的提升Redis服务的可用性,减少甚至避免Redis服务发生完 ...

  5. 国产开源数据库OpenGauss的安装运行

    步骤一:OpenGauss 的安装 环境 OS:openEuler 20.03 64bit with ARM 架构:arm64 部署:单机 安装过程 1.环境配置 安装依赖包: yum install ...

  6. 什么是coredump

    什么是 coredump 介绍 在 Linux 开发中,我们经常听到程序员说我的程序 core 掉了,通常出现这类的问题是低级 bug 中的内存访问越界.使用空指针.堆栈溢出等情况.使程序运行过程中异 ...

  7. 选择排序的基本实现【数据结构与算法—TypeScript 实现】

    笔记整理自 coderwhy 『TypeScript 高阶数据结构与算法』课程 概念 本质:两两元素相比较,先扫描一遍未排序数列,把未排序的数列中的最小(大)元素,放到数列的已排序的末尾 特性 选择排 ...

  8. HarmonyOS API Version 7版本特性说明

    2020年9月11日,HarmonyOS SDK发布了首个Beta版本,支持基于HarmonyOS的华为智慧屏.智能穿戴.车机设备开发,让广大的开发者正式步入了HarmonyOS应用开发之旅. 开发者 ...

  9. Java入门01:环境安装与配置

    Java入门01:环境安装与配置 JDK下载 下载地址:https://www.oracle.com/cn/java/technologies/javase/javase-jdk8-downloads ...

  10. Flask搭建APP统一管理平台

    主页效果: 1.从数据库中获取所有APP的信息,每个卡片上展示APP名称.bundle id.版本构建历史记录,系统类型等构建信息 2.支持查询筛选,模糊查询 3.点击历史记录跳转APP历史记录详情页 ...