在使用kubectl apply操作workload产生的非预期行为:修订间差异
来自三线的随记
(创建页面,内容为“先创建一个普通的deployment apiVersion: apps/v1 kind: Deployment metadata: labels: sit.k8s.io/app: yaml-test name: yaml-test spec: replicas:…”) |
小无编辑摘要 |
||
| 第83行: | 第83行: | ||
ip: 1.1.1.8 | ip: 1.1.1.8 | ||
containers: | containers: | ||
- image: 192.168.150.181/ | - image: 192.168.150.181/test/nginx-2048:latest | ||
imagePullPolicy: IfNotPresent | imagePullPolicy: IfNotPresent | ||
name: yaml-test | name: yaml-test | ||
| 第114行: | 第114行: | ||
这个也是跟k8s apply的实现方式有关系 | 这个也是跟k8s apply的实现方式有关系 | ||
Related article: [[K8s的一些小坑或者bug简要记录]] | |||
[[分类:K8s]] | [[分类:K8s]] | ||
{{DEFAULTSORT:apply}} | {{DEFAULTSORT:apply}} | ||
2023年6月9日 (五) 17:52的版本
先创建一个普通的deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
sit.k8s.io/app: yaml-test
name: yaml-test
spec:
replicas: 1
selector:
matchLabels:
sit.k8s.io/app: yaml-test
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
sit.k8s.io/app: yaml-test
sit.k8s.io/app: yaml-test
name: yaml-test
spec:
hostAliases:
- hostnames:
- testaaaa.com
- testbbb.com
ip: 1.1.1.7
containers:
- image: 192.168.150.181/test/nginx-2048:latest
imagePullPolicy: IfNotPresent
name: yaml-test
readinessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
resources:
limits:
cpu: "1"
memory: "64Mi"
requests:
cpu: 64m
memory: "64Mi"
dnsPolicy: ClusterFirst
restartPolicy: Always
然后修改一下hostAliases的值,执行kubectl apply -f xxx.yaml --dry-run=server -oyaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
sit.k8s.io/app: yaml-test
name: yaml-test
spec:
replicas: 1
selector:
matchLabels:
sit.k8s.io/app: yaml-test
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
sit.k8s.io/app: yaml-test
sit.k8s.io/app: yaml-test
name: yaml-test
spec:
hostAliases:
- hostnames:
- testaaaa.com
- testbbb.com
ip: 1.1.1.8
containers:
- image: 192.168.150.181/test/nginx-2048:latest
imagePullPolicy: IfNotPresent
name: yaml-test
readinessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
resources:
limits:
cpu: "1"
memory: "64Mi"
requests:
cpu: 64m
memory: "64Mi"
dnsPolicy: ClusterFirst
restartPolicy: Always
会发现apply以后的结果hostAliases字段非预期(1.1.1.8直接被追加了进去,而不是替换)
或者一开始使用apply创建资源,然后删除kubectl.kubernetes.io/last-applied-configuration: ,再修改ip,再apply
如果一开始是用kubectl apply -f xxxx创建资源,然后用apply -f更新资源,则不会复现
这个也是跟k8s apply的实现方式有关系
Related article: K8s的一些小坑或者bug简要记录