txn2 / kubefwd

Bulk port forwarding Kubernetes services for local development.
https://imti.co/kubernetes-port-forwarding/
Apache License 2.0
3.8k stars 205 forks source link

Error connecting to k8s cluster: Get "https://172.26.0.18/version" #233

Closed a1exus closed 2 years ago

a1exus commented 2 years ago

Hello World!

I'm following https://github.com/txn2/kubefwd#docker and while kubefwd mostly works for me, there are other times when it doesn't, like so:

% docker run -it --rm --privileged --name the-project \
    -v "$(echo $HOME)/.kube/":/root/.kube/ \
    txn2/kubefwd services -n the-project
INFO[23:00:42]  _          _           __             _     
INFO[23:00:42] | | ___   _| |__   ___ / _|_      ____| |    
INFO[23:00:42] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |    
INFO[23:00:42] |   <| |_| | |_) |  __/  _|\ V  V / (_| |    
INFO[23:00:42] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|    
INFO[23:00:42]                                              
INFO[23:00:42] Version 1.22.3                               
INFO[23:00:42] https://github.com/txn2/kubefwd              
INFO[23:00:42]                                              
INFO[23:00:42] Press [Ctrl-C] to stop forwarding.           
INFO[23:00:42] 'cat /etc/hosts' to see all host entries.    
INFO[23:00:42] Loaded hosts file /etc/hosts                 
INFO[23:00:42] HostFile management: Backing up your original hosts file /etc/hosts to /root/hosts.original 
FATA[23:00:42] Error connecting to k8s cluster: Get "https://172.26.0.18/version": error executing access token command "/Users/alexus/opt/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=fork/exec /Users/alexus/opt/google-cloud-sdk/bin/gcloud: no such file or directory output= stderr= 
% 

I've tried to mount my google-cloud-sdk, however now it's missing python...

% docker run -it --rm --privileged --name the-project \
    -v "$(echo $HOME)/.kube/":/root/.kube/ \
    -v "$HOME/opt/google-cloud-sdk/:$HOME/opt/google-cloud-sdk/" txn2/kubefwd services -n the-project
INFO[23:03:53]  _          _           __             _     
INFO[23:03:53] | | ___   _| |__   ___ / _|_      ____| |    
INFO[23:03:53] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |    
INFO[23:03:53] |   <| |_| | |_) |  __/  _|\ V  V / (_| |    
INFO[23:03:53] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|    
INFO[23:03:53]                                              
INFO[23:03:53] Version 1.22.3                               
INFO[23:03:53] https://github.com/txn2/kubefwd              
INFO[23:03:53]                                              
INFO[23:03:53] Press [Ctrl-C] to stop forwarding.           
INFO[23:03:53] 'cat /etc/hosts' to see all host entries.    
INFO[23:03:53] Loaded hosts file /etc/hosts                 
INFO[23:03:53] HostFile management: Backing up your original hosts file /etc/hosts to /root/hosts.original 
FATA[23:03:53] Error connecting to k8s cluster: Get "https://172.26.0.18/version": error executing access token command "/Users/X/opt/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exit status 127 output= stderr=/Users/X/opt/google-cloud-sdk/bin/gcloud: exec: line 192: python: not found

% 

Is there another way to handle that error? as API IS reachable:

/ # curl -skI https://172.26.0.18/version | head -1
HTTP/2 403 
/ # 

Please advise.

cjimti commented 2 years ago

I have not used the kubefwd docker container with gcloud. I suggest creating a new container with kubefwd and Python installed.

a1exus commented 2 years ago
% cat Dockerfile 
FROM google/cloud-sdk:alpine as cloud-sdk
COPY --from=cloud-sdk /google-cloud-sdk/ /google-cloud-sdk/ 

FROM python:alpine as python
COPY --from=python /usr/local /usr/local

FROM txn2/kubefwd:latest
% 

also, I found these useful as well:

% grep -A3 environment docker-compose.yml 
    environment:
      - CLOUDSDK_PYTHON="/usr/local/bin/python"
      - CLOUDSDK_CONFIG="/google-cloud-sdk/config"
      - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/google-cloud-sdk/bin
%