Change the Timezone of GKE Containers

Change the timezone of every container in a GKE cluster with k8tz, instead of the default UTC.

Published
Read time 1 min
Stack GKE · k8tz · Helm · Cloud Shell

By default GKE Cluster with container image is using UTC+0 timezone, to change the timezone we need to use k8tz installed to the cluster. You can check the details of k8tz on their github page here https://github.com/k8tz/k8tz (opens in a new tab)

This example use GKE Private cluster with Access control plane using its external IP address enable.

First open Cloud Shell.

Check cloud shell external IP address using this command

Terminal window
dig +short myip.opendns.com @resolver1.opendns.com

Add cloud shell external IP to the cluster.

Terminal window
gcloud container clusters update CLUSTER_NAME \
--zone CLUSTER_ZONE_LOCATION \
--project PROJECT_ID \
--enable-master-authorized-networks \
--master-authorized-networks CLOUDSHELL_IP/32,

Connect to the cluster.

Terminal window
gcloud container clusters get-credentials CLUSTER_NAME \
--zone CLUSTER_ZONE_LOCATION \
--project PROJECT_ID

Install k8tz to the cluster using helm charts by running the following command:

Terminal window
helm repo add k8tz https://k8tz.github.io/k8tz/
helm install k8tz k8tz/k8tz --set timezone=Asia/Jakarta

don’t forget to change the timezone with your timezone.

Inject k8tz to the deployments or statefulsets using the following command:

  • For statefulsets

    Terminal window
    kubectl get statefulset -oyaml -n kubemq | \
    ./k8tz inject -tAsia/Jakarta - | kubectl apply -f -
  • For deployments

    Terminal window
    kubectl get deploy -oyaml -n kubemq | \
    ./k8tz inject -tAsia/Jakarta - | kubectl apply -f -

After that you can verify the timezone by run date command inside the pods using kubectl exec.


Next in Kubernetes & Containers