How to generate kubeconfig user for a service-account?

10/26/2019

I'm stuck at creating a user for my serivice_account which I can use in my kubeconfig

Background: I have a cluser-A, which I have created using the google-cloud-python library. I can see the cluster created in the console. Now I want to deploy some manifests to this cluster so i'm trying to use the kubernetes-python client. To create a Client() object, I need to have a KUBECONFIG so I can:

client = kubernetes.client.load_kube_config(<MY_KUBE_CONFIG>)

I'm stuck at generating a user for this service_account in my kubeconfig. I don't know what kind of authentication certificate/key I should use for my user.

Searched everywhere but still can't figure out how to use my service_account to access my GKE cluster through the kubernetes-python library.

Additional Info: I already have a Credentials() object (source) created using the service_accounts.Credentails() class (source).

-- Panda
google-kubernetes-engine
kubernetes
python
service-accounts

1 Answer

10/26/2019

A Kubernetes ServiceAccount is generally used by a service within the cluster itself, and most clients offer a version of rest.InClusterConfig(). If you mean a GCP-level service account, it is activated as below:

gcloud auth activate-service-account --key-file gcp-key.json

and then probably you would set a project and use gcloud container clusters get-credentials as per normal with GKE to get Kubernetes config and credentials.

-- coderanger
Source: StackOverflow