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
dig +short myip.opendns.com @resolver1.opendns.com
-
Add cloud shell external IP to the cluster.
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.
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:
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
kubectl get statefulset -oyaml -n kubemq | \ ./k8tz inject -tAsia/Jakarta - | kubectl apply -f -
-
For deployments
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
.