<br/>  
I have a cluster on Digital Ocean. The API of my project is in  DO. My image is from google/cloud-sdk:alpine and also I installed gke-gcloud-auth-plugin with the following command
<pre><code>gcloud components install gke-gcloud-auth-plugin
</code></pre>
<p>I have another cluster on Google Kubernetes Engine. I want to create, list, delete pods on gke cluster from my api which is in DO. I use kubernetes go client. I give the kubeconfig file of gke cluster to go client. But when I try to do an operation (like listing pods) I get the following error:</p>
<pre><code> cred.go:145] print credential failed with error: Failed to retrieve access token:: failure while executing gcloud, with args [config config-helper --format=json]: exit status 1
2023/04/04 07:28:21 code: get_pod_error, error: Get &quot;https://..../api/v1/namespaces/default/pods/cloud-flow-80117068-9715-4374-b91b-799472d647be&quot;: getting credentials: exec: executable gke-gcloud-auth-plugin failed with exit code 1
</code></pre>
<p>I used the same method to create or delete pods on another cluster in DO and worked successfuly.</p>
<p>Briefly I want to connect GKE cluster from DO cluster by using kubeconfig file of GKE
Is there anyone who encounter with the same problem?
Thanks..</p>

computerengineer
<p>Finally I solved like following:</p>
<p>1: Create a secret with a token and service account. Then associate them.<br/>
2: Create a clusterrole (give necessary permissions) and clusterrolebinding. Associate them. <br/>
3: Associate the service account and clusterrolebinding.</p>
<p>Now you can use the token to connect gke cluster without using gke-gcloud-auth-plugin. <br/>
If I dont use the token argument, the output is: <br/></p>
<p><a href="https://i.stack.imgur.com/v31lx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v31lx.png" alt="enter image description here" /></a></p>
<p>But , if I use the token, it works successfully
<a href="https://i.stack.imgur.com/fYyfo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fYyfo.png" alt="enter image description here" /></a></p>
<p><br/><br/></p>
<p>Also the go code that uses token and prints the pods is like following:</p>
<pre><code>package main

import (
    &quot;context&quot;
    &quot;fmt&quot;
    &quot;os&quot;

    v1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
)

func main() {
    // Path to the kubeconfig file
    kubeconfigPath := &quot;/home/latif/.kube/config&quot;

    // Build the configuration from the kubeconfig file
    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, kubeconfigPath)
    if err != nil {
        fmt.Printf(&quot;Error building config from kubeconfig: %v&quot;, err)
        os.Exit(1)
    }

    // Set the authentication token
    config.BearerToken = &quot;my_token&quot;

    // Create a new Kubernetes client
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        fmt.Printf(&quot;Error creating Kubernetes client: %v&quot;, err)
        os.Exit(1)
    }

    // Get the list of pods in the default namespace
    pods, err := clientset.CoreV1().Pods(&quot;default&quot;).List(context.Background(), v1.ListOptions{})
    if err != nil {
        fmt.Printf(&quot;Error getting pods: %v&quot;, err)
        os.Exit(1)
    }

    // Print the name of each pod
    for _, pod := range pods.Items {
        fmt.Println(pod.Name)
    }
}
</code></pre>
