10
Jan
2024

GCP autostart

10 Jan 2024
**Kubectl** subl subl /home/USER/.config/systemd/user/kubectl.service [Unit] Description=Kubectl Port Forward [Service] Type=simple ExecStart=/home/USER/Autostart/kubectl_port_forward.sh Restart=on-failure RestartSec=5 [Install] WantedBy=default.target subl /home/USER/Autostart/kubectl_port_forward.sh #!/bin/bash # Set the path to the Google Cloud SDK (adjust the path based on your installation) export PATH="/home/USER/Apps/google-cloud-sdk/bin:$PATH" # Set the path to the gke-gcloud-auth-plugin executable export GKE_GCLOUD_AUTH_PLUGIN="/home/USER/Apps/google-cloud-sdk/bin/gke-gcloud-auth-plugin" # Set the Kubernetes configuration file path (adjust the path based on your configuration) export KUBECONFIG="/home/USER/.kube/config" # Set the path to your service account key file export GOOGLE_APPLICATION_CREDENTIALS="/home/USER/.config/gcloud/application_default_credentials.json" # Authenticate with Google Cloud using the service account gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS" # Run kubectl port-forward with the necessary authentication kubectl port-forward svc/mysql-stage-v8-k8sqlv3-stage-v8 -n mysql 3321:3306 systemctl --user enable kubectl_port_forward systemctl --user start kubectl_port_forward **Cloud SQL Proxy** subl /home/USER/.config/systemd/user/cloud-sql-proxy.service [Unit] Description=Cloud SQL Proxy [Service] Type=simple ExecStart=/home/USER/cloud_sql_proxy -instances=autodoc-XXXXXXX:europe-west3:slave-11=tcp:3311 #master Restart=on-failure RestartSec=5 [Install] WantedBy=default.target