Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I edit a resource configuration with kubectl?

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"
like image 348
Chris Stryczynski Avatar asked Aug 04 '17 09:08

Chris Stryczynski


People also ask

How do I edit a pod configuration file?

Edit a PODRun the kubectl edit pod <pod name> command. This will open the pod specification in an editor (vi editor). Then edit the required properties.

How do you use the kubectl edit command?

To use the kubectl edit command, create a KUBE_EDITOR environment variable and specify your preferred text editor as the variable value. In addition, append the watch flag ( -w ) to the value so that kubectl knows when you have committed (saved) your changes.

How do I edit service in kubectl?

Synopsis. Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows.


1 Answers

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
like image 63
svenwltr Avatar answered Sep 23 '22 06:09

svenwltr