Get back docker-for-windows Kuberentes kubeconfig file after deleting it

2/17/2019

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.

-- DarVar
docker
docker-for-windows
kubernetes

2 Answers

2/17/2019

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
Source: StackOverflow

2/17/2019

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
Source: StackOverflow