Kubernetes的Deployment对象使用
source link: https://www.tuicool.com/articles/RzmUby2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
一、什么是Deployment对象
明明ReplicaSet已经可以控制pod的数量了,为什么还需要Deployment?
简单的说,Deployment控制ReplicaSet的多个版本,ReplicaSet控制Pod个数
Deploymen实际上一个两层控制器,遵循一种滚动更新的方式来实升级现有的容器,这个能力的实现,依赖的就是ReplicaSet这个对象
当我们修改了Deployment对象后,Deployment控制器会使用修改后的模板,创建一个新的ReplicaSet对象,这时候有两个RelicaSet对象,
Deployment通过控制ReplicaSet对象的pod数量来达到滚动升级的效果
例如A和B,如果最终设置的pod数都是3,通过A-1,B+1这样的方式,直到A的pod数量变为0,最终 达到了滚动升级的目的。
同时,因为存在多个ReplicaSet,让回滚成为了可能
二、使用示例
示例yaml文件
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
template字段,指定了创建pod的模板
replicas指定了pod的节点数量
还有一个 type: RollingUpdate,指定了滚动升级的策略
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: ... strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1
查看deployments
kubectl get deployments demo2 -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR demo2 2/3 3 2 24d demo2 harbor.eoffcn.com/dev/demo2 workload.user.cattle.io/workloadselector=deployment-web-demo2
UP-TO-DATE:当前处于最新版本的 Pod 的个数,所谓最新版本指的是 Pod 的 Spec 部分与 Deployment 里 Pod 模板里定义的完全一致
AVAILABLE:当前已经可用的 Pod 的个数,即:既是 Running 状态,又是最新版本,并且已经处于 Ready(健康检查正确)状态的 Pod 的个数
READY:前处于 Running 状态的 Pod 的个数/用户期望的 Pod 副本个数
三、查看历史和回滚
查看历史版本
kubectl rollout history deployment ${name} deployment.extensions/demo2 REVISION CHANGE-CAUSE 1 <none> 2 <none> 3 <none> 4 <none>
查看指定版本
kubectl rollout history deployment ${name} --revision=${version}
回滚到上一版本
kubectl rollout undo deployment ${name}
回滚到指定版本
kubectl rollout undo deployment ${name} --to-revision=${version}
Recommend
-
134
pipeline The pipeline tutorial walks you through creating an end-to-end deployment pipeline using Cloud Container Builder,
-
77
I'm glad to announce the immediate availability of API Platform 2.2 beta 1. This is a huge release that comes with a lot of exciting features including (but not limited too): GraphQL and JSON API support Symfony 4 / Flex integration API Platform...
-
64
在之前的文章中,我们一直在讨论如何使用kubernetes,很多时候我们知道怎么使用kubectl命令行工作来启动一个POD,也看到我们在安装kubernetes 过程中使用了一些 YAML 文件来创建,但是发现很多朋友对 YAML 文件来创建一个 POD 还是非常陌生。所以我们来简单看看 YA...
-
55
kubernetes deploymet滚动升级操作
-
82
readme.md
-
66
我们接着前面的文章说,如果不清楚的请查看之前的博文:http://blog.51cto.com/wzlinux/2322616前面我们已经了解到,Kubernetes通过各种Controller来管理Pod的生命周期。为了满足不同业务场景,Kubernetes开发了Deployment、ReplicaSet、DaemonSet、StatefuleSet、...
-
58
README.md
-
58
If you happen to use established online applications like e.g. Gmail, or some the biggest social media or e-commerce platforms, you probably never encountered a static page asking you “Please wait while we updat...
-
51
如果你在生产环境中使用过 Kubernetes,那么相信你对 Deployment 一定不会陌生,Deployment 提供了一种对Pod 和ReplicaSet 的管理方式,每一个 Deployment 都对应集群中的一次部署,是非常常见的 Kubernetes 对象。 我们在这篇...
-
0
使用 Kubernetes 对象 Dockershim removal set for Kubernetes 1.24 As of Kubernetes 1.24, Dockershim will no longer be included in Kubernetes. Read the
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK