1

I've been able to deploy things via helm, and even directly with a docker push to a GCP container. But I can't figure out how to get kubectl to access the GCP cluster. When I search for accessing a GCP cluster via kubectl, it always talks about creating a new cluster. I already have one. I'm still learning this; so in the process I was able to get this to work with a Service rather than a User. However, I'd like to force my kubectl (especially) to use my GCP's admin user. This is a personal, throwaway account; I wouldn't take this approach on a more serious environment.

How can I tell kubectl, hey, sign in as joe@example.com? For that matter, how do I display whatever credentials (user, service, etc) it is trying to use to authenticate?

lepsch
  • 8,927
  • 5
  • 24
  • 44
Woodsman
  • 901
  • 21
  • 61

2 Answers2

0

Check if gcloud auth list outputs the correct account.

Did you authenticate against your GKE cluster?

Check if kubectl config get-contexts outputs correct cluster contexts.

You can auth against your cluster by running gcloud container clusters get-credentials <cluster name> --region <cluster region> --project <gcp project of cluster>

bilcy
  • 168
  • 1
  • 12
0

To store cluster information for kubectl, first you need to review the current context configured for kubectl. Kubernetes uses a config YAML file to store cluster authentication, this file stores a group of access parameters called contexts; to review the content of this file you can use this command:

kubectl config view

Then, we need to check the kubeconfig file generated for your cluster. If you have not generated a kubeconfig context for your cluster, you can run this command:

gcloud container clusters get-credentials CLUSTER_NAME

Once the kubeconfig has been generated, you can run individual kubectl commands against your cluster, so you can use this command to add the user and password to your configuration file:

kubectl config --kubeconfig=config-demo set-credentials experimenter --username=exp --password=some-password

Note: config-demo must be replaced with the name of your config file.

You can check this public document if you need more assistance with access to kubectl in Kubernetes.

Leo
  • 695
  • 3
  • 11