Shwetha:
kubectl edit deployment <xxx>
is used when you already have a deployment created and you want to edit it. vi xyz.yaml
is used to edit the yaml file, BUT editing the yaml file doesnt apply the changes. You need to either delete and recreate the resource (if it is a pod), else do a kubectl apply -f xyz.yaml
to create/edit the yaml file.
Shwetha:
Also kubectl edit deployment
is specific to editing deployments. You cannot edit other type of resources like pods, replicasets, persistent volumes, networkpolicies with the above command.
AnmM:
Hi @Shwetha - rather than editing the deployment, you can always copy the deployment yaml then delete the (old) deployment, make the changes in the deployment YAML and apply this new YAML to create the (new) deployment. This is better one.
Shwetha:
yes, there are more than one way of achieving the same. I prefer editing deployment directly as it saves precious time during exams.
AnmM:
So @Shwetha - If I edit the deployment it opens up it in a temp yaml file by kubectl exe. So if I say increase the replicas in it from 1 to 2, does it reflect immediately or how can I apply those changes ? Asking this Q as never used edit deployment.
Shwetha:
For updating the replicas, you can do kubectl scale deploy/<deployment_name> --replicas=2
no need to edit the deployment. Lets say you want to add more containers, nodeSelectors, probes etc. you can edit the deployment. It opens a temp yaml which you can edit. Once you save it, k8s applies the changes to the deployment after a validation. Changes are reflected within seconds. If you have made mistakes in the syntax, it saves it as a temp file giving you the location.
Shwetha:
Here is a reference for all commands: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
AnmM:
Hi @Shwetha - I just tried ‘kubectl edit deployment’ it is really fast than copying the yaml and applying it. Pod edit will also fast with edit I guess.
Shwetha:
You cannot edit the pod. It needs to be output as yaml, updated. Pod deleted and replaced with new pod. All of the exceptions are covered in the course.
AnmM:
Hi @Shwetha - I am learning livenesee and readiness probe in my deployment. But somehow its not working. Would you be able to help in that ?
I posted it in slack channel but no response from anyone.
Shwetha:
Do you have the link to the slack thread?