The hpa-operator
will will create automatically Horizontal Pod Scaling base on Annotations
in spec.metadata
in Deployment
. The annotations are
hpa.apixio.com/min -> minimum number of replicas
hpa.apixio.com/max -> maximum number of replicas
hpa.apixio.com/template -> name of hpa template you want to use
hpa.apixio.com/behavior -> scaling behavior name, use default if not defined
Simply checking Deployment by using Deployment Informer and Lister. If deployment has the valid annotations, it will create or update HPA with the same name as Deployment Name.
When Deployment is deleted, it also deleted either.
HPA Templates were stored in ConfigMap that was mounted to hpa-operator
as volume at /template
HPA Template configmap
kubectl create -f https://raw.githubusercontent.com/zduymz/hpa-operator/master/examples/hpatemplate.yaml
HPA Operator with RBAC
kubectl create -f https://raw.githubusercontent.com/zduymz/hpa-operator/master/examples/hpa-rbac.yaml
HPA Operator without RBAC
kubectl create -f https://raw.githubusercontent.com/zduymz/hpa-operator/master/examples/hpa.yaml
Create nginx deployment
kubectl create -f https://raw.githubusercontent.com/zduymz/hpa-operator/master/examples/nginx.yaml
Send requests
kubectl run -it load-generator --image=busybox /bin/sh
while true; do wget -q -O- http://nginx-svc.default.svc.cluster.local; done
You need to install golang >= 1.20.
# Install requirements package
go mod tidy
# build on macos
make macos
# build on linux
make linux
We have some environment variables
- K8S_MASTER: k8s master url (automatically look up if empty)
- K8S_CONFIG: kubeconfig file (automatically look up if empty)
- HPA_TEMPLATES: directory contain hpa templates (default is /template/)