Weighted-Routing(Canary) with Kubernetes and Istio

Final Architecture Preview

Weighted-Routing (Canary) for two deployments (versions)


Environment Setup


# Update your system
sudo apt-get update -y
sudo apt-get upgrade -y
# Install required packages
sudo apt-get install curl wget apt-transport-https -y
# Download latest minikube
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
# Add minikube to $PATH and give executable permission
sudo cp minikube-linux-amd64 /usr/local/bin/minikube
sudo chmod +x /usr/local/bin/minikube
# Verify installation
minikube version


sudo apt-get update && sudo apt-get install -y apt-transport-httpscurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.listsudo apt-get update
sudo apt-get install -y kubectl
kubectl version -o json


curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

Create Minikube Cluster

sudo minikube start --memory=8192 --cpus=4 --kubernetes --vm-driver none# To run minikube as your user from now on
sudo mv /home/$USER/.kube /home/$USER/.minikube $HOME
sudo chown -R $USER /home/$USER/.kube /home/$USER/.minikube
minikube status

Install Istio

# Download Istio version 1.4.0
curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.4.0 sh -
cd istio-1.4.0# Deploy Istio Custom Resource Definitions
for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done
# Deploy Istio Components
kubectl apply -f install/kubernetes/istio-demo.yaml
# Wait pods to be Running
watch -n1 kubectl get pods -n istio-system
# Enable sidecar injection
kubectl label namespace default istio-injection=enabled
Verify that the istio-system is created by watch command

Deploy Two Version for Our Service

# Create two directories for creating Docker images inside them
mkdir production feature
# Download Dockerfile, two package.json and two server.js
curl https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/Dockerfile | tee production/Dockerfile feature/Dockerfile
curl https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/package.json | tee production/package.json feature/package.jsoncurl https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/server_production.js --output production/server.jscurl https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/server_feature.js --output feature/server.js# Build Docker images
docker build -f production/Dockerfile -t hmerac/nodejs:production ./production
docker build -f feature/Dockerfile -t hmerac/nodejs:feature ./feature# Verify the Docker images
docker images
# Deploy our NodeJS service
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/service.yml
# Make the production deployment for our NodeJS service
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/deployment_production.yml
All of the traffic is being routed to Production
# Create Ingress Gateway
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/ingress_gateway.yml
# Create Virtual Service
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/virtual_service.yml
# Create Destination Rule
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/destination_rule.yml
echo “$(kubectl get service -n istio-system | grep ingress | awk ‘{print $3}’) nodejs.com” | sudo tee -a /etc/hosts
Making requests to Ingress Gateway
# Make the feature deployment for our NodeJS service
kubectl apply -f https://raw.githubusercontent.com/Hmerac/AWSCSAProNotes/master/final_solution/istio_components/deployment_feature.yml
One out of nine requests hit Feature version

What is hell for Doomguy, is manual work for me (I also hit animal skin stretched over hollow wooden objects to create music 🥁) mertacikportali.com