How do I edit a resource configuration with kubectl?

8/4/2017

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"
-- Chris Stryczynski
kubectl
kubernetes

1 Answer

8/4/2017

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
-- svenwltr
Source: StackOverflow