Canary Deployments To Kubernetes Using Istio and Friends
Делаю:
21.01.2021
07 Automating Canary Deployments With Flagger
https://gist.github.com/96be243dcf4d3768c8b059c16c34fa79
Возможно нужно, но я точно не знаю:
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.8/samples/addons/prometheus.yaml
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.8/samples/addons/grafana.yaml
######################
# Installing Flagger
######################
$ kubectl apply \
--kustomize github.com/weaveworks/flagger/kustomize/istio
#####################
# Deploying The App
#####################
$ export GH_USER=vfarcic
$ cd ~
$ git clone \
https://github.com/$GH_USER/go-demo-7.git
$ 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/db \
--recursive
$ ls -l k8s/app
$ cat k8s/app/*
$ kubectl --namespace go-demo-7 apply \
--filename k8s/app \
--recursive
$ kubectl --namespace go-demo-7 rollout status deployment go-demo-7
$ chmod +x k8s/istio/get-ingress-host.sh
$ INGRESS_HOST=$(\
./k8s/istio/get-ingress-host.sh \
$PROVIDER)
$ echo ${INGRESS_HOST}
$ curl -v -H "Host: go-demo-7.acme.com" \
"http://${INGRESS_HOST}/version"
curl: (7) Failed to connect to 192.168.49.20 port 80: Connection refused
$ kubectl --namespace go-demo-7 \
get gateways,ingresses
No resources found in go-demo-7 namespace.
##############################
# Deploying Flagger Resource
##############################
$ cat k8s/istio/flagger/exercise/flagger.yaml
$ kubectl --namespace go-demo-7 apply \
--filename k8s/istio/flagger/exercise/flagger.yaml
$ cat k8s/istio/flagger/exercise/gateway.yaml
$ kubectl --namespace go-demo-7 apply \
--filename k8s/istio/flagger/exercise/gateway.yaml
$ kubectl --namespace go-demo-7 \
get deployments
$ kubectl --namespace go-demo-7 \
rollout status \
deployment go-demo-7-primary
$ kubectl --namespace go-demo-7 \
get hpa
# Might be `<unknown>` if metrics server is not installed
$ for i in {1..10}; do
curl -H "Host: go-demo-7.acme.com" \
"http://$INGRESS_HOST/version"
sleep 0.25
done
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
Version: 0.0.1; Release: unknown
$ kubectl --namespace go-demo-7 \
get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
go-demo-7 ClusterIP 10.103.68.154 <none> 80/TCP 7m21s
go-demo-7-canary ClusterIP 10.100.79.47 <none> 80/TCP 8m21s
go-demo-7-db ClusterIP 10.105.27.5 <none> 27017/TCP 50m
go-demo-7-primary ClusterIP 10.103.249.225 <none> 80/TCP 8m21s
$ kubectl --namespace go-demo-7 \
get destinationrules
NAME HOST AGE
go-demo-7-canary go-demo-7-canary 8m4s
go-demo-7-primary go-demo-7-primary 8m4s
$ kubectl --namespace go-demo-7 \
get virtualservices
NAME GATEWAYS HOSTS AGE
go-demo-7 ["go-demo-7"] ["go-demo-7.acme.com","go-demo-7"] 8m39s
$ kubectl --namespace go-demo-7 \
get canaries
NAME STATUS WEIGHT LASTTRANSITIONTIME
go-demo-7 Initialized 0 2021-01-21T17:06:13Z
$ kubectl --namespace go-demo-7 \
describe canary go-demo-7
###########################
# Deploying A New Release
###########################
$ cat k8s/istio/flagger/exercise/deployment-0-0-2.yaml
$ diff k8s/app/deployment.yaml \
k8s/istio/flagger/exercise/deployment-0-0-2.yaml
<br/
$ echo ${INGRESS_HOST}
# Open a second terminal session
$ export INGRESS_HOST=[...]
$ while true; do
curl -H "Host: go-demo-7.acme.com" \
"http://${INGRESS_HOST}/version"
sleep 1
done
# 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 \
get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
go-demo-7 2/2 2 2 159m
go-demo-7-db 1/1 1 1 161m
go-demo-7-primary 2/2 2 2 118m
$ kubectl --namespace go-demo-7 \
get virtualservices
$ kubectl --namespace go-demo-7 \
describe virtualservice go-demo-7
$ kubectl --namespace go-demo-7 \
get pods
NAME READY STATUS RESTARTS AGE
go-demo-7-6d47f98d98-6vsvh 2/2 Running 0 83s
go-demo-7-6d47f98d98-pjbvj 2/2 Running 0 81s
go-demo-7-db-dbd659775-vpqx9 2/2 Running 0 161m
go-demo-7-primary-5b46c7c88b-7pccx 2/2 Running 0 119m
go-demo-7-primary-5b46c7c88b-cprq8 2/2 Running 0 119m
$ kubectl --namespace go-demo-7 \
get canaries
NAME STATUS WEIGHT LASTTRANSITIONTIME
go-demo-7 Progressing 20 2021-01-21T19:04:13Z
$ kubectl --namespace go-demo-7 \
describe canary go-demo-7
$ kubectl --namespace go-demo-7 \
describe virtualservice go-demo-7
$ kubectl --namespace go-demo-7 \
get canaries
# Go to the second terminal session and stop the loop with _ctrl+c_
#######################
# Visualizing Metrics
#######################
# Go to the first terminal session
$ istioctl manifest install \
--set values.grafana.enabled=true
$ kubectl --namespace istio-system \
port-forward $(kubectl \
--namespace istio-system \
get pod \
--selector app=grafana \
--output jsonpath='{.items[0].metadata.name}') \
3000:3000 &
$ cat k8s/grafana/flagger.json
# Copy the JSON
open “http://localhost:3000/dashboard/import”
# Paste the JSON
###############
# Cleaning Up
###############
$ cd ..
$ killall kubectl
$ kubectl delete namespace go-demo-7