Using kubectl set to update the container image

Use the kubectl set command allows us to overwrite the spec.template.spec.containers[].image property that is similar to using the kubectl run command to specify the image file. The following example specifies my-nginx deployment to set the container my-nginx to change the image to nginx version 1.12.0:

$ kubectl set image deployment my-nginx my-nginx=nginx:1.12.0 --record
deployment.apps "my-nginx" image updated


$ kubectl describe deploy my-nginx
Name: my-nginx


Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True ReplicaSetUpdated
OldReplicaSets: my-nginx-54bb7bbcf9 (3/3 replicas created)
NewReplicaSet: my-nginx-77769b7666 (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 27s deployment-controller Scaled up replica set my-nginx-54bb7bbcf9 to 3
Normal ScalingReplicaSet 2s deployment-controller Scaled up replica set my-nginx-77769b7666 to 1

As you can see, OldReplicaSets becomes the previous ReplicaSet (my-nginx-54bb7bbcf9) and NewReplicaSet becomes my-nginx-77769b7666. Note that you can see the OldReplicaSets property until NewReplicaSet is ready, so once the new ReplicaSet is successfully launched, OldReplicaSet becomes <none>, as follows:

$ kubectl describe deploy my-nginx
Name: my-nginx


Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: my-nginx-77769b7666 (3/3 replicas created)

If you can see the ReplicaSet list by kubectl get rs, you can see two ReplicaSet, as follows:

$ kubectl get rs
NAME DESIRED CURRENT READY AGE
my-nginx-54bb7bbcf9 0 0 0 3m
my-nginx-77769b7666 3 3 3 3m

As you can see, in the old ReplicaSet (my-nginx-54bb7bbcf9), the numbers of DESIRED/CURRENT/READY pods are all zero.

In addition, because the preceding example uses the --record option, you can see the history of the Deployment my-nginx rollout with the kubectl rollout history command, as follows:

$ kubectl rollout history deployment my-nginx
deployments "my-nginx"
REVISION CHANGE-CAUSE
1 kubectl create --filename=deploy.yaml --save-config=true --record=true
2 kubectl set image deployment/my-nginx my-nginx=nginx:1.12.0 --record=true
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.116.137