Kubernetes rolling deployment using the yaml file

7/12/2018

I have deployed an application into kubernetes using the following command.

kubectl apply -f deployment.yaml -n <NAMESPACE>

I have my deployment content in the deployment yaml file.

This is working fine. Now, I have updated few things in the deployment.yaml file and hence would like to update the deployment.

Option 1:- Delete and deploy again

kubectl delete -f deployment.yaml -n <NAMESPACE>
kubectl apply -f deployment.yaml -n <NAMESPACE>

Option 2:- Use set to update changes

kubectl set image deployment/nginx-deployment nginx=nginx:1.91

I dont want to use this approach as i am keeping my deployment.yaml file in GitHUB.

Option 3:- Using edit command

kubectl edit deployment/nginx-deployment

I dont want to use the above 3 options.

Is there any way to update the deployment using the file itself.

Like,

kubectl update deployment.yaml -n NAMESPACE

This way, I will make sure that I will always have the latest deployment file in my GITHUB.

Thanks

-- user1578872
kubernetes

1 Answer

7/12/2018

As @Daisy Shipton has said, what you want to do could be simplified with a simple command: kubectl apply -f deployment.yaml.

I will also add that I don't think it's correct to utilize the Option 2 to update the image utilized by the Pod with an imperative command! If the source of truth is the Deployment file present on your GitHub, you should simply update that file, by modifying the image that is used by your Pod's container there!

  • Next time you desire to update your Deployment object, unless you don't forget to modify the .yaml file, you will be setting the Pods to use the previous Nginx's image.

So there certainly should exist some restriction in using imperative commands to update the specification of any Kubernetes's object!

-- André B
Source: StackOverflow