kubernetes 101 : "kubectl edit" - Troubleshooting the "Error: At least one of apiVersion, kind and name was changed" -



When trying to edit the configuration of a kubernetes resource using the "kubectl edit", we might get the below error:

error: At least one of apiVersion, kind and name was changed

For example we have the below pod:

After creating the pod using the below command:


We can modify its parameters using the below command:


It opens the editor mentioned in the environment variable (KUBE-EDITOR), then we change the name of the pod to "nginx-pod-changed" for example:


When we save the file, we get the above error:

error: At least one of apiVersion, kind and name was changed

Also we get the below message, when we try to change other parameters like the container's port with the "kubectl edit":


The reason is that some parameters like the name of a kubernetes resource, its kind and apiVersion can't be changed. 
We would have to delete the resource and re-create it with the new parameters.

An example of a parameter that could be changed using the "kubectl edit" command is the image of the container

Comments

Leave as a comment:

Archive