Canary Deployments To Kubernetes Using Istio and Friends

Делаю:
21.01.2021


09 Integrating Canary Deployments With Continuous Delivery

https://gist.github.com/8523efa6e7b1f0d48c1fda4f347ca55b


######################
# Installing Flagger
######################


$ kubectl apply \
 --kustomize github.com/weaveworks/flagger/kustomize/istio


#####################
# Deploying The App
#####################


$ cd go-demo-7


$ kubectl create namespace go-demo-7


$ kubectl label namespace go-demo-7 \
 istio-injection=enabled


$ kubectl --namespace go-demo-7 apply \
 --filename k8s/istio/flagger-full/db \
 --recursive


$ kubectl --namespace go-demo-7 apply \
 --filename k8s/istio/flagger-full/app \
 --recursive


$ kubectl --namespace go-demo-7 \
 rollout status \
 deployment go-demo-7


$ kubectl --namespace go-demo-7 \
 rollout status \
 deployment go-demo-7-primary


$ kubectl --namespace go-demo-7 \
 get deployments


NAME                READY   UP-TO-DATE   AVAILABLE   AGE
go-demo-7           2/2     2            2           2m19s
go-demo-7-db        1/1     1            1           2m24s
go-demo-7-primary   2/2     2            2           23s


$ chmod +x k8s/istio/get-ingress-host.sh


$ INGRESS_HOST=$(\
 ./k8s/istio/get-ingress-host.sh \
 $PROVIDER)


$ echo ${INGRESS_HOST}


$ curl -H "Host: go-demo-7.acme.com" \
 "http://$INGRESS_HOST/version"
Version: 0.0.1; Release: unknown


##############
# The Script
##############


$ kubectl --namespace go-demo-7 \
 get canary go-demo-7 \
 --output yaml


$ kubectl --namespace go-demo-7 \
 get canary go-demo-7 \
 --output jsonpath="{.status.phase}"


$ cat k8s/istio/flagger-status.sh
$ chmod +x k8s/istio/flagger-status.sh


#####################
# Successful Canary
#####################


$ echo ${INGRESS_HOST}


# Open a second terminal session


$ export INGRESS_HOST=[...]


$ echo {INGRESS_HOST}


$ cd ~/go-demo-7


$ export ADDR="http://${INGRESS_HOST}/version"

$ ./k8s/istio/flagger-status.sh "$ADDR"


# Go back to the first terminal session


$ kubectl --namespace go-demo-7 apply \
 --filename k8s/istio/flagger/exercise/deployment-0-0-2.yaml


$ kubectl --namespace go-demo-7 \
 describe canary go-demo-7


# Go to the second terminal session


echo $?


# Go back to the first terminal session

# Wait for a while (e.g., 5 min.)


#################
# Failed Canary
#################


# Go to the second terminal session


$ export ADDR="http://$INGRESS_HOST/demo/random-error"


$ ./k8s/istio/flagger-status.sh "$ADDR"


# Go back to the first terminal session


$ kubectl --namespace go-demo-7 apply \
 --filename k8s/istio/flagger/exercise/deployment-0-0-3.yaml


$ kubectl --namespace go-demo-7 \
 describe canary go-demo-7


# Go to the second terminal session


$ echo $?


# Go back to the first terminal session


###############
# Cleaning Up
###############


$ cd ..


$ kubectl delete namespace go-demo-7