运行一个容器:

apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2020-09-19T02:41:11Z"
generation: 1
labels:
app: nginx
name: nginx
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 3 # 副本数
revisionHistoryLimit: 10 # 历史记录保留的个数
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.15.4
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
# 保存为deployment.yaml 并创建nginx pod:
[root@k8s-master01 yaml]# kubectl create -f deployment-nginx.yaml
deployment.apps/nginx created #检查:
[root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-6cdd5dd489-d7kll 1/1 Running 0 17s
nginx-6cdd5dd489-dblw2 1/1 Running 0 17s
nginx-6cdd5dd489-zc8fl 1/1 Running 0 17s #检查nginx版本:
[root@k8s-master01 yaml]# kubectl exec -it nginx-6cdd5dd489-d7kll -- sh
# nginx -v
nginx version: nginx/1.15.4

镜像升级与回滚

#升级:
root@k8s-master01[11:10:24]:~/yaml$ kubectl set image deploy nginx nginx=nginx:1.15.5 --record=true
deployment.apps/nginx image updated #检查升级过程:
kubectl describe pod nginx-7c4b6d99fd-csh5s Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 76s default-scheduler Successfully assigned default/nginx-df9789dc8-6h7p7 to k8s-node02
Normal Pulling 76s kubelet Pulling image "nginx:1.15.5"
Normal Pulled 51s kubelet Successfully pulled image "nginx:1.15.5" in 24.828362289s
Normal Created 51s kubelet Created container nginx
Normal Started 51s kubelet Started container nginx #检查现在的版本:
[root@k8s-master01 yaml]# kubectl exec -it nginx-df9789dc8-trtwq -- sh # nginx -v
nginx version: nginx/1.15.5 #检查更新过程
kubectl rollout status deploy nginx [root@k8s-master01 yaml]# kubectl rollout status deploy nginx
Waiting for deployment "nginx" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "nginx" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "nginx" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
deployment "nginx" successfully rolled out [root@k8s-master01 yaml]# kubectl exec -it nginx-6cdd5dd489-bsb7f -- sh
# nginx -v
nginx version: nginx/1.15.5 #为了实验效果 在升级一次
[root@k8s-master01 yaml]# kubectl set image deploy nginx nginx=nginx:1.15.6 --record=true [root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-5455fbc855-64brv 1/1 Running 0 2m48s
nginx-5455fbc855-nblks 1/1 Running 0 3m16s
nginx-5455fbc855-ns4kz 1/1 Running 0 2m47s
[root@k8s-master01 yaml]# kubectl exec -it nginx-5455fbc855-64brv -- sh
# nginx -v
nginx version: nginx/1.15.6 #回滚:
1. 查看历史更新
kubectl rollout history deploy nginx [root@k8s-master01 yaml]# kubectl rollout history deploy nginx
deployment.apps/nginx
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image deploy nginx nginx=nginx:1.15.5 --record=true
3 kubectl set image deploy nginx nginx=nginx:1.15.6 --record=true 2. 回滚到上一个版本[kubectl rollout undo deploy {name} ]
[root@k8s-master01 yaml]# kubectl rollout undo deploy nginx
deployment.apps/nginx rolled back 3. 检查回滚状态:
[root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-6cdd5dd489-bzdgd 1/1 Running 0 21s
nginx-6cdd5dd489-cwxv5 1/1 Running 0 22s
nginx-6cdd5dd489-xb6xj 1/1 Running 0 20s 3.1 进入容器检查:
[root@k8s-master01 yaml]# kubectl exec -it nginx-6cdd5dd489-bzdgd -- sh
# nginx -v
nginx version: nginx/1.15.4 4. 回滚到指定版本
[root@k8s-master01 yaml]# kubectl rollout history deploy nginx
deployment.apps/nginx
REVISION CHANGE-CAUSE
1 kubectl set image deploy nginx nginx=nginx:1.15.5 --record=true
2 kubectl set image deploy nginx nginx=nginx:1.15.6 --record=true # 查看指定版本信息
kubectl rollout history deploy nginx --revision=1 #回滚到指定版本
kubectl rollout undo deploy nginx --to-revision=1 [root@k8s-master01 yaml]# kubectl exec -it nginx-6cdd5dd489-q44cr -- sh
# nginx -v
nginx version: nginx/1.15.5

使用pod扩容,缩容

[root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-df9789dc8-gqk5j 1/1 Running 0 11m
nginx-df9789dc8-vhqkd 1/1 Running 0 11m #修改资源:
[root@k8s-master01 yaml]# kubectl edit deploy nginx
deployment.apps/nginx edited 找到: replicas: 2
改为: replicas: 3 #检查状态:
[root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-df9789dc8-c47mc 1/1 Running 0 3s
nginx-df9789dc8-gqk5j 1/1 Running 0 11m
nginx-df9789dc8-vhqkd 1/1 Running 0 11m #缩容就是继续把 replicas: 3 改为: replicas: 2即可:
[root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-df9789dc8-gqk5j 1/1 Running 0 13m
nginx-df9789dc8-vhqkd 1/1 Running 0 13m

使用yaml文件进行升级

apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2020-09-19T02:41:11Z"
generation: 1
labels:
app: nginx
name: nginx
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 3 # 副本数
revisionHistoryLimit: 10 # 历史记录保留的个数
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.15.4
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
#修改:
spec:
containers:
- image: nginx:1.15.5 #改为想要的镜像版本 #改为 1.15.5
[root@k8s-master01 yaml]# kubectl apply -f nginx-1.yaml
deployment.apps/nginx configured
[root@k8s-master01 yaml]# kubectl get pod #注意升级的时候 他会起新的rs(replicas),通过命令可以看到,他会新起来一个pod 并把老副本数设置为2,新副本起来2个的时候
#老副本数会设置为1,直到变成0 最后才会真正的完成滚动更新。
[root@k8s-master01 yaml]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-5455fbc855 3 3 3 4m46s
nginx-565979ccb4 1 1 0 5s [root@k8s-master01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-5455fbc855-j552c 1/1 Running 0 17s
nginx-5455fbc855-sl8m8 1/1 Running 0 15s
nginx-5455fbc855-sq4mr 1/1 Running 0 14s
[root@k8s-master01 yaml]# kubectl exec -it nginx-5455fbc855-j552c -- sh
# nginx -v
nginx version: nginx/1.15.5 ## 查看滚动更新过程:
NewReplicaSet: nginx-565979ccb4 (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 10m deployment-controller Scaled up replica set nginx-6cdd5dd489 to 3
Normal ScalingReplicaSet 9m53s deployment-controller Scaled up replica set nginx-df9789dc8 to 1
Normal ScalingReplicaSet 9m51s deployment-controller Scaled down replica set nginx-6cdd5dd489 to 2
Normal ScalingReplicaSet 9m51s deployment-controller Scaled up replica set nginx-df9789dc8 to 2
Normal ScalingReplicaSet 9m50s deployment-controller Scaled down replica set nginx-6cdd5dd489 to 1
Normal ScalingReplicaSet 9m50s deployment-controller Scaled up replica set nginx-df9789dc8 to 3
Normal ScalingReplicaSet 9m48s deployment-controller Scaled down replica set nginx-6cdd5dd489 to 0
Normal ScalingReplicaSet 7m47s deployment-controller Scaled up replica set nginx-5455fbc855 to 1
Normal ScalingReplicaSet 7m45s deployment-controller Scaled down replica set nginx-df9789dc8 to 2
Normal ScalingReplicaSet 2m18s (x10 over 7m45s) deployment-controller (combined from similar events): Scaled down replica set nginx-5455fbc855 to 0

kubernetes pod升级与回滚扩容与缩容的更多相关文章

  1. Kubernetes:Pod 升级、回滚

    本篇主要讨论如何实现滚动更新和回滚,任意更换版本并且回滚以前的版本(版本更新),而下一章会讨论到 Pod 缩放,根据机器资源自动拓展和收缩应用(自动扩容实例). 本文为作者的 Kubernetes 系 ...

  2. kubernetes deployment升级和回滚

    a.创建deployment pod kubectl run mynginx --image=docker.io/nginx: --record 准备svc文件 apiVersion: v1 kind ...

  3. k8s用kubectl管理应用升级,服务发布与回滚,扩缩容

    应用升级 Kubectl set image --help 有案例指定新版本 [root@k8s-master ~]# kubectl set image deployment/nginx nginx ...

  4. Docker Kubernetes 容器更新与回滚

    Docker Kubernetes 容器更新与回滚 环境: 系统:Centos 7.4 x64 Docker版本:18.09.0 Kubernetes版本:v1.8 管理节点:192.168.1.79 ...

  5. 022.掌握Pod-Pod升级和回滚

    一 deploymentPod升级和回滚 1.1 deployment升级 若Pod是通过Deployment创建的,可以在运行时修改Deployment的Pod定义(spec.template)或镜 ...

  6. Kubernetes 笔记 012 Pod 的自动扩容与缩容

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. Hi,大家好, ...

  7. Kubernetes 笔记 11 Pod 扩容与缩容 双十一前后的忙碌

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. Hi,大家好, ...

  8. Hadoop HDFS概念学习系列之HDFS升级和回滚机制(十二)

    不多说,直接上干货! HDFS升级和回滚机制 作为一个大型的分布式系统,Hadoop内部实现了一套升级机制,当在一个集群上升级Hadoop时,像其他的软件升级一样,可能会有新的bug或一些会影响现有应 ...

  9. Docker Kubernetes 容器扩容与缩容

    Docker Kubernetes 容器扩容与缩容 环境: 系统:Centos 7.4 x64 Docker版本:18.09.0 Kubernetes版本:v1.8 管理节点:192.168.1.79 ...

  10. k8s Pod 扩容和缩容

    在生产环境下,在面临服务需要扩容的场景时,可以使用Deployment/RC的Scale机制来实现.Kubernetes支持对Pod的手动扩容和自动扩容. 手动扩容缩容 通过执行扩容命令,对某个dep ...

随机推荐

  1. 重新点亮shell————语法[四]

    前言 简单介绍一下语法. 正文 数组: 定义数组: IPTS =(10.0.0.1 10.0.0.2 10.0.0.3) 显示所以数组元素: echo ${IPTS[@]} 显示数组元素的个数 ech ...

  2. cv2在图像上画不同比例的锚框

    ''' cv2在图像上画不同比例的锚框 ''' import cv2 import math # 画宽高比1:1的锚框 def display_11_anchor(img,anchor_11_left ...

  3. 密码学中的RSA算法与椭圆曲线算法

    PrimiHub一款由密码学专家团队打造的开源隐私计算平台,专注于分享数据安全.密码学.联邦学习.同态加密等隐私计算领域的技术和内容. 在数字安全领域,加密算法扮演着至关重要的角色.它们确保了信息的机 ...

  4. LeetCode - 最接近的三数之和

    最接近的三数之和 你一个长度为 n 的整数数组 nums 和 一个目标值 target.请你从 nums 中选出三个整数,使它们的和与 target 最接近. 返回这三个数的和. 假定每组输入只存在恰 ...

  5. Spring 源码阅读(二)IoC 容器初始化以及 BeanFactory 创建和 BeanDefinition 加载过程

    相关代码提交记录:https://github.com/linweiwang/spring-framework-5.3.33 IoC 容器三种启动方式 XML JavaSE: ApplicationC ...

  6. 一个 Blink 小白的成长之路

    写在前面 写过blink sql的同学应该都有体会,明明写的时候就很顺滑,小手一抖,洋洋洒洒三百行代码,一气呵成.结果跑的时候,吞吐量就是上不去.导致数据延迟高,消息严重积压,被业务方疯狂吐槽.这时候 ...

  7. 利器解读!Linux 内核调测中最最让开发者头疼的 bug 有解了|龙蜥技术

    ​简介:通过在Anolis 5.10 内核中增强 kfence 的功能,实现了一个线上的.精准的.可定制的内存调试解决方案. 编者按:一直持续存在内核内存调测领域两大行业难题: "内存被改& ...

  8. Databricks 企业版 Spark&Delta Lake 引擎助力 Lakehouse 高效访问

    ​简介:本文介绍了Databricks企业版Delta Lake的性能优势,借助这些特性能够大幅提升Spark SQL的查询性能,加快Delta表的查询速度. 作者: 李锦桂(锦犀) 阿里云开源大数据 ...

  9. Go 语言网络库 getty 的那些事

    简介: Getty 维护团队不追求无意义的 benchmark 数据,不做无意义的炫技式优化,只根据生产环境需求来进行自身改进.只要维护团队在,Getty 稳定性和性能定会越来越优秀. 个人从事互联网 ...

  10. EMR on ACK 全新发布,助力企业高效构建大数据平台

    ​简介: 阿里云 EMR on ACK 为用户提供了全新的构建大数据平台的方式,用户可以将开源大数据服务部署在阿里云容器服务(ACK)上.利用 ACK 在服务部署和对高性能可伸缩的容器应用管理的能力优 ...