[英]Update deployment labels using “kubectl patch” does not work in v1.18
I am trying to update a label using kubectl v1.18.我正在尝试使用 kubectl v1.18 更新 label。
I tried kubectl patch deployment my-deployment --patch "$(cat patch1.yaml)";我试过 kubectl 补丁部署 my-deployment --patch "$(cat patch1.yaml)"; it returns an error
它返回一个错误
The Deployment "my-deployment" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"nginx"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable部署“my-deployment”无效:spec.selector:无效值:v1.LabelSelector{MatchLabels:map[string]string{"app":"nginx"},MatchExpressions:[]v1.LabelSelectorRequirement(nil)}:字段是不可变的
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
client: user
name: my-deployment
spec:
replicas: 1
selector:
matchLabels:
app: revproxy
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 2
template:
metadata:
creationTimestamp: null
labels:
app: revproxy
spec:
containers:
- image: nginx:1.7.9
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
The patch yaml is补丁 yaml 是
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
Note: In API version apps/v1, a Deployment's label selector is immutable after it gets created.
注意:在 API 版本 apps/v1 中,Deployment 的 label 选择器在创建后是不可变的。
Motivations for making label selector immutable are使 label 选择器不可变的动机是
If you want to make modification to label selector you will have to delete the exiting deployment and recreate it.如果要修改 label 选择器,则必须删除现有部署并重新创建它。
Modification to only metadata.labels
should work though.只修改
metadata.labels
应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.