DEV Community

Cheedge Lee
Cheedge Lee

Posted on • Originally published at Medium

CKA Recap -- Deployment

Deployment

Basic CMD

# Create
kubectl create deploy NAME --image=IMAGE --replica NUM
# Scale (or use kubectl edit)
kubectl scale deploy NAME --replicas NUM
# Change image of deploy
kubectl set image deployments/DP_NAME ContainerName=IMAGE
k set image deployments/apache httpd=httpd:alpine
Enter fullscreen mode Exit fullscreen mode

When using kubectl create cmd create the deployment, it will automatically add the same labels for both deployment and pods. So if you want to customize the label, it's better to print out --dry-run=client -oyaml the yaml file and have a check.

And if not clear the container name, can use following to find it

k get pod NAME -oyaml | grep -3 -i container
Enter fullscreen mode Exit fullscreen mode

Rollout

k rollout history deployment/DP_NAME
k rollout history deployment/DP_NAME --revision REV_NUM
k rollout undo deployment/DP_NAME --to-revision REV_NUM
k rollout status deployment DP_NAME
Enter fullscreen mode Exit fullscreen mode
controlplane $ k rollout history deployment video-app
deployment.apps/video-app 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
3         <none>
controlplane $ k rollout history deployment/video-app --revision 3
deployment.apps/video-app with revision #3
Pod Template:
  Labels:       app=video-app
        pod-template-hash=69648db755
  Containers:
   redis:
    Image:      redis:7.0.13
    Port:       <none>
    Host Port:  <none>
    Environment:        <none>
    Mounts:     <none>
  Volumes:      <none>
  Node-Selectors:       <none>
  Tolerations:  <none>
controlplane $ k rollout undo deployment/video-app --to-revision 3
deployment.apps/video-app skipped rollback (current template already matches revision 3)
Enter fullscreen mode Exit fullscreen mode

Rolling Strategy

.spec.strategy.rollingUpdate.Unavailable and .spec.strategy.rollingUpdate.maxSurge

  • Max Unavailable
    • unavailable during the update process.
  • Max Surge
    • specifies the maximum number of Pods that can be created over the desired number of Pods
 strategy:
   type: RollingUpdate
   rollingUpdate:
     maxSurge: 30%
     maxUnavailable: 45%
Enter fullscreen mode Exit fullscreen mode

.spec.strategy.type==Recreate, and we can also destroy all existing pods first then create the new pods.

 strategy:
   type: Recreate
Enter fullscreen mode Exit fullscreen mode

Top comments (0)