An example controller in go which prints the number of replicas when a deployment is scaled. Local dev environment with kind and ko.
Make sure Docker is up and running. Then start a local Kubernetes cluster with kind:
./kind-with-registry.sh
This will start a docker registry and a Kubernetes cluster and wires them up. Easy peasy right?
Our source is written in go and thus we can use ko to build and deploy:
export KO_DOCKER_REPO=localhost:5000/controller-example
ko apply -f deployment.yaml
scale a deployment
kubectl logs -f controller-example-7f7fffd5c5-pdnml
kubectl scale deployment --replicas 2 controller-example
kubectl scale deployment --replicas 4 controller-example
watch the controller logs
2020/02/15 14:16:12 Deployment: controller-example, Replicas: 2
2020/02/15 14:16:19 Deployment: controller-example, Replicas: 4