admin管理员组文章数量:1566356
k8s更新策略
https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
Strategy
.spec.strategy specifies the strategy used to replace old Pods by new ones.
.spec.strategy.type can be “Recreate” or “RollingUpdate”. “RollingUpdate” is the default value.
Recreate Deployment
All existing Pods are killed before new ones are created when .spec.strategy.type==Recreate.
Rolling Update Deployment
The Deployment updates Pods in a rolling update fashion when .spec.strategy.type==RollingUpdate.
You can specify maxUnavailable and maxSurge to control the rolling update process.
Max Unavailable
.spec.strategy.rollingUpdate.maxUnavailable is an optional field that specifies
the maximum number of Pods that can be unavailable during the update process.
The value can be an absolute number (for example, 5) or a percentage of desired Pods
(for example, 10%). The absolute number is calculated from percentage by rounding down.
The value cannot be 0 if .spec.strategy.rollingUpdate.maxSurge is 0. The default value is 25%.
For example, when this value is set to 30%, the old ReplicaSet can be scaled down to 70% of
desired Pods immediately when the rolling update starts. Once new Pods are ready,
old ReplicaSet can be scaled down further, followed by scaling up the new ReplicaSet,
ensuring that the total number of Pods available at all times during the update is
at least 70% of the desired Pods.
Max Surge
.spec.strategy.rollingUpdate.maxSurge is an optional field that specifies the maximum number
of Pods that can be created over the desired number of Pods. The value can be an absolute
number (for example, 5) or a percentage of desired Pods (for example, 10%). The value cannot
be 0 if MaxUnavailable is 0. The absolute number is calculated from the percentage by rounding up.
The default value is 25%.
For example, when this value is set to 30%, the new ReplicaSet can be scaled up immediately
when the rolling update starts, such that the total number of old and new Pods does not exceed
130% of desired Pods. Once old Pods have been killed, the new ReplicaSet can be scaled up further,
ensuring that the total number of Pods running at any time during the update is at most 130%
of desired Pods.
maxSurge:滚动更新时最多可以多启动多少个pod
maxUnavailable:滚动更新时最大可以删除多少个pod
maxSurge和maxUnavailable可以用来决定更新是的最大pod数和最小pod数
是先启动一个pod再删除一个pod还是先删除一个pod再启动一个pod
例如
replicas是5
maxSurge: 1
maxUnavailable: 0
更新时 最大的pod数是 replicas+ maxSurge = 5+1 =6,最大的个数是6
最小pod数是 replicas - maxUnavailable = 5-0 = 5,最小pod数是5,所以只能先启动一个pod,再删除一个pod
demo
apiVersion: apps/v1
kind: Deployment
metadata:
name: testStrategy
labels:
app: testStrategy
spec:
replicas: 5
strategy: #升级策略(默认为滚动升级,不需要修改)
type: RollingUpdate
rollingUpdate:
maxSurge: 25% #滚动升级中,容器副本的最大数量(默认值,可根据实际情况修改)
maxUnavailable: 25% #滚动升级中,容器副本停止的最大数量(默认值,可根据实际情况修改)
本文标签: 策略K8sdeploymentStrategy
版权声明:本文标题:k8s deployment Strategy 更新策略 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1725700298a1037386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论