大网数据广告活动
服务器运维问答

Kubernetes how to expose a port on host node to pods?

· 52CE 我爱测

We are just getting started with k8s. One of the things we need to do is expose a service running on each bare metal Ubuntu 20.04 host node to pods in k8s. The service is listening on the node's real IP as well as localhost on po…

问题原文

原帖链接 · David Tinker · CC BY-SA 4.0

We are just getting started with k8s. One of the things we need to do is expose a service running on each bare metal Ubuntu 20.04 host node to pods in k8s. The service is listening on the node's real IP as well as localhost on port 8500. Is there an easy way to do this?

I can get to port 80 and 443 on the node from inside a pod using its IP but not to 8500.

已采纳解答

原帖链接 · Mikołaj Głodziak · CC BY-SA 4.0

As @David Tinker mentioned in the comments, problem is solved.

connections from inside k8s pods on the same host would get blocked by our firewall rules.

So, the solution is hidden in iptables:

iptables -A INPUT -p tcp --dport 8500 -j ACCEPT
iptables -A INPUT -i cni0 -j ACCEPT

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-05-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。