Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created December 5, 2021 16:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vfarcic/215c6e3126ae9bc4c6fee363a9682dbf to your computer and use it in GitHub Desktop.
Save vfarcic/215c6e3126ae9bc4c6fee363a9682dbf to your computer and use it in GitHub Desktop.
#########################################################################
# How To Do Canary Deployments In Kubernetes Using Flagger And Linkerd? #
# https://youtu.be/NrytqS43dgw #
#########################################################################
# Referenced videos:
# - What Is Linkerd Kubernetes Service Mesh? Linkerd Tutorial Part 1: https://youtu.be/mDC3KA_6vfg
# - Progressive Delivery Explained - Big Bang (Recreate), Blue-Green, Rolling Updates, Canaries: https://youtu.be/HKkhD6nokC8
# - Service Mesh In Kubernetes Explained: https://youtu.be/cjhb7_uwzDk
# - Argo Rollouts - Canary Deployments Made Easy In Kubernetes: https://youtu.be/84Ky0aPbHvY
# - Kustomize - How to Simplify Kubernetes Configuration Management: https://youtu.be/Twtbg6LFnAg
#########
# Setup #
#########
# Create a Kubernetes cluster with NGINX Ingress
gh repo fork vfarcic/linkerd-demo \
--clone
cd linkerd-demo
# Replace `[...]` with the Ingress Service IP
export INGRESS_HOST=[...]
cat kustomize/overlays/flagger/ingress.yaml \
| sed -e "s@host: .*@host: silly-demo.$INGRESS_HOST.nip.io@g" \
| tee kustomize/overlays/flagger/ingress.yaml
kubectl create namespace production
#############################
# Install And Setup Linkerd #
#############################
# Please watch https://youtu.be/mDC3KA_6vfg if you're not familiar with Linkerd
linkerd install \
| kubectl apply --filename -
linkerd viz install \
| kubectl apply --filename -
linkerd check
###################
# Install Flagger #
###################
kubectl apply \
--kustomize github.com/fluxcd/flagger/kustomize/linkerd
##########################
# Define Canary Resource #
##########################
cd kustomize/overlays/flagger
cat deployment.yaml
cat hpa.yaml
cat ingress.yaml
cat canary.yaml
# Watch https://youtu.be/Twtbg6LFnAg if you are not familiar with Kustomize
kubectl apply --kustomize .
kubectl --namespace production get pods
kubectl --namespace production \
get canaries
kubectl --namespace production \
get services
kubectl --namespace production \
get canaries
kubectl --namespace production \
describe canary silly-demo
###########################
# Deploy A Canary Release #
###########################
kustomize edit set image \
vfarcic/silly-demo=vfarcic/silly-demo:1.0.3
kubectl apply --kustomize .
while true; do
kubectl --namespace production get canaries
curl http://silly-demo.$INGRESS_HOST.nip.io
echo ""
sleep 0.5
done
kubectl --namespace production \
describe canary silly-demo
############################
# Canary Releases Rollback #
############################
kustomize edit set image \
vfarcic/silly-demo=vfarcic/silly-demo:1.0.4
kubectl apply --kustomize .
while true; do
kubectl --namespace production get canaries
curl http://silly-demo.$INGRESS_HOST.nip.io
curl http://silly-demo.$INGRESS_HOST.nip.io?fail
echo ""
sleep 0.5
done
kubectl --namespace production \
describe canary silly-demo
######################################################
# Flagger Webhooks, Gating, Alerting, And Monitoring #
######################################################
# Open https://docs.flagger.app/usage/webhooks
# Open https://docs.flagger.app/usage/alerting
# Open https://docs.flagger.app/usage/monitoring
###########
# Destroy #
###########
kustomize edit set image \
vfarcic/silly-demo=vfarcic/silly-demo:1.0.2
# Destroy the cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment