我正在尝试使用kubectl v1.18更新标签。
我尝试了kubectl补丁部署my-deployment --patch“ $(cat patch1.yaml)”;它返回错误
部署“ 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
补丁yaml是
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
答案 0 :(得分:2)
从文档here
注意:在API版本apps / v1中,部署的标签选择器为 创建后便一成不变。
使标签选择器不可变的动机
如果要修改标签选择器,则必须删除现有部署并重新创建。
修改为仅metadata.labels
应该可以。