Canary Deployment to Kubernetes # 1: Gitlab CI

We will be using Gitlab CI and manual GitOps to implement and use Canary deployments in Kubernetes.








Articles from this cycle:



  1. (this article)
  2. Canary Deployment with ArgoCI
  3. Canary Deployment with Istio
  4. Canary Deployment with Jenkins-X, Istio and Flagger


Canary- GitOps / Kubernetes. , Kubernetes Canary , , .





https://www.norberteder.com/canary-deployment/



Canary Deployment



Canary- . , , .



Kubernetes Deployment (rolling update)



Kubernetes Deployment β€” rolling-update, . , , .



GitOps



GitOps , :



  • Git
  • Git Operations ( , git tag/merge )




β€” .





API Python+Flask, JSON. GitlabCI Gitlab Registry. :



  • wuestkamp/k8s-deployment-example-app:v1
  • wuestkamp/k8s-deployment-example-app:v2


JSON-. , .





GitlabCI Kubernetes, .gitlab-ci.yml :



image: traherom/kustomize-docker

before_script:
   - printenv
   - kubectl version

stages:
 - deploy

deploy test:
   stage: deploy
   before_script:
     - echo $KUBECONFIG
   script:
     - kubectl get all
     - kubectl apply -f i/k8s

   only:
     - master


, Gcloud:



gcloud container clusters create canary --num-nodes 3 --zone europe-west3-b

gcloud compute firewall-rules create incoming-80 --allow tcp:80


https://gitlab.com/wuestkamp/k8s-deployment-example-canary-infrastructure KUBECONFIG GitlabCI, kubectl .



, (Gcloud) .



Yaml



service:



apiVersion: v1
kind: Service
metadata:
 labels:
   id: app
 name: app
spec:
 ports:
 - port: 80
   protocol: TCP
   targetPort: 5000
 selector:
   id: app
 type: LoadBalancer


deployment deploy.yaml:



apiVersion: apps/v1
kind: Deployment
metadata:
 name: app
spec:
 replicas: 10
 selector:
   matchLabels:
     id: app
     type: main
 template:
   metadata:
     labels:
       id: app
       type: main
   spec:
     containers:
     - image: registry.gitlab.com/wuestkamp/k8s-deployment-example-app:v1
       name: app
       resources:
         limits:
           cpu: 100m
           memory: 100Mi


deployment deploy-canary.yaml:



kind: Deployment
metadata:
 name: app-canary
spec:
 replicas: 0
 selector:
   matchLabels:
     id: app
     type: canary
 template:
   metadata:
     labels:
       id: app
       type: canary
   spec:
     containers:
     - image: registry.gitlab.com/wuestkamp/k8s-deployment-example-app:v2
       name: app
       resources:
         limits:
           cpu: 100m
           memory: 100Mi


, app-deploy .





deployment GitlabCI -. kubectl :








app deployment c 10 app-canary 0. LoadBalancer curl External IP:



while true; do curl -s 35.198.149.232 | grep label; sleep 0.1; done








, β€œv1”.



Canary



1:



1 deploy-canary.yaml :



kind: Deployment
metadata:
 name: app-canary
spec:
 replicas: 1
 selector:
   matchLabels:
     id: app
     type: canary
 template:
   metadata:
     labels:
       id: app
       type: canary
   spec:
     containers:
     - image: registry.gitlab.com/wuestkamp/k8s-deployment-example-app:v2
       name: app
       resources:
         limits:
           cpu: 100m
           memory: 100Mi


deploy.yaml 9:



kind: Deployment
metadata:
 name: app
spec:
 replicas: 9
 selector:
   matchLabels:
     id: app
...


, ( GitlabCI) :








Service , app. - Kubernetes ~ 10% :








(GitOps, Git Single Source Of Truth) deployments c , .



~10% . .



2:



, . deploy.yaml , 10. deploy-canary.yaml 0. :










k8s. Kubernetes API, .



, β€” (LoadBalancer Ingress), . .



, , .



:






All Articles