On the road again

The article describes basic commands for managing k8s Deployments

Deployment is a k8s object built on top of ReplicaSets and Pods, the main aim is to provide seamless rolling updates.
 
Example deployment.yml:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: hello-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-pod
        image: nigelpoulton/k8sbook:latest
        ports:
        - containerPort: 8080
 
Some parameters description:
Update using the RollingUpdate strategy
Only ever have one Pod unavailable ( maxUnavailable: 1 )
Never go more than one Pod above the desired state ( maxSurge: 1 )
 
Create deployment:
kubectl create -f ./deployment.yml
 
The simpler way to create a new deployment for a single-container pod is to use kubectl run:
kubectl run echoserver --image=k8s.gcr.io/echoserver:1.5 --port=8080 --replicas=2
 
Inspect deployment:
kubectl get deploy
kubectl describe deploy
 
Edit deployment:
kubectl edit deployment echoserver
 
To perform a rolling update:
1. Change deployment manifest (e.g. change the docker image)
2. Apply the manifest:  kubectl apply -f  ./deployment.yml --record ("--record" saves the rollout revision to a history hence it is very simple to perform a rollback to certain revision)
3. Monitor rolling update process:   kubectl rollout status deployment hello-deploy
4. View revision history: kubectl rollout history deployment hello-deploy
 
To undo the deployment to certain revision (perform a rollback):
kubectl rollout undo deployment hello-deploy --to-revision=1
 
Add comment