Reputation: 825
I´m running windows 10 with WSL1 and ubuntu as distrib. My windows version is Version 1903 (Build 18362.418)
I´m trying to connect to kubernetes using kubectl proxy within ubuntu WSL. I get a connection refused when trying to connect to the dashboard with my browser.
I have checked in windows with netstat -a to see active connections.
If i run kubectl within the windows terminal i have no problem to connect to kubernetes, so the problem is only happening when i try to connect with ubuntu WSL1.
I have also tried to run the following command
kubectl proxy --address='0.0.0.0' --port=8001 --accept-hosts='.*'
... but the connection is refused although i see that windows is listening to the port. Changing port to another port didn´t fix the proble. Disabling the firewall didnt´fix the problem as well.
Any idea ?
Upvotes: 1
Views: 1775
Reputation: 617
WSL has a virtual ip, so 127.0.0.1 (localhost) from windows points at your windows host (not WSL).
I wrote this run-proxy.sh
script, hopefully it helps others
#!/bin/bash
# Find the WSL2 IP Address
wsl_ip=$(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1)
if [ -z "$wsl_ip" ]; then
echo "Failed to find the WSL2 IP address."
exit 1
fi
echo "WSL2 IP Address: $wsl_ip"
# Set the desired port for kubectl proxy
proxy_port=8001
echo "Starting kubectl proxy on http://$wsl_ip:$proxy_port"
echo "dashboard: http://$wsl_ip:$proxy_port/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/"
kubectl proxy --address="$wsl_ip" --port=$proxy_port --accept-hosts='.*'
# Note: You can access Kubernetes API from Windows using http://$wsl_ip:$proxy_port
Upvotes: 0
Reputation: 13888
First thing to do would be to check if you able to safely talk to your cluster: (kubectl get svc -n kube-system
, kubectl cluster-info
)
If not check if $HOME/.kube
folder was created. If not, run:
gcloud container clusters get-credentials default --region=<your_region>
Upvotes: 2