How do I edit a resource configuration with kubectl?

情到浓时终转凉″ 提交于 2019-12-12 15:08:41

问题


I've created a resource with: kubectl create -f example.yaml

How do I edit this resource with kubectl? Supposedly kubectl edit, but I'm not sure of the resource name, and kubectl edit example returns an error of:

the server doesn't have a resource type "example"

回答1:


You can do a kubectl edit -f example.yaml to edit it directly. Nevertheless I would recommend to edit the file locally and do a kubectl apply -f example.yaml, so it gets updated on Kubernetes.

Also: Your command fails, because you have to specify a resource type. Example types are pod, service, deployment and so on. You can see all possible types with a plain kubectl get. The type should match the kind value in the YAML file and the name should match metadata.name.

For example the following file could be edited with 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


来源:https://stackoverflow.com/questions/45502729/how-do-i-edit-a-resource-configuration-with-kubectl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!