Skip to content

Commit

Permalink
refactor bluegreen example to work using Metac (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: AmitKumarDas <[email protected]>
  • Loading branch information
Amit Kumar Das authored Oct 7, 2019
1 parent c8987c0 commit b8565d1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
32 changes: 22 additions & 10 deletions examples/bluegreen/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
## BlueGreenDeployment

This is an example CompositeController that implements a custom rollout strategy
based on a technique called Blue-Green Deployment.
This is an example CompositeController that implements a custom rollout strategy based on a technique called Blue-Green Deployment.

The controller ramps up a completely separate ReplicaSet in the background for any change to the
Pod template. It then waits for the new ReplicaSet to be fully Ready and Available
(all Pods satisfy minReadySeconds), and then switches a Service to point to the new ReplicaSet.
Finally, it scales down the old ReplicaSet.
The controller ramps up a completely separate ReplicaSet in the background for any change to the Pod template. It then waits for the new ReplicaSet to be fully Ready and Available (all Pods satisfy minReadySeconds), and then switches a Service to point to the new ReplicaSet. Finally, it scales down the old ReplicaSet.

### Prerequisites

* Install [Metacontroller](https://github.com/GoogleCloudPlatform/metacontroller)
* Install Metac from the manifests folder

### Deploy the controller
```sh
# verify presence of metac CRDs
kubectl get crd

# verify presence of metac controller
kubectl get sts -n metac
```

### Deploy the BlueGreen controller

```sh
kubectl create configmap bluegreen-controller -n metacontroller --from-file=sync.js
kubectl apply -f bluegreen-controller.yaml
kubectl create configmap bluegreen-controller -n metac --from-file=sync.js

kubectl apply -f operator.yaml

# verify presence of BlueGreen CRD
kubectl get crd

# verify presence of BlueGreen controller deployment & service
kubectl get deploy -n metac
kubectl get svc -n metac
```

### Create a BlueGreenDeployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
subresources:
status: {}
---
apiVersion: metacontroller.k8s.io/v1alpha1
apiVersion: metac.openebs.io/v1alpha1
kind: CompositeController
metadata:
name: bluegreen-controller
Expand All @@ -35,13 +35,13 @@ spec:
hooks:
sync:
webhook:
url: http://bluegreen-controller.metacontroller/sync
url: http://bluegreen-controller.metac/sync
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: bluegreen-controller
namespace: metacontroller
namespace: metac
spec:
replicas: 1
selector:
Expand All @@ -68,7 +68,7 @@ apiVersion: v1
kind: Service
metadata:
name: bluegreen-controller
namespace: metacontroller
namespace: metac
spec:
selector:
app: bluegreen-controller
Expand Down
43 changes: 28 additions & 15 deletions examples/bluegreen/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,65 @@

cleanup() {
set +e
echo "Clean up..."
echo ""

echo "--------------------------"
echo "++ Clean up started"
echo "--------------------------"

kubectl delete -f my-bluegreen.yaml
kubectl delete rs,svc -l app=nginx,component=frontend
kubectl delete -f bluegreen-controller.yaml
kubectl delete configmap bluegreen-controller -n metacontroller
kubectl delete -f operator.yaml
kubectl delete configmap bluegreen-controller -n metac

echo "--------------------------"
echo "++ Clean up completed"
echo "--------------------------"
}

# Comment below if you want to check manually
# the state of the cluster and intended resources
trap cleanup EXIT

set -ex
# Uncomment below if debug / verbose execution is needed
#set -ex

bgd="bluegreendeployments"
bgd="bluegreendeployments.ctl.enisoc.com"

echo "Install controller..."
kubectl create configmap bluegreen-controller -n metacontroller --from-file=sync.js
kubectl apply -f bluegreen-controller.yaml
echo -e "\n Install BlueGreen controller..."
kubectl create configmap bluegreen-controller -n metac --from-file=sync.js
kubectl apply -f operator.yaml

echo "Wait until CRD is available..."
echo -e "\n Wait until BlueGreen CRD is available..."
until kubectl get $bgd; do sleep 1; done

echo "Create an object..."
echo -e "\n Create a BlueGreen object..."
kubectl apply -f my-bluegreen.yaml

# TODO(juntee): change observedGeneration steps to compare against generation number when k8s 1.10 and earlier retire.

echo "Wait for nginx-blue RS to be active..."
echo -e "\n Wait for nginx-blue RS to be active..."
until [[ "$(kubectl get rs nginx-blue -o 'jsonpath={.status.readyReplicas}')" -eq 3 ]]; do sleep 1; done
until [[ "$(kubectl get rs nginx-green -o 'jsonpath={.status.replicas}')" -eq 0 ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.activeColor}')" -eq "blue" ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.active.availableReplicas}')" -eq 3 ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.observedGeneration}')" -eq "$(kubectl get $bgd nginx -o 'jsonpath={.metadata.generation}')" ]]; do sleep 1; done


echo "Trigger a rollout..."
echo -e "\n Trigger a rollout..."
kubectl patch $bgd nginx --type=merge -p '{"spec":{"template":{"metadata":{"labels":{"new":"label"}}}}}'

echo "Wait for nginx-green RS to be active..."
echo -e "\n Wait for nginx-green RS to be active..."
until [[ "$(kubectl get rs nginx-green -o 'jsonpath={.status.readyReplicas}')" -eq 3 ]]; do sleep 1; done
until [[ "$(kubectl get rs nginx-blue -o 'jsonpath={.status.replicas}')" -eq 0 ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.activeColor}')" -eq "green" ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.active.availableReplicas}')" -eq 3 ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.observedGeneration}')" -eq "$(kubectl get $bgd nginx -o 'jsonpath={.metadata.generation}')" ]]; do sleep 1; done

echo "Trigger another rollout..."
echo -e "\n Trigger another rollout..."
kubectl patch $bgd nginx --type=merge -p '{"spec":{"template":{"metadata":{"labels":{"new2":"label2"}}}}}'

echo "Wait for nginx-blue RS to be active..."
echo -e "\n Wait for nginx-blue RS to be active..."
until [[ "$(kubectl get rs nginx-blue -o 'jsonpath={.status.readyReplicas}')" -eq 3 ]]; do sleep 1; done
until [[ "$(kubectl get rs nginx-green -o 'jsonpath={.status.replicas}')" -eq 0 ]]; do sleep 1; done
until [[ "$(kubectl get $bgd nginx -o 'jsonpath={.status.activeColor}')" -eq "blue" ]]; do sleep 1; done
Expand Down
2 changes: 1 addition & 1 deletion examples/status/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cleanup() {
set +e
echo ""
echo ""

echo "--------------------------"
echo "++ Clean up started"
Expand Down

0 comments on commit b8565d1

Please sign in to comment.