Skip to content

Proper way to connect to a GKE cluster in production. #1664

Closed
@ginokurian87

Description

@ginokurian87

Describe the bug
I've been running around in circles trying to connect to GKE and get it working properly. Here are the steps that i did for the same.
I'm trying to connect to a GKE cluster from outside of the GCP env. For this i created a service account and downloaded the key.
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to the above key.
Also ran the gcloud container clusters get-credentials......... command locally to generate the config files.
Then wrote a sample java app based in the examples like below:

   GoogleCredentials.getApplicationDefault(); //so that the token is refreshed automatically
        KubeConfig.registerAuthenticator(new GCPAuthenticator());
        ApiClient client = Config.defaultClient();
        // if you prefer not to refresh service account token, please use:
        // ApiClient client = ClientBuilder.oldCluster().build();
        Configuration.setDefaultApiClient(client);
        CoreV1Api api = new CoreV1Api();
        V1PodList list =
                api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
        for (V1Pod item : list.getItems()) {
            System.out.println(item.getMetadata().getName());
        }

    }

When i run the code, for the first time it works well. However after(persumably!) the token refresh, i get the following error :

Exception in thread "main" java.lang.IllegalStateException: Unimplemented
	at io.kubernetes.client.util.authenticators.GCPAuthenticator.refresh(GCPAuthenticator.java:61)
	at io.kubernetes.client.util.KubeConfig.getAccessToken(KubeConfig.java:215)
	at io.kubernetes.client.util.credentials.KubeconfigAuthentication.<init>(KubeconfigAuthentication.java:57)
	at io.kubernetes.client.util.ClientBuilder.kubeconfig(ClientBuilder.java:297)
	at io.kubernetes.client.util.ClientBuilder.getClientBuilder(ClientBuilder.java:129)
	at io.kubernetes.client.util.ClientBuilder.standard(ClientBuilder.java:105)
	at io.kubernetes.client.util.ClientBuilder.standard(ClientBuilder.java:100)

It works If i do any kubectl operation in my local and then retry. Is this because of ISSUE-290?

All of the above hacks works in the local system, but whet would be the correct approach in prod? Do we have a err...less hacky way of connecting and staying connected to the GKE cluster ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions