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"
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With