Change GKE Container Timezone

Change GKE Container Timezone

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

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
1
dig +short myip.opendns.com @resolver1.opendns.com

Add cloud shell external IP to the cluster.

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

Connect to the cluster.

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

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

Terminal window
1
helm repo add k8tz https://k8tz.github.io/k8tz/
2
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
    1
    kubectl get statefulset -oyaml -n kubemq | \
    2
    ./k8tz inject -tAsia/Jakarta - | kubectl apply -f -
  • For deployments

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

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