What is the best way to authenticate to a GKE cluster without actually setting env variables for GOOGLE_APPLICATION_CREDENTIALS or KUBECONFIG. I have an application running on a container which has to communicate with multiple GKE clusters at once. Hence I am trying to generate the kubeconfig yaml file on the fly like so. But when I try to run any kubectl commands I get a non authorized error as it is expecting the service account creds to be set in the environment variable. Is there any way to actually avoid this and auth to multiple clusters on the fly by generating the kubeconfig file ?
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: {{.CertData}}
server: {{.MasterURL}}
name: {{.ClusterName}}
contexts:
- context:
cluster: {{.ClusterName}}
user: {{.ClusterName}}
name: {{.ClusterName}}
current-context: {{.ClusterName}}
kind: Config
preferences: {}
users:
- name: {{.ClusterName}}
user:
auth-provider:
config:
cmd-args: config config-helper --format=json
cmd-path: /usr/local/bin/gcloud/google-cloud-sdk/bin/gcloud
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: {{.ClusterName}}