我创建了一个资源:kubectl create -f example.yaml
如何使用 kubectl 编辑此资源?据说 kubectl edit
,但我不确定资源名称,以及 kubectl edit example
返回错误:
the server doesn't have a resource type "example"
最佳答案
你可以做一个 kubectl edit -f example.yaml
直接编辑它。尽管如此,我还是建议在本地编辑文件并执行 kubectl apply -f example.yaml
,所以它会在 Kubernetes 上更新。
另外:您的命令失败,因为您必须指定资源类型。示例类型为 pod
, service
, deployment
等等。您可以使用普通 kubectl get
查看所有可能的类型.类型应该匹配 kind
YAML 文件中的值和名称应匹配 metadata.name
.
例如,可以使用 kubectl edit deployment nginx-deployment
编辑以下文件
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2 # tells deployment to run 2 pods matching the template
template: # create pods using pod definition in this template
metadata:
# unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
# generated from the deployment name
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
关于kubernetes - 如何使用 kubectl 编辑资源配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45502729/