【发布时间】:2017-08-04 09:10:17
【问题描述】:
我创建了一个资源:
kubectl create -f example.yaml
如何使用 kubectl 编辑此资源?据说是kubectl edit,但是我不确定资源名,kubectl edit example返回错误:
the server doesn't have a resource type "example"
【问题讨论】:
标签: kubernetes kubectl
我创建了一个资源:
kubectl create -f example.yaml
如何使用 kubectl 编辑此资源?据说是kubectl edit,但是我不确定资源名,kubectl edit example返回错误:
the server doesn't have a resource type "example"
【问题讨论】:
标签: kubernetes kubectl
您可以通过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
【讨论】:
example.yaml 的内容?
apply 会给我一个警告:Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply。 kubectl replace -f example.yaml 似乎在没有警告的情况下实现了上述目标。