我创建了一个资源: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
查看所有可能的类型。类型应与 YAML 文件中的kind
值匹配,名称应与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