K8s getting error after change gcloud sdk location on Macos - kubernetes

I'm just fished connect to my kubernete.
But affter that I need to change the gcloud location from /Download to /usr folder.
Next, I run install.sh file for update the new location in .bash_profile.
Then I check gcloud command. It working well
But when I run kubectl get pod. The error showing.
Unable to connect to the server: error executing access token command "/Users/panda/Downloads/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=fork/exec /Users/panda/Downloads/google-cloud-sdk/bin/gcloud: no such file or directory output= stderr=
Hmm, how to update the location of gcloud sdk for solve this problem.
Thanks for your help.

In your Kubeconfig file (probably in ~/.kube/config) you’ll see it has the old path to your gcloud CLI. Update that file with the new path.

Related

gcloud 'no such file or directory'

On Ubuntu 20.04, gcloud installed with snap install google-cloud-sdk --classic...
Today it no longer works. Yesterday there was an auto update.
$ kubectl get all
Unable to connect to the server: error executing access token command "/snap/google-cloud-sdk/188/bin/gcloud config config-helper --format=json": err=fork/exec /snap/google-cloud-sdk/188/bin/gcloud: no such file or directory output= stderr=
Version 188 it is referencing is gone, and it is now at 190. (Version 189 is also present.)
I've uninstalled and deleted the .config/gcloud, and reinstalled, but still have the same error.
Any tips on where to look for that stale path?
The problem is that gcloud stores the absolete reference to the gcloud binary to ~/.kube/config. The solution is to replace /snap/google-cloud-sdk/.*/gcloud -> /snap/bin/gcloud in ~/.kube/config.
Example of accomplishing this with perl on the command line:
perl -i -p -e 's/\/snap\/google-cloud-(sdk|cli)\/.*?\/gcloud/\/snap\/bin\/gcloud/' ~/.kube/config

gcloud SDK: Unable to write file

I installed gcloud SDK with brew cask install google-cloud-sdk
$ gcloud container clusters get-credentials my-gke-cluster --region europe-west4-c
Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials)
Unable to write file [/Users/xxxxx/my-repo]: [Errno 21] Is a directory: '/Users/xxxxx/my-repo'
Now all permissions of the folder and recursive files are restricted to 600 (drw-------). Tried to reinstall gcloud but with no effect on its behavior.
I assume you're using macOS and I'm unfamiliar with it.
The gcloud container clusters get-credentials command should write to a file called ${HOME}/.kube/config.
The error suggests that it's trying to write the credentials to /Users/xxxxx/my-repo and this is determined by the value of ${KUBECONFIG}. Have you changed either ${KUBECONFIG} or your ${HOME} environment variable? You should be able to printf "HOME=${HOME}\nKUBECONFIG=${KUBECONFIG}" to inspect these.
You may be able to choose a different destination by adjust the value of KUBECONFIG. Perhaps set this to /Users/xxxxx and try the command again.
Ultimately, this is some sugar to update the local configuration file. It should be possible to create this manually if needs be. If the above don't work, I can update this answer with more details.

error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

I have KUBECONFIG inside my .kube/ folder still facing this issue.
I have also tried
kubectl config set-context ~/.kube/kubeconfig.yml
kubectl config use-context ~/.kube/kubeconfig.yml
No luck! Still the same.
Answering my own question
Initially, I had lost a lot of time on this error, but later I found that my kubeconfig is not having the correct context.
I tried the same steps:
kubectl config set-context ~/.kube/kubeconfig1.yml
kubectl config use-context ~/.kube/kubeconfig1.yml
or add a line with kubeconfig to your ~/.bashrc file
export KUBECONFIG=~/.kube/<kubeconfig_env>.yml
Also, if you want to add multiple kubeconfig: Add it like in ~/.bashrc file
export KUBECONFIG=~/.kube/kubeconfig_dev.yml:~/.kube/kubeconfig_dev1.yml:~/.kube/kubeconfig_dev2.yml
with different Kube contexts and it worked well.
Though the error should simplify and return the specific error related to kubecontext.
But after some digging it worked.
if u are running k3s u can put the following line to ur ~/.zshrc / ~/.bashrc
k3s
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
By default, kubectl looks for a file named config in the $HOME/. kube directory. So you have to rename your config file or set its location properly.
Look here for more detailed explanation
I had the same problem because I used the Linux subsystem on Windows.
If you use the command kubectl in the subsystem, you must copy your config file to part of the Linux system.
For example, if your username on Windows is jammy, and your username is also jammy in the Linux subsystem, you must copy the config file
from:
/mnt/c/Users/jammy/.kube/config
to:
/home/jammy/.kube/

Unable to run Grafana server on local system

I have to create a plugin for Grafana. For that i cloned the code from Github and followed this. I have managed to build the grafana but having issue in running the server. I am getting the error
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath
I did find this issue at issue. I have copied the "sample.ini" and re-named it to "custom.ini" and used the following commands in the bin folder made after building the grafana
.\grafana-server.exe --config D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini
.\grafana-server.exe D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini
.\grafana-server.exe -config D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini
.\grafana-server.exe -config "D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini"
.\grafana-server.exe --config "D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini"
.\grafana-server.exe "D:\Go-UpdatedWorkSpace\grafana\conf\custom.ini"
But non of them worked. I am still getting the error
Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath
What am i doing wrong ? I am new to Grafana development, any help would be much appreciated.
I have managed to resolve the issue. I ran the Grafana locally by using following command
./grafana-server.exe -config "D:\Go-UpdatedWorkSpace\grafana\conf\defaults.ini" -homepath "D:\Go-UpdatedWorkSpace\grafana".
I executed this command on the "bin" folder created after building the grafana with GoLang. (There is also a bin folder inside the homepath directory, i think we can use any of then "bin" folder). Issue was that i was not providing "homepath" in the command. "homepath" is the directory where grafana code is cloned.
In case someone looking for Mac, the below works. I tried with grafana version 8.x . For default install, No need to give -config as -homepath should take care. this could run from any location.
/grafana-install-path/bin/grafana-server -homepath /grafana-install-path web

gcloud command changes ownership of the current directory

I'm performing usual operation of fetching kubernetes cluster credentials from GCP. The gcloud command doesn't fetch the credentials and surprisingly updates the ownership of the local directory:
~/tmp/1> ls
~/tmp/1> gcloud container clusters get-credentials production-ng
Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials) Unable to write file [/home/vladimir/tmp/1]: [Errno 21] Is a directory: '/home/vladimir/tmp/1'
~/tmp/1> ls
ls: cannot open directory '.': Permission denied
Other commands, like gcloud container clusters list work fine. I've tried to reinstall the gcloud.
This happens if your KUBECONFIG has an empty entry, like :/Users/acme/.kube/config
gcloud resolves the empty value as the current directory, changes permissions and tries to write to it
Reported at https://issuetracker.google.com/issues/143911217
It happened to be a problem with kubectl. Reinstalling it solved this strange issue.
If you, like me, have stuck with strange gcloud behavior, following points could help to track an issue:
Checking alias command and if it's really pointing to the intended binary;
Launch separate docker container with gsutil and feed it your config files. If the gcloud container clusters get-credentials ... runs smoothly there, than it's the problem with binaries (not configuration):
docker run -it \
-v $HOME/.config:/root/.config \
-v $HOME/.kube:/root/.kube google/cloud-sdk:217.0.0-alpine sh
Problem with binary can be solved just by reinstalling/updating;
If it's a problem with configs, then you could back them up and reinstall kubectl / gsutil from scratch using not just apt-get remove ..., but apt-get purge .... Be aware: purge removes config files!
Hope this would help somebody else.