The Deployment Scaler Operator is a Kubernetes controller designed to dynamically scale deployments based on predefined time periods.
This operator utilizes a custom resource named DepScaler
to specify the scaling schedule for one or more deployments. It continuously monitors the current time and scales the specified deployments to the desired number of replicas if the current time falls within the specified time period (in hours).
- Go version 1.20 (only required if running locally)
- A Running Kubernetes Cluster
- Build and push your image to the location specified by
IMG
:
make docker-build docker-push IMG=<some-registry>/depscaler:tag
- Deploy the controller to the cluster with the image specified by
IMG
:
make deploy IMG=<some-registry>/depscaler:tag
- Create a sample deployment
kubectl create deployment nginx --image=nginx
- Install Instances of Custom Resources:
kubectl apply -f config/samples/
To delete the CRDs from the cluster:
make uninstall
UnDeploy the controller from the cluster:
make undeploy
-
Clone the repository:
git clone https://github.com/yrs147/deployment-scaler-operator.git cd deployment-scaler-operator
-
Run the
make install
commandmake install
-
Create a sample deployment
kubectl create deployment nginx --image=nginx
-
Now in another terminal window run the operator using
make run
-
Now create your custom
Depscaler
using the template belowapiVersion: depscale.yrs.scaler/v1 kind: DepScaler metadata: labels: name: depscaler-sample spec: begin: 10 # start time hour(in 24hr format) end: 17 # end time hour(in 24hr format) replicas: 6 deployments: - name: nginx namespace: default
Use the make test
command to run tests
make test
Operator in action
To adjust the deployment scale for a particular time period, modify the begin and end hours in the spec section of the DepScaler manifest. Specify the desired number of replicas for that time period.