deployment in a environment

we not want to update all of the running pod as once. So we can pause some pods and update some others. Deployments stays higher then replicasets which stays higher then pods which stays hihger than containers…

herachie:

  • deployments
    • replicasets
      • pods
        • container

create deployment-definition.yml file

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
    app: myapp
    type: front-end

spec:
  template:
    metadata:
      name: nginx
      labels:
        apps: nginx
        type: front-end
    spec:
      containers:
        - name: nginx
          image: nginx
  replicas: 3
  selector: 
    matchLabels:
      type: front-end

apply deployment

# apply yaml file
> kubectl create -f deployment-definition.yml

# show depoloyments
> kubectl get deployments

# show rs
> kubectl get replicaset

# show pods
> kubectl get pods

# desribe deployment
> kubectl describe deployments.apps myapp-deployment

# get all - which is very nice
> kubectl get all 

# delete deployment
> kubectl delete deployments myapp-deployment

updates and rolebacks in a deployment

When first creates a deployment it triggers a rollout. A new rollout creates a new deployment - we call it revision 1 as example. When we create a updated deployment we creates a revision 2 of our rollout.

manage rollouts

# get rollout sttaus
> kubectl rollout status deployment myapp-deployment
> kubectl rollout status deployment/myapp-deployment

# get history revisions
> kubectl rollout status deployment myapp-deployment

there are 2 types of deployment strategies

  • one type to upgrade is to destroy all running instances ansd created a new one which will result in a downtime

    • recreate strategie
  • the second is to not delete all running instances at once - just one by one

    • rolling update - which is the default strategie

we can change the nginx version in our deployment and upgrade our deployment
> kubectl apply -f deployment-defini.yml

A new rollout created and run a new deployment. This makes a lot of fun. Here is the point which makes kubernetes fantastic for me.

image changing can also be done over the console but this is just temporaly - nice for testing

> kubectl set image deployment myapp-deployment redis=redis
> kubectl set image deployment myapp-deployment nginx=nginx:1.7.1

the image have to exist


the difference between Recreate and RollingUpdate

  • Recreate waits until a replicaset is down and then it creates a new one
  • RollingUpdate scales the old rs down and creates the new one simultaniously

upgrades

When a new deployment is created with 5 replicas. RollingUpdate first creates a rs automaticly - under the hood a new replicaset is created and updated this one pod to another.

rollback to previuos using undo

# set an not existing container to deployment - rs will not start
> kubectl set image deployment myapp-deployment nginx=nginx:latest-test

# undo rollout to previously version 
> kubectl rollout undo deployment myapp-deployment

# show rollout deployment status
> kubectl rollout status deployment myapp-deployment

# show rollout rs status - live status
> kubectl rollout status rs myapp-deployment-867c9776f7

# show revision history and change reasons
> kubectl rollout history deployment myapp-deployment

removing the deployment will also remove all replicasets - playing arround here for a while to get practice

# get StrategyType
> kubectl describe deployment myapp-deployment
...
StrategyType:           RollingUpdate
...