kubernetes - k8s yaml文件中标签策略的不同值有什么区别
问题描述
我用两个 yaml 文件进行测试,只有标签策略不同
第一:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
test.k8s: test
name: test
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
test.k8s: test
spec:
containers:
- name: test
image: alpine3.6
imagePullPolicy: IfNotPresent
...
第二:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
test.k8s: test
name: test
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
test.k8s: test
spec:
containers:
- name: test
image: alpine3.6
imagePullPolicy: IfNotPresent
...
然后我使用 kubectl patch 和 kubectl replace 命令更新部署。似乎只有新的 pod 开始时间不同。当新的 pod 启动失败并丢失图像时,旧的 pod 将在这两种情况下最终终止。
有人知道吗?
非常感谢~
解决方案
基本上,.spec.strategy
标签指定集群引擎如何用新 Pod 替换旧 Pod。
在您的情况下,.spec.strategy.type==Recreate
标签告诉集群引擎在创建新 Pod 之前终止(杀死)所有现有 Pod。
至于第二个例子,.spec.strategy.type==RollingUpdate
标签描述了在没有临时中断的情况下更新服务的方法,因为它涉及每次更新一个 pod 以避免服务不可用。
从您的示例中,有两个参数定义了 RollingUpdate 策略:
.spec.strategy.rollingUpdate.maxUnavailable
- 表示更新过程中不可用的 Pod 的最大数量。
.spec.strategy.rollingUpdate.maxSurge
- 指定在所需 Pod 数量上可以创建的最大 Pod 数量。
您可以考虑在 中使用几个附加参数RollingUpdate
,有关更多信息,请参阅文档。
通过使用kubectl replace
命令,您可以重新创建策略并重建对象,但不能更新。
推荐阅读
- c# - 将 2 字节值转换为顶点值
- c# - 防止在同一位置连续生成预制件
- vba - 如何在报表代码中引用表单对象
- amazon-web-services - 有没有办法轻松获取特定 AWS Lambda 执行的日志条目?
- python - 如何使用 manim 从非场景类播放动画?
- c++ - C ++:在没有取消引用运算符的情况下访问“数组指针”的值?
- python - 将 bs4 的 get_text() 输出转换为带有标题的 csv
- python - 加入数百个 IRC 频道套接字死亡(抽搐)
- aem - AEM 6.5.3 - WCM IO 问题 - 在上下文感知配置页面上显示标签 ID 而不是标签值
- reactjs - 在可重用组件中呈现不同的 html