gke-pvm-killer

by rimusz

Helm chartv0.1.3App 1.0.49MIT

A Helm chart for gke-pvm-killer

About this chart

GKE preemptible VMs killer

This small Kubernetes application loop through a given GKE preemptibles node pool and kill a node before the regular 24h life time of a preemptible VM.

Why?

When creating a cluster, all the node are created at the same time and should be deleted after 24h of activity. To prevent large disruption, the estafette-gke-preemptible-killer can be used to kill instances during a random period of time between 12 and 24h. It makes use of the node annotation to store the time to kill value.

You can read more about the use case on Travix Engineering blog post.

How does that work

At a given interval, the application get the list of preemptible (PVMs) nodes and check either the node should be deleted or not. If the annotation doesn't exist, a time to kill value is added to the node annotation with a random range between 12h and 24h based on the node creation time stamp. When the time to kill time is passed, the Kubernetes node is marked as unschedulable, drained and the instance deleted on Google Cloud.

Prerequisites

  • Kubernetes cluster on Google Container Engine (GKE)
  • GCP Service account with role set to Compute Instance Admin and Kubernetes Engine Admin. This key is going to be used to authenticate from the application to the GCP Compute API. See documentation.

Installing the Chart

To install the chart with the release name gke-pvm-killer:

helm upgrade --install gke-pvm-killer --namespace estafette rimusz/gke-pvm-killer \
    --set googleServiceAccount="$(cat path_to_your/google-service-account.json | base64)"

Installing with existing secret

You can deploy the Google service account google-service-account.json file as a Kubernetes secret.

Create the Kubernetes secret:

kubectl create secret generic gke-pvm-killer -n estafette --from-file=path_to_your/google-service-account.json

Pass the configuration file to helm:

helm upgrade --install gke-pvm-killer --namespace estafette rimusz/gke-pvm-killer \
    --set existingSecret="gke-pvm-killer"

NOTE: You have to keep passing the configuration file secret parameter as --set existingSecret="gke-pvm-killer" on all future calls to helm upgrade or set it in values.yaml file existingSecret: gke-pvm-killer!

Uninstalling the Chart

To uninstall/delete the gke-pvm-killer deployment:

helm delete --purge gke-pvm-killer

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following table lists the configurable parameters of the kubernetes-dashboard chart and their default values.

ParameterDescriptionDefault
image.repositoryImage repository nameestafette/estafette-gke-preemptible-killer
image.pullPolicyImage pull policyIfNotPresent
image.pullSecretsImage pull secret from private registry``
googleServiceAccountbase64 encoded google-service-account.json file``
existingSecretSpecifies an existing secret for google-service-account.json file``
node.drainTimeoutMax time in second to wait before deleting a node300
node.intervalTime in second to wait between each node check600
securityContext.enabledEnables Security Contexttrue
securityContext.userIdSecurity User Id1000
securityContext.groupIdSecurity Group Id1000
annotations.prometheus.io/scrapeThe address to listen on for Prometheus metrics requeststrue
annotations.prometheus.io/portThe port to listen for Prometheus metrics requests9001
livenessProbeSet liveness probe{}
resources.limits.cpuSpecifies CPU limit50m
resources.limits.memorySpecifies memory limit128Mi
resources.requests.cpuSpecifies CPU request10m
resources.requests.memorySpecifies memory request16Mi
nodeSelectorgke-pvm-killer node selector{}
tolerationsgke-pvm-killer node tolerations[]
affinitygke-pvm-killer node affinitycloud.google.com/gke-preemptible
podDisruptionBudget.enabledEnables Pod Disruption Budgetfalse
podDisruptionBudget.maxUnavailableMax unavailable Pods1
podDisruptionBudget.minAvailablemin unavailable Pods``
rbac.enabledSpecifies whether RBAC resources should be createdtrue

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

helm upgrade --install gke-pvm-killer --namespace estafette rimusz/gke-pvm-killer --set resources.limits.cpu=200m

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,

helm upgrade --install gke-pvm-killer --namespace estafette rimusz/gke-pvm-killer -f values.yaml

Tip: You can use the default values.yaml

Deploy gke-pvm-killer with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has gke-pvm-killer on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartgke-pvm-killer is pinned at v0.1.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply