Skip to content

Latest commit

 

History

History

04-deployment

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Deployment

  1. Create Deployment

    kubectl apply -f deployment.yaml
    
  2. Check

    kubectl get deployment
    
    kubectl get replicaset
    
    kubectl get replicaset nginx-xxxx -o yaml
    
    • You can see the replicaset is created by Deployment in ownerReferences field.
    • You can also see pod-template-hash, which is added by Deployment.
    kubectl get pod
    
  3. Change replicas

    1. Update replicas: 2 in deployment.yaml

    2. Apply it

      kubectl apply deployment.yaml
      

      rollout isn't triggered as replica is not in the pod template.

  4. Change image by command

    kubectl set image deployment/nginx nginx=nginx:1.15
    

    check:

    kubectl get rs
    

    You can see two replicasets; one is old one, the other is new one.

  5. Change image by updating yaml file.

    1. Change nginx:1.14 -> nginx:1.15 in deployment.yaml

    2. Apply it

      kubectl apply -f deployment.yaml
      
    3. You can check the replicasets

      kubectl get replicaset
      

      -> 3 replicasets

  6. Rollback

    1. Check rollout history.

      kubectl rollout history deployment.v1.apps/nginx
      
    2. Roll back to the revision 2

      kubectl rollout undo deployment.v1.apps/nginx --to-revision=2
      
    3. Check replicaset

      kubectl get rs
      

      -> replicaset with nginx:1.15 has running pods.

  7. Delete the resources

    kubectl delete -f deployment.yaml