
上QQ阅读APP看书,第一时间看更新
Editing a Deployment
This recipe will take you through the instructions to edit an existing Kubernetes object, and you will learn how to change a Deployment object's parameters when needed.
Let's perform the following steps:
- Edit the Deployment object and change the container image from image nginx 1.7.9 to image nginx 1.16.0:
$ kubectl edit deployment nginx-deployment
- You can see that the Deployment first goes into pending termination and later the rollout status shows a successfully rolled out message after you run the following command:
$ kubectl rollout status deployment nginx-deployment
Waiting for deployment "nginx-deployment" rollout to finish: 1 old replicas are pending termination...
deployment "nginx-deployment"
- Confirm that your Deployment spins up the new pods by creating a new ReplicaSet and scaling down the old one from 2 to 0:
$ kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5c689d88bb 0 0 0 36m
nginx-deployment-f98cbd66f 2 2 2 46s
- We will create a change cause annotation. The following command will add the description defined in the kubernetes.io/change-cause parameter to your current Deployment:
$ kubectl annotate deployment nginx-deployment kubernetes.io/change-cause="image updated to 1.16.0"
- Now, as an alternative way to edit a Deployment, edit the deployment-nginx.yaml file and change the replicas from replicas: 2 to replicas: 3 and nginx:1.7.9 to image: nginx:1.17.0:
$ nano deployment-nginx.yaml
- Update the Deployment by applying the updated YAML manifest with your changes. This step will apply the change of image tag used for the Deployment and the number of replicas we increased in step 5:
$ kubectl apply -f deployment-nginx.yaml
- Confirm that your Deployment spins up the new pods by creating a new ReplicaSet and scaling down the old pods:
$ kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5c689d88bb 0 0 0 56m
nginx-deployment-5d599789c6 3 3 3 15s
nginx-deployment-f98cbd66f 0 0 0 20m
- Create another change cause annotation by defining the changes we made using the kubernetes.io/change-cause parameter:
$ kubectl annotate deployment nginx-deployment kubernetes.io/change-cause="image updated to 1.17.0 and scaled up to 3 replicas"
Now you have learned how to edit, scale up, and also roll out a new version of the application using a ReplicaSet.