我有一个配置映射,如下所示:
kubectl describe configmap example-config --namespace kube-system
Name: example-config
Namespace: kube-system
Labels: <none>
Annotations: <none>
Data
====
mapRoles:
----
- rolearn: arn:aws:iam::0123456789012:role/user-role-1
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
- rolearn: arn:aws:iam::0123456789012:role/user-role-2
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
我想从配置映射中删除user-role-2。我想我需要使用带有";删除";活动从配置映射中删除部分的语法是什么?
下面是一个我可以用来附加到配置映射的示例命令:
kubectl patch -n=kube-system cm/aws-auth --patch "{"data":{"mapRoles": "- rolearn: "arn:aws:iam::0123456789012:role/user-role-3" n username: system:node:{{EC2PrivateDNSName}}n groups:n - system:bootstrappersn - system:nodesn"}}"
根据kubernetes官方文档:https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/
kubectl patch
中没有像配置映射那样从api对象中删除节的语法。
下面是一个我可以用来附加到配置映射的示例命令:
kubectl patch -n=kube-system cm/aws-auth --patch "{"data":{"mapRoles": "- rolearn: "arn:aws:iam::0123456789012:role/user-role-3" n username: system:node:{{EC2PrivateDNSName}}n groups:n - system:bootstrappersn - system:nodesn"}}"
上面的命令用于替换configmap中的整个数据字段。因此,您可以简单地使用它来修补更新所需的数据:
kubectl patch -n=kube-system cm/example-config --patch '{"data":{"mapRoles": "- rolearn: arn:aws:iam::0123456789012:role/user-role-1n username: system:node:{{EC2PrivateDNSName}}n groups:n - system:bootstrappers
n - system:nodes"}}'
我认为最简单的方法是这样的:
kubectl get configmaps foo -o yaml > foo.yaml
现在按照您想要的方式编辑foo.yaml
然后应用您的新配置:
kubectl apply -f foo.yaml