[Solved] gcloud command changes folder permission and ownership

I was trying with google cloud kubernetes and was trying to setup clusters. I was following guideline from google cloud page. https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials

~/personal/www/test ᐅ gcloud beta container clusters get-credentials whooweme-dev-cluster
Fetching cluster endpoint and auth data.
ERROR: (gcloud.beta.container.clusters.get-credentials) Unable to write file [/Users/samundra/personal/www/test]: [Errno 21] Is a directory: '/Users/samundra/personal/www/test'

Look at the second line, that is being reported by gcloud. But nowhere it mentions anything about KUBECONFIG. The root cause is environment variable KUBECONFIG contains empty entry. You might have something like this.

export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config

Here, the first $KUBECONFIG could result in empty string and thus leading to issue. Gcloud command tries to create directory in the current directory and thus fails.

Same issue happens with minikube start. But minikube error is more friendly then gcloud.

Sample output of minikube when it fails on same error

~/personal/www ᐅ minikube start
There is a newer version of minikube available (v1.11.0).  Download it here:
https://github.com/kubernetes/minikube/releases/tag/v1.11.0

To disable this notification, run the following:
minikube config set WantUpdateNotification false
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
E0611 03:03:50.611997   86710 start.go:289] Error setting up kubeconfig:  writing kubeconfig: Error writing file : open : no such file or directory

Now, we know what caused the problem, lets dive into solution. Here, we have two solutions.

  1. Remove $KUBECONFIG and start with proper path e.g. $HOME/.kube/config
  2. unset KUBECONFIG altogether from environment

I used solution 1 as I sometime have to use other clusters. However we can also use solultion 2 for quickfix and source our `.bashrc` or `.zshrc` as per our shell. I hope this helps someone out there having the same problem as me.

While trying to fix this issue, I landed to github issues and stackoverflow. They are listed below:

  • https://stackoverflow.com/questions/54927224/gcloud-command-changes-ownership-of-the-current-directory
  • https://github.com/kubernetes/minikube/issues/4100

Leave a Reply

Your email address will not be published. Required fields are marked *