This repository contains a proof-of-concept of blue-green deployment af an
application to Minikube and Docker-compose.
sk
script in the root stands for "Swiss Knife" is inspired by
make(file) and contains all commands necessary to manage code and deployment.
- Linux (Arch)
- VirtualBox 6.1.28 r147628
- Minikube v1.24.0
- Kubernetes / kubectl v1.22.4
- Docker 20.10.10
- Python3 3.9.7
- Jq 1.6
-
Initialize environment:
./sk init-venv
-
Run locally:
./sk run-dev # or ./sk run-gunicorn
-
Build docker image:
./sk build
-
Run in docker:
./sk run-docker
-
Run tests (infrastructure ones, in Docker):
./sk test-docker
-
Start minikube. For instance:
minikube start --kubernetes-version v1.22.4 --vm-driver=virtualbox #or ./sk mk-init
-
Switch to minikube's docker:
minikube docker-env | source
-
Build few docker images' versions:
VERSION=0.0.1 ./sk build # change the code VERSION=0.0.2 ./sk build
-
Deploy
VERSION=0.0.1 ./sk mk-deploy-all VERSION=0.0.2 ROLE=green ./sk mk-deploy-deployment ./sk mk-get-public-url
-
Start continuous role switching:
./sk mk-role-blink
-
Run benchmark testing (in separate console):
./sk mk-test-ab
Possible and tested, but is out of scope.
This solution is over-simplified and could work only as PoC. Real application production usage would require an infrastructure management code (Terraform, etc.), package manager for Kubernetes (e.g. Helm), code tests, fully-featured ingress-controller and many other important features.
Nevertheless, it was possible to achieve seamless switching between blue and green environments both with Minikube and Docker-compose setups (i.e. get zero failed requests in Apache Benchmark report):
...
Server Software: gunicorn
Server Hostname: 192.168.59.108
Server Port: 30998
Document Path: /api/
Document Length: 20 bytes
Concurrency Level: 1
Time taken for tests: 18.867 seconds
Complete requests: 9999
Failed requests: 0
Total transferred: 1649835 bytes
HTML transferred: 199980 bytes
Requests per second: 529.98 [#/sec] (mean)
Time per request: 1.887 [ms] (mean)
Time per request: 1.887 [ms] (mean, across all concurrent requests)
Transfer rate: 85.40 [Kbytes/sec] received
...