Skip to content

Latest commit

 

History

History

api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

API demo

Simple demo of how to deploy a basic API on kubernetes. The demo has 3 stages from simpler to more complex deployment strategies.

Setup

Basic setup of minikube and docker

  1. Start vanilla minikube with bash scripts/minkube_setup.sh
  2. Point docker-cli to minikube's docker-server eval $(minikube docker-env)
  3. Build api with docker build -t api:v0.1.0 . inside api/ folder

Deploy basic API

Deploy app using vanilla kubernetes

  1. Create services with kubectl apply -f deploy/api/networking.yml
  2. Create deployment with kubectl apply -f deploy/api/deployment.yml
  3. Test that the api works with minikube service api-svc-stable

Istio

Introduce Istio for smarter rounting and Ingress.

  1. Setup istio
  2. install istio in the cluster with istioctl install
  3. Create istio's components with kubectl apply -f deploy/api/istio.yml
  4. Open another terminal and run minikube tunnel
  5. Get ingress IP with INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  6. Run the consumer with python scripts/consumer.py -e http://$INGRESS_HOST

Argo rollouts

Introduce Argo rollouts for Canary deployments

  1. Cleanup with kubectl delete deployment api
  2. Install argo rollouts controller and it's kubectl addon
  3. Install prometheus for istio
  4. Create rollout kubectl apply -f deploy/api/rollout.yml first time is going to ignore canary and deploy inmediatelly
  5. Modify api/app.py
  6. Build new version with docker build -t api:v0.1.1 inside api/ folder
  7. Deploy new version with kubectl argo rollouts set image api-rollout api=api:<NEW_VERSION>
  8. Watch progress with kubectl argo rollouts get rollout api-rollout --watch

You can run 2 consumers while rolling the deployment, and set the user to juancarlo on one of them. There is a special rule on the virtual service that always routes this user to the stable version.

For testing a failed canary add a sleep of 1 second to the API endpoint or an respond with a non 2XX code, build and deploy as described above.

Troubleshoot:

  • Wierd 503 certificate errors: kubectl delete -n istio-system pod istio-ingressgateway-<Tab>