Kubernetes: Wait until another pod is ready

November 2, 2020

The idea is to wait inside an init-container until the health check is successful. The health check, in this case, is the HTTP response code equal to 200.

  • This init-container will continue after the service returns 200.
  • If the init-container doesn't complete, the container will not be executed.
initContainers:
- name: wait-for-webserver
  image: curlimages/curl:latest
  command: ["/bin/sh","-c"]
  args: ["while [ $(curl -sw '%{http_code}' http://webserver.svc.cluster.local -o /dev/null) -ne 200 ]; do sleep 5; echo 'Waiting for the webserver...'; done"]
Read more

Kubernetes: Global environment variables for pods

September 30, 2020

I was trying to insert a few global environment variables to every container running, so one of the options was Pod Presets but I realized this feature will be removed in Kubernetes 1.20.x, check this pull request).

One of the solution is create a ConfigMap and use the envFrom to define all of the ConfigMap's data as container environment variables.

Read more

Persistent volume in Kubernetes cluster with multiple availability zones

August 25, 2020

After a wild using Kubernetes in AWS and set-up persistent volumes via EBS, I faced a problem with evicted pods after they are re-schedule to another node; The issue was the EBS volumes are dedicated by zone, makes sense because the volumes work via networking and are dedicated per datacenter, for the network latency.

Read more

Kubernetes multiple zones and autoscaling

July 6, 2020

After a while using Kubernetes, I tried to improve the cluster and try to use all the features from the cloud provider such as the autoscaling groups and multiple availability zones.

The environment

  • AWS (The idea is the same for other cloud providers)
  • Kubernetes
  • Autoscaling groups for the workes for each availability zone (zone-a, zone-b, zone-c).
  • Cluster-Autoscaler (CA)

The cluster will scale when:

  • There are pods that failed to run in the cluster due to insufficient resources.
  • There are nodes in the cluster that have been underutilized for an extended period of time and their pods can be placed on other existing nodes.
Read more