Kubernetes time based scale operator
- Create project
kubebuilder init --domain scaler.cloudsteak.com --owner "CloudSteak" --repo github.com/cloudsteak/scale-operator.git
- Create API
kubebuilder create api --kind Scaler --version v1alpha1 --group api
- Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
make generate
- Create manifests (CRD, RBAC and Controller)
make manifests
-
Develop your code
-
Install CRDs
make install
- Create deployment
kubectl create deploy nginx --image=nginx
- Configure scaler
nano config/samples/api_v1alpha1_scaler.yaml
spec:
start: 5 # UTC time
end: 11 # UTC time
replicas: 2
deployments:
- name: nginx
namespace: nginx
- Create scaler
kubectl apply -f config/samples/api_v1alpha1_scaler.yaml
- Run the controller
make run
- Check output
** Scale up
2024-07-08T07:41:02+02:00 INFO --- Scaling up deployments {"controller": "scaler", "controllerGroup": "api.scaler.cloudsteak.com", "controllerKind": "Scaler", "Scaler": {"name":"scaler-sample","namespace":"default"}, "namespace": "default", "name": "scaler-sample", "reconcileID": "d113f2c7-e8d2-4d9a-a3f9-3b51134e7dd1"}
2024-07-08T07:41:02+02:00 INFO Scaling Deployment {"name": "nginx", "namespace": "default", "replicas_to": 2, "replicas_from": 1}
** Scale down
2024-07-08T16:40:02+02:00 INFO --- Scaling down deployments {"controller": "scaler", "controllerGroup": "api.scaler.cloudsteak.com", "controllerKind": "Scaler", "Scaler": {"name":"scaler-sample","namespace":"default"}, "namespace": "default", "name": "scaler-sample", "reconcileID": "c0668843-f7ee-4c7a-99d6-7cf6e5fbeb0f"}
2024-07-08T16:40:02+02:00 INFO Scaling Deployment {"name": "nginx", "namespace": "default", "replicas_to": 1, "replicas_from": 2}