Amer Nureddin:
Hello guys,
If I want to edit a deployment, what is the best practice? is it to run kubectl edit pod <pod inside deployment>
or directly kubectl edit deployment
?
and what are the things that can be edited and cannot be edited using the edit
command ? in the case that cannot be edited I mean that I have to delete the resource and re create it again…
Eyal Solomon:
Hey @Amer Nureddin
Pods are part of a deployment
lets say you have a Deployment with 10 replicas within it ( 10 Pods)
If you do
kubectl edit pod X
You will only edit THIS Pod configuration
So you will probably want to edit the Deployment itself.
REMEMBER that in both cases it will be hard to track/remember changes you made this way
NOTICE that BEST PRACTICE is to have the Deployment as a .yaml file and just make the changes and
kubectl apply -f X.yaml
Eyal Solomon:
@unnivkn correct me if im wrong
Amer Nureddin:
Thank you @Eyal Solomon
actually in my case it was a deployment with 1 pod
and I know the case that a deployment may has many pods,
but when I run the kubectl edit deployments do I get everything that is related to my pod/pods ? or there are some things/parameters that can only be edited from the kubectl edit pod ?
lets say I want to edit the service account name within a pod is it doable from the edit deployment or from edit pod?
Eyal Solomon:
Thats a good question
If you edit a Deployment ALL Pods will use new configuration / get re-created
There are some properties that CANNOT be edit so you need to re-create the Deployment/Pod
As of your question - if you want ONLY this Pod to use that service account you can use
kubectl edit pod x
make sure service account isn’t a property that require a re-creation
I will still sugged using a .yaml file and not edit
Eyal Solomon:
@Amer Nureddin
Amer Nureddin:
great! thanks @Eyal Solomon
is there a list that contains the things that can be edited without re-creation?
and can we consider deleting the resource (pod/deployment/svc etc…) and re creating it from a .yaml file as a best practice?
Eyal Solomon:
@Amer Nureddin
Im also not sure about all of the properties
if you find the list PM me
you can use
kubectl replace -f X.yaml
it will do
deployment.apps/X deleted
deployment.apps/X replaced
To change fields that cannot be updated once initialized, use replace --force
, which deletes and re-creates the resource immediately
unnivkn:
I suggest edit the pod template inside the deployment yaml. The purpose of deployment is to have multiple instances of same application. Regarding edit we have to learn from experience, there is no specific list available.