简体   繁体   中英

Kubernetes rolling deployment using the yaml file

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 don't 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 don't 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 repo.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM