minikube overwrites existing ~/.kube/config when starting up

Created on 23 Jun 2017  路  3Comments  路  Source: kubernetes/minikube

When starting minikube, if there is an existing ~/.kube/config kubeconfig it will be overwritten by minikube.

Minikube version (use minikube version): v0.19.0

Environment:

  • OS (e.g. from /etc/os-release): Mac OS 10.12.5
  • VM Driver (e.g. cat ~/.minikube/machines/minikube/config.json | grep DriverName): virtualbox
  • ISO version (e.g. cat ~/.minikube/machines/minikube/config.json | grep -i ISO or minikube ssh cat /etc/VERSION): .minikube/cache/iso/minikube-v0.18.0.iso
  • Install tools:
  • Others:

What happened:

What you expected to happen: The pre-existing kubeconfig to be maintained after exiting or prompted at startup whether to overwrite the existing config or not.

How to reproduce it (as minimally and precisely as possible): Start minikube with a pre-existing ~/.kube/config present that is different than minikube.

kinbug

Most helpful comment

@r2d4 I must have pre-maturely entered this. I retested myself and cannot reproduce either. I think I saw the file get changed by looking at the last modified and then when inspecting it too quickly assumed it was actually replaced. My apologies for the noise/trouble. I am closing.

Thank you for your work/contributions.

All 3 comments

I wasn't able to reproduce this. Minikube will switch the context, but it will only append the contents of your kubeconfig.

Steps I took:

  1. rm ~/.kube/config
  2. Set up kubeconfig with a GKE entry with gcloud container clusters get-credentials cluster-2 \ --zone us-central1-b --project r2d4minikube
  3. Start minikube
  4. 4.
$ kubectl config get-clusters
NAME
gke_r2d4minikube_us-central1-b_cluster-2
minikube

$ kubectl config get-contexts
CURRENT   NAME                                       CLUSTER                                    AUTHINFO                                   NAMESPACE
*         minikube                                   minikube                                   minikube                                   
          gke_r2d4minikube_us-central1-b_cluster-2   gke_r2d4minikube_us-central1-b_cluster-2   gke_r2d4minikube_us-central1-b_cluster-2   

Anything else you might be able to provide to help debug?

@r2d4 I must have pre-maturely entered this. I retested myself and cannot reproduce either. I think I saw the file get changed by looking at the last modified and then when inspecting it too quickly assumed it was actually replaced. My apologies for the noise/trouble. I am closing.

Thank you for your work/contributions.

As I did not want to merge my kubeconfigs and still switch with my zsh directly and fast with a command.
I just set a different $KUBECONFIG path everytime I use minikube.
I created the following alias for my minikube:

# minikube
minikube(){
    if [[ ($1 == "start") ]]; then
        export LAST_KUBECONFIG=$KUBECONFIG
        export KUBECONFIG="${HOME}/.kube/configs/minikube.yaml"
        command minikube "$@"
        eval $(minikube -p minikube docker-env)
        echo '...done'
    elif [[ ($1 == "stop") ]]; then
        export KUBECONFIG=$LAST_KUBECONFIG
        command minikube "$@"
        echo '* $KUBECONFIG='$KUBECONFIG
    else
        command minikube "$@"
    fi
}

Start is changing to a default minikube configuration file on my system starting minikube and then exposing the images that minikube is using
Stop is changing back to the previously set config and stops minikube

I use the folder ${HOME}/.kube/configs/ as my directory where I store all of my different kubectl configurations.

Was this page helpful?
0 / 5 - 0 ratings