Kubernetes Redeploy Operator to redeploy pods in a deployment in the form of rolling updates.
This project is built with help of Operator-SDK.
Redeploy Operator basically adds a label to PodSpec field in deployments.
This triggers a deployment rollout. Type of rollout depends on MaxSurge
and MaxUnavailable
fields in your deployments.
The label you will see added is the datetime (UTC) field.
Eg: redeployed: 2018-08-07-05_28_41
- It only works for deployments. ( Statefulsets, replicasets and daemonsets are not covered. )
- Install CRD, rbac and operator.
kubectl apply -f deploy/crd.yaml
kubectl apply -f deploy/rbac.yaml
kubectl apply -f deploy/operator.yaml
- Install a demo app:
kubectl create namespace nginx
kubectl run nginx --namespace nginx --image nginx:alpine --replicas=2
- Trigger a redeploy:
kubectl apply -f deploy/cr.yaml
- See it work:
kubectl -n nginx get pods -w
kubectl -n redeploy-operator logs -l name=redeploy-operator
-
Check status
- Check the custom resource.
kubectl -n redeploy-operator get redeploies -o yaml
You should see RedeployNeeded set to
false
and status fields appended.spec: DeploymentName: nginx DeploymentNamespace: nginx RedeployNeeded: false status: Date: 2018-08-07-05_28_41 Status: REDEPLOYED
- Check the deployment
kubectl -n nginx get deployment nginx -o yaml | grep redeployed
redeployed: 2018-08-07-05_28_41
- Install Operator-SDK
operator-sdk generate k8s
operator-sdk build <IMAGE-NAME>
docker push <IMAGE-NAME>
Note: operator.yaml is custom built. It is overwritten upon building the project. Please make necessary changes to make it work.