At Bonnier News we autoscale our Kubernetes cluster to prepare for the unknown, support our devs and increase efficiency of our cluster resources. By using custom controllers we can also autoscale using spot nodes for specific applications.
the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state. Examples of controllers that ship with Kubernetes today are the replication controller, endpoints controller, namespace controller, and serviceaccounts controller.” tldr;
deployment controller watches deployment api objects. • New -> create a replicaset object with a owner reference ((write back status) • The replicaset controller will create pods and set their owner references. • The kubelet will create containers. • Controllers doesn’t always need to create objects within kubernetes,. • Do something based on the changed state • … • But they always watch api objects for changes
• Listen to events for your api object • Reconcile it! apiVersion: crew.testproject.org/v1 kind: FirstMate metadata: labels: controller-tools.k8s.io: "1.0" name: firstmate-sample spec: # Add fields here foo: bar
bonniernews.io --license apache2 --owner ”Bonnier News”’ $ kubebuilder create api --group core --version v1 --kind Events # Implement the controller’s Reconcile function, code, code, code! $ make deploy • Kubebuilder • Kubebuilder is an SDK for rapidly building and publishing Kubernetes APIs in Go
Scale up if there are insufficient resources • Scale down if there are underutilized nodes • Simulates the scheduler • Predicates (taints. tolerations, affinity) • Resources • VolumeZonePredicate predicate HPA & VPA friendly!
"k8s.io/cluster-autoscaler/enabled" = "true" "kubernetes.io/cluster/${var.cluster_name}" = "true" • One ASG per AZ and instance type • K8S metadata as AWS tags on ASG’s (The cluster-autoscaler reads them) • Taints and labels