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!
Install
To install kube-green just clone this repository, check out to the latest stable tag, 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
Usage
The use of this operator is very simple. Once installed on the cluster, configure the desired CRD to make it works.
SleepInfo
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 namespace will go to sleep. Valid values are, for example, 19:00or
*:*
for every minute and every hour. Resources sleep will be deployments (setting replicas value to 0) and, ifsuspendCronjobs
option is set to true, cron jobs will be suspended. - wakeUpAt (optional): time in hours and minutes (HH:mm) when namespace should be restored to the initial state (before sleep). 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
. - suspendCronJobs (optional): if set to true, cronjobs will be suspended.
- excludeRef (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", "batch/v1beta1" and "batch/v1"
- kind: the kind of resource. Now it is supported "Deployment" and "CronJob"
- 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"
suspendCronJobs: true
excludeRef:
- apiVersion: "apps/v1"
kind: Deployment
name: api-gateway
Lifecycle
TODO
Uninstall
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.
Versioning
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
./hack/update-version.sh $VERSION
- run
make
- add, commit and push
- git tag $VERSION
git push --tags origin $VERSION
API Reference documentation
API reference is automatically generated with this tool. To generate it automatically, are added in api versioned folder a file doc.go
with the content of file groupversion_info.go
and a comment with +genclient
in the sleepinfo_types.go
file for the resource type.
Acknowledgement
Special thanks to JGiola for the tech review.