How many of your dev/preview pods stay on during weekends? Or at night? It's a waste of resources! And money! But fear not, kube-green is here to the rescue.
kube-green is a simple k8s addon that automatically shuts down (some of) your resources when you don't need them.
Keep reading to find out how to use it, and if you have ideas on how to improve kube-green, open an issue, we'd love to hear them!
To install kube-green just clone this repository and run:
make deploy
This will create a new namespace, kube-green, which contains the pod of the operator.
For further information about the installation, see here
The use of this operator is very simple. Once installed on the cluster, configure the desired CRD to make it works.
In the namespace where you want to enable kube-green, apply the SleepInfo CRD. An example of CRD is accessible at this link
The SleepInfo spec contains:
- weekdays: day of the week.
*
is every day,1
is monday,1-5
is from monday to friday - sleepAt: time in hours and minutes (HH:mm)when deployments replicas should be set to 0. Valid values are, for example, 19:00or
*:*
for every minute and every hour. - wakeUpAt (optional): time in hours and minutes (HH:mm) when deployments replicas should be restored. Valid values are, for example, 19:00or
*:*
for every minute and every hour. If wake up value is not set, pod in namespace will not be restored. So, you will need to deploy the initial namespace configuration to restore it. - timeZone (optional): time zone in IANA specification. For example for italian hour, set
Europe/Rome
- excluldeRef (optional): an array of object containing the resource to exclude from sleep. It contains:
- apiVersion: version of the resource. Now it is supported "apps/v1"
- kind: the kind of resource. Now it is supported "Deployment"
- name: the name of the resource.
An example of a complete SleepInfo resource:
apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
name: working-hours
spec:
weekdays: "1-5"
sleepAt: "20:00"
wakeUpAt: "08:00"
timeZone: "Europe/Rome"
excludeRef:
- apiVersion: "apps/v1"
kind: Deployment
name: api-gateway
TODO
To uninstall the operator from the cluster, run:
make undeploy
⚠️ If you run undeploy command, the namespace of kube-green (by defaultkube-green
), will be deleted.
To upgrade the version:
export VERSION=v{{NEW_VERSION_TO_TAG}}
where{{NEW_VERSION_TO_TAG}}
should be replaced with the next version to upgrade. N.B.: version should includev
as first char.- run
./scripts/update-version.sh $VERSION
- run
make
- add, commit and push
- git tag $VERSION
git push --tags origin $VERSION
Special thanks to JGiola for the tech review.