kbg (Kube Blue-Green) - Pronounced "Cabbage"
# assuming local kube is running and kubectx is pointing to it
make install
docker-compose up kbg
TODO
~/ kubectl create ns test
namespace/test created
~/ kubectl apply -f config/samples/cluster_v1alpha1_bluegreendeployment.yaml -n test
bluegreendeployment.cluster.kbg/myserver created
~/ kubectl get kbg -n test
NAME COLOR STATUS ACTIVE BACKUP AGE
myserver blue Unknown 0 0 8s
~/ kubectl get all -n test
NAME READY STATUS RESTARTS AGE
pod/myserver-blue-6w6st 1/1 Running 0 34s
pod/myserver-blue-q4w2v 1/1 Running 0 34s
pod/myserver-green-qjfcc 1/1 Running 0 34s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/myserver NodePort 10.106.146.24 <none> 80:30697/TCP 34s
service/myserver-backup NodePort 10.107.59.27 <none> 80:31623/TCP 34s
NAME DESIRED CURRENT READY AGE
replicaset.apps/myserver-blue 2 2 2 34s
replicaset.apps/myserver-green 1 1 1 34s
~/ kubectl get kbg -n test
NAME COLOR STATUS ACTIVE BACKUP AGE
myserver blue Nominal 2 1 38s
Update the Nginx version in the sample
containers:
- name: nginx
image: nginx:1.19.0
~/ kubectl apply -f config/samples/cluster_v1alpha1_bluegreendeployment.yaml -n test
bluegreendeployment.cluster.kbg/myserver configured
~/ kubectl get kbg -n test
NAME COLOR STATUS ACTIVE BACKUP AGE
myserver blue Deploying 2 1 13m
~/ kubectl get all -n test
NAME READY STATUS RESTARTS AGE
pod/myserver-blue-6w6st 1/1 Running 0 13m
pod/myserver-green-4nkc4 1/1 Running 0 2m21s
pod/myserver-green-x8dl7 1/1 Running 0 2m37s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/myserver NodePort 10.106.146.24 <none> 80:30697/TCP 13m
service/myserver-backup NodePort 10.107.59.27 <none> 80:31623/TCP 13m
NAME DESIRED CURRENT READY AGE
replicaset.apps/myserver-blue 1 1 1 13m
replicaset.apps/myserver-green 2 2 2 2m37s
~/ kubectl get kbg -n test
NAME COLOR STATUS ACTIVE BACKUP AGE
myserver green Nominal 2 1 14m
~/ curl -sD - 127.0.0.1:30697 -o /dev/null | grep Server
Server: nginx/1.19.0
For instant rollback set these values
spec:
swapStrategy: SwapThenScale
overrideColor: blue
~/ kubectl apply -f config/samples/cluster_v1alpha1_bluegreendeployment.yaml -n test
bluegreendeployment.cluster.kbg/myserver configured
~/ kubectl get kbg -n test
NAME COLOR STATUS ACTIVE BACKUP AGE
myserver blue Overridden 2 1 17m
Clean up
~/ kubectl delete kbg --all -n test
bluegreendeployment.cluster.kbg "myserver" deleted
~/ kubectl get all -n test
No resources found in test namespace.
- HPA support (untested)
- Default/Validating webhooks (untested)
- Sync mode (hook into admission?) to fail the update if tests fail
- RBAC, tested in "privileged" mode
- Fix all TODOs
- Unit/Integration testing, then refactoring
- A big part of this is based on Google's sample Blue/Green Controller
- Kubebuilder book
- Kubebuilder book v1