时间: 2020-09-3|tag:67次围观|0 条评论


kubectl patch

使用(patch)补丁修改、更新资源的字段。

支持JSON和YAML格式。

请参阅https://htmlpreview.github.io/?https://github.com/kubernetes/kubernetes/blob/HEAD/docs/api-reference/v1/definitions.html中说明,查找资源字段是否为可变的。

语法

$ patch (-f FILENAME | TYPE NAME) -p PATCH

示例

使用patch更新Node节点。

kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'

使用patch更新由“node.json”文件中指定的类型和名称标识的节点

kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}'
更新容器的镜像
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'

 更改service类型为NodePort形式

kubectl patch  svc schedule -n uat --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"},{"op":"add","path":"/spec/ports/0/nodePort","value":30930}]'kubectl patch svc schedule -n uat --type='json' -p '[{"op":"remove","path":"/spec/ports/0/nodePort"},{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'

 给pod手动添加dns解析

kubectl -n monitoring patch  deployments prometheus-grafana --patch '{    "spec": {        "template": {            "spec": {                "hostAliases": [                    {                        "hostnames":                        [                            "prometheus-prometheus-oper-prometheus"                        ],                            "ip": "10.233.10.10"                    }                ]            }        }    }}'

 

文章转载于:https://www.cnblogs.com/Dev0ps/p/12724455.html

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《Kubectl patch命令使用
   

还没有人抢沙发呢~