How to get the kubernetes config via sudo when using gcloud?

8/7/2017

Previously I asked a question: Why does kubectl have different behavior with sudo?

So it turns out that using gcloud, kubectl config is generated somehow. However when / how is this generated? And how could I generate the config to be present for the root user as well (for sudo purposes)?

-- Chris Stryczynski
gcloud
google-kubernetes-engine
kubectl
kubernetes

1 Answer

8/7/2017

When you type gcloud container clusters get-credentials <clustername> --zone <zone> then gcloud puts some credentials for the specified cluster into your ~/.kube/config file, and makes it the active context in kubectl. The gcloud command is documented here.

If you want the root user on your local machine to be able to access the cluster too, you need to install kubectl and gcloud where the root user can see them, and repeat theget-credentials command.

-- Eric Tune
Source: StackOverflow