Dynamically scale kubernetes resources using length of an AMQP queue (number of messages available for retrieval from the queue) to determine the load on an application/Kubernetes pod.
NOTICE
If your application load is not queue-bound but rather CPU-sensitive, make sure to use built-in Kubernetes Horizontal Pod Autoscaling instead of this project.
Alpha
The best way to use the service is by importing automated build docker container. Please follow the instructions on the automated build page.
go get github.com/mbogus/kube-amqp-autoscale
Clone from github
- Create directory for APT projects
mkdir -p $GOPATH/src/github.com/mbogus
as typical in writing go programs - Clone this project
git clone https://github.com/mbogus/kube-amqp-autoscale.git
If you have a unix-y shell on Windows (MSYS2, CYGWIN or other), see Build project below.
The project depends on several external Go projects that can be automatically
downloaded using make depend
target.
Run make depend && make [build]
GOMAXPROCS
limits the number of operating system threads that can execute user-level Go code simultaneously
amqp-uri
required, RabbitMQ broker URI, e.g.amqp://guest:[email protected]:5672//
amqp-queue
required, RabbitMQ queue name to measure load on an application. Use comma separator to specify multiple queues.api-url
required, Kubernetes API URL, e.g.http://127.0.0.1:8080
api-user
optional, username for basic authentication on Kubernetes APIapi-passwd
optional, password for basic authentication on Kubernetes APIapi-token
optional, path to a bearer token file for OAuth authentication, on a Kubernetes pod usually/var/run/secrets/kubernetes.io/serviceaccount/token
api-cafile
optional, path to CA certificate file for HTTPS connections to Kubernetes API from within a cluster, typically/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
api-insecure
optional, set totrue
for connecting to Kubernetes API without verifying TLS certificate; unsafe, use for development only (defaultfalse
)min
lower limit for the number of replicas for a Kubernetes pod that can be set by the autoscaler (default1
)max
required, upper limit for the number of replicate for a Kubernetes pod that can be set by the autoscaler (must be greater thanmin
)name
required, name of the Kubernetes resource to autoscalekind
type of the Kubernetes resource to autoscale, one ofDeployment
,ReplicationController
,ReplicaSet
(defaultDeployment
)ns
Kubernetes namespace (defaultdefault
)interval
time interval between Kubernetes resource scale runs in secs (default30
)threshold
required, number of messages on a queue representing maximum load on the autoscaled Kubernetes resourceincrease-limit
limit number of Kubernetes pods to be provisioned in a single scale iteration to max of the value, set to a number greater than 0, defaultunbounded
decrease-limit
limit number of Kubernetes pods to be terminated in a single scale iteration to max of the value, set to a number greater than 0, defaultunbounded
stats-interval
time interval between metrics gathering runs in seconds (default5
)eval-intervals
number of autoscale intervals used to calculate average queue length (default2
)stats-coverage
required percentage of statistics to calculate average queue length (default0.75
)db
sqlite3 database filename for storing queue length statistics (defaultfile::memory:?cache=shared
)db-dir
directory for sqlite3 statistics database fileversion
show versionmetrics-listen-address
the address to listen on for exporting Prometheus metrics (default:9505
)
To run intergation tests, make sure to configure access to running RabbitMQ instance,
export environment variable AMQP_URI=amqp://username:passwd@rabbitmq-host:5672//
and run go test -tags=integration ./...