نشر Canary إلى Kubernetes # 1: Gitlab CI

سنستخدم Gitlab CI و GitOps اليدوية لتنفيذ عمليات نشر Canary واستخدامها في Kubernetes.








مقالات من هذه الدورة:



  1. (هذه المقالة)
  2. انتشار الكناري مع ArgoCI
  3. انتشار الكناري مع Istio
  4. انتشار Canary مع Jenkins-X و Istio و 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