This Go application checks all Kubernetes Deployments in all namespaces for scaling annotations and scales the deployment according to the annotations.
There are two branches in this repo:
- master branch uses your own kubeconfig to access the cluster. This can be run in Docker on your local machine.
- master-incluster branch is meant to be deployed in your Kubernetes cluster to be run as a Job/CronJob. This makes use of service account tokens to give your pod access to the cluster.
In the Kubernetes Deployment manifest of the Deployment that you want to enable scaling, add the annotations scaleUp and scaleDown.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: app
annotations: #used to attach data
scaleDown: '0'
scaleUp: '1'
spec:
replicas: 1
revisionHistoryLimit: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 2
template:
metadata:
labels:
app: app
spec:
...
To run this application in a Docker container:
docker build -t halosan/k8-pod-scheduler:latest .
docker run -v $HOME/.kube:/root/.kube -e "SCALE=scaleUp" halosan/k8-pod-scheduler:latest
The environment variable SCALE
can either be scaleUp
or scaleDown
.
docker build -t halosan/k8-pod-scheduler:dev -f Dockerfile-dev .
docker run --rm -it -v $(pwd):/go/src/app \
-v $HOME/.kube:/home/1000/.kube \
halosan/k8-pod-scheduler:dev bash
From the root directory of this project:
glide install
This will create a vendor
directory which has the correct version of Kubernetes client-go
.