2

My Docker for Windows ~/.kube/config file was replaced when setting up access to cloud based K8s cluster.

Is there a way to re-create it without having to restart Docker for Windows Kubernetes?

Update My current ~/.kube/config file is now set to a GKE cluster. I don't want to reset Docker for Kubernetes and clobber it. Instead I want to create a separate kubeconfig file for Docker for Windows i.e. place it in some other location rather than ~/.kube/config.

Community
  • 1
  • 1
DarVar
  • 16,882
  • 29
  • 97
  • 146

3 Answers3

5

You probably want to back up your ~/.kube/config for GKE and then disable/reenable Kubernetes on Docker for Windows. Pull up a Windows command prompt:

copy \<where-your-.kube-is\config \<where-your-.kube-is\config.bak

Then follow this. In essence, uncheck the box, wait for a few minutes and check it again.

docker for windows

You can re-recreate without disabling/reenabling Kubernetes on Docker but you will have to know exactly where your API server and credentials (certificates, etc):

 kubectl config set-context ...
 kubectl config use-context ...

What's odd is that you are specifying ~/.kube/config where the ~ (tilde) thingy is unix/linux thing, but maybe what you mean is $HOME

Rico
  • 58,485
  • 12
  • 111
  • 141
1

I just want to add to this, in case you are using wsl as kubectl/docker client as I am. You can find your local kubernetes config in C:\Users\username\.kube\config.

You can then use that to create a new kubernetes context for docker.

For instance: cp /mnt/c/Users/username/.kube/config ~/.kube/docker-k8s.config

docker context create local-k8s --default-stack-orchestrator=kubernetes --kubernetes config-file=/home/username/.kube/docker-k8s.config --docker host=tcp://localhost:2375

Note: I have exposed the docker engine on port 2375. The default settings for the unix sock type of connection can be found on the link above. You need to add the absolute path to the kubeconfig, you can't use '~'.

Then you can use docker context use <context name> to switch between your local docker-desktop kubernetes cluster and an external cloud env cluster with your docker client.

docker context ls will show the local existing contexts.

Arizon
  • 56
  • 1
  • 10
0

You basically want to access multiple clusters. One option is to play around with KUBECONFIG environmental variable. Here is the documentation.

The KUBECONFIG environment variable is a list of paths to configuration files. The list is colon-delimited for Linux and Mac, and semicolon-delimited for Windows. If you have a KUBECONFIG environment variable, familiarize yourself with the configuration files in the list.

Or, you can provide an inline option.

kubectl config --kubeconfig=config-demo set-context dev-frontend --cluster=development --namespace=frontend --user=developer
kubectl config --kubeconfig=config-demo set-context dev-storage --cluster=development --namespace=storage --user=developer
kubectl config --kubeconfig=config-demo set-context exp-scratch --cluster=scratch --namespace=default --user=experimenter

And then use use-context

Vishrant
  • 15,456
  • 11
  • 71
  • 120