ubuntu 节点无法连接google

71 阅读2分钟

1 目标

让「局域网 Ubuntu 物理机」所有流量自动走「另一台 Windows 上的 Claxx xxrge」

2 操作

临时命令行代理(最快验证) 在 Ubuntu 里执行(假设 Windows 的局域网 IP 是 192.168.1.100,Clash 默认 HTTP 端口 7890):

export http_proxy="http://192.168.1.100:7890"
export https_proxy="http://192.168.1.100:7890"
# 立即测试
curl -I https://www.google.com

能通就说明链路 OK;把上面两行写进 ~/.bashrc 可长期生效。
缺点:仅对认 http_proxy 的程序生效,浏览器、snap、docker 不一定吃。

3 查看windows机器的局域网ip

ipconfig

问题

问题1

执行 kubectl get node 会直接卡住 原因: 把 http_proxy/https_proxy 指向了 Clash,但 kubectl/helm 也会去读这两个变量,结果本机→apiserver 的内网流量被错误地转到了代理,而 apiserver 地址(apiserver.cluster.local:6443并不需要、也不应该走代理,于是出现 EOF/connection refused

解决思路
“让 apiserver 地址直连,其余流量继续走代理”——给 kubectl/helm 设置 NO_PROXY 即可。

# 1. 清掉刚才的代理(可选,验证用)
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
kubectl version   # 先确认能直连

# 2. 重新导出代理,但把「内网网段 + 集群域名」排除
export http_proxy="http://192.168.18.196:7897"
export https_proxy="http://192.168.18.196:7897"
export NO_PROXY="localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.cluster.local,.svc,.kubernetes,apiserver.cluster.local"

问题2

执行kubectl get node 显示notready

kubectl get node
NAME              STATUS     ROLES           AGE    VERSION
k8s-master-node   NotReady   control-plane   4d7h   v1.27.7

日志里清一色 EOF 指向 **apiserver.cluster.local:6443—— kubelet 根本连不上 apiserver,所以节点一直NotReady`,Pod 也永远调度不了。

根因还是 “kubelet → apiserver” 的流量被错误地送到 Clash 代理(变量末尾空格、或者 NO_PROXY 没生效)。

立刻让 kubelet 直连(临时去掉代理)

# 1. 删掉错误代理文件
sudo rm -f /etc/systemd/system/kubelet.service.d/http-proxy.conf \
            /etc/systemd/system/containerd.service.d/http-proxy.conf

# 2. 重载并重启
sudo systemctl daemon-reload
sudo systemctl restart containerd
sudo systemctl restart kubelet

问题3

docker 如何能够稳定下载

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<'EOF'
[Service]
Environment="HTTP_PROXY=http://192.168.18.196:7897"
Environment="HTTPS_PROXY=http://192.168.18.196:7897"
Environment="NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker