容器编排技术 -- Kubernetes kubectl edit 命令详解

容器编排技术 -- Kubernetes kubectl edit 命令详解

 

kubectl edit

使用默认编辑器 编辑服务器上定义的资源。

使用命令行工具获取的任何资源都可以使用edit命令编辑。edit命令会打开使用KUBE_EDITOR,GIT_EDITOR 或者EDITOR环境变量定义的编辑器,可以同时编辑多个资源,但所编辑过的资源只会一次性提交。edit除命令参数外还接受文件名形式。

文件默认输出格式为YAML。要以JSON格式编辑,请指定“-o json”选项。

如果在更新资源时报错,将会在磁盘上创建一个临时文件来记录。在更新资源时最常见的错误是几个用户同时使用编辑器更改服务器上资源,发生这种情况,你需要将你的更改应用到最新版本的资源上,或者更新保存的临时副本。

语法

$ edit (RESOURCE/NAME | -f FILENAME)

示例

编辑名为'docker-registry'的service:

kubectl edit svc/docker-registry

使用替代的编辑器

KUBE_EDITOR="nano" kubectl edit svc/docker-registry

编辑名为“myjob”的service,输出JSON格式 V1 API版本

kubectl edit job.v1.batch/myjob -o json

以YAML格式输出编辑deployment“mydeployment”,并将修改的配置保存在annotation中:

kubectl edit deployment/mydeployment -o yaml --save-config

Flags

NameShorthandDefaultUsage
filenamef[]Filename, directory, or URL to files to use to edit the resource
include-extended-apis trueIf true, include definitions of new APIs via calls to the API server. [default true]
outputoyamlOutput format. One of: yaml|json.
record falseRecord current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.
recursiveRfalseProcess the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
save-config falseIf true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schemaIf non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
validate trueIf true, use a schema to validate the input before sending it
windows-line-endings falseUse Windows line-ending
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值