[kubernetes]Calico运行异常:dial tcp 10.96.0.1:443: connect: connection refused

安装Calico后,pod未能进入Ready状态,报错:dial tcp 10.96.0.1:443: connect: connection refused。错误根源不在于iptables,而是由于10.96.0.1是kubernetes API的ClusterIP。集群内pod通过kube-proxy访问此服务。问题可能是kube-proxy未运行或异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装calico网络插件之后,发现相关pod一直不能进入Ready状态,查看log,出现如下问题:

Hit error connecting to datastore - retry error=Get “https://10.96.0.1:443/api/v1/nodes/foo”: dial tcp 10.96.0.1:443: connect: connection refused

网上查资料都说是什么iptables配置的问题,各种尝试,发现完全不对。于是打算从根源了解这个东西。

那么这个10.96.0.1到底是什么呢?原来

在 kubernetes,可以从集群外部和内部两种方式访问 kubernetes API,在集群外直接访问 apiserver 提供的 API,在集群内即 pod 中可以通过访问 service 为 kubernetes 的 ClusterIP。kubernetes 集群在初始化完成后就会创建一个 kubernetes service,该 service 是 kube-apiserver 创建并进行维护的,如下所示:

[root@master1 dingpwen]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   2d20h

内置的 kubernetes service 无法删除,其 ClusterIP 为通过 --service-cluster-ip-range 参数指定的 ip 段中的首个 ip,kubernetes endpoints 中的 ip 以及 port 可以通过 --advertise-address 和 --secure-port 启动参数来指定。

那么我们Node上的pod又如何才能访问到这个服务呢?毕竟相对于master机器,Node机器通过ip访问相当于“外网”。

其实我们查看kube-proxy的代码就会发现

I0427 01:46:24.595581       1 config.go:233
[reset] Unmounting mounted directories in "/var/lib/kubelet" W0321 14:19:36.524481 91940 cleanupnode.go:99] [reset] Failed to remove containers: [failed to stop running pod cdf897d2b8231f7d3fffa49017090a655b94ddb22cbc24d06f32d519fbaa2c5f: output: E0321 14:19:19.953922 92079 remote_runtime.go:205] "StopPodSandbox from runtime service failed" err="rpc error: code = Unknown desc = failed to destroy network for sandbox \"cdf897d2b8231f7d3fffa49017090a655b94ddb22cbc24d06f32d519fbaa2c5f\": plugin type=\"calico\" failed (delete): error getting ClusterInformation: Get \"https://10.96.0.1:443/apis/crd.projectcalico.org/v1/clusterinformations/default\": dial tcp 10.96.0.1:443: connect: connection refused" podSandboxID="cdf897d2b8231f7d3fffa49017090a655b94ddb22cbc24d06f32d519fbaa2c5f" time="2025-03-21T14:19:19+08:00" level=fatal msg="stopping the pod sandbox \"cdf897d2b8231f7d3fffa49017090a655b94ddb22cbc24d06f32d519fbaa2c5f\": rpc error: code = Unknown desc = failed to destroy network for sandbox \"cdf897d2b8231f7d3fffa49017090a655b94ddb22cbc24d06f32d519fbaa2c5f\": plugin type=\"calico\" failed (delete): error getting ClusterInformation: Get \"https://10.96.0.1:443/apis/crd.projectcalico.org/v1/clusterinformations/default\": dial tcp 10.96.0.1:443: connect: connection refused" : exit status 1, failed to stop running pod e4fee45416ccc066380fe4d0f2f28ca861bf836967d88f2074ce62d6d77ec9ed: output: E0321 14:19:20.255860 92242 remote_runtime.go:205] "StopPodSandbox from runtime service failed" err="rpc error: code = Unknown desc = failed to destroy network for sandbox \"e4fee45416ccc066380fe4d0f2f28ca861bf836967d88f2074ce62d6d77ec9ed\": plugin type=\"calico\" failed (delete): error getting ClusterInformation: Get \"https://10.96.0.1:443/apis/crd.projectcalico.org/v1/clusterinformations/default\": dial tcp 10.96.0.1:443: connect: connection refused" podSandboxID="e4fee45416ccc066380fe4d0f2f28ca861bf836967d88f2074ce62d6d77ec9ed" time="2025-03-21T14:19:20+08:00" level=fatal msg="stopping the pod sandbox \"e4fee45416ccc06638
最新发布
03-22
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值