如何从外部访问Pod IP [英] How to access pod IP from outside

查看:81
本文介绍了如何从外部访问Pod IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是k8s的新秀.

我知道Pod IP由-cluster-cidr 设置在范围内.例如. 10.244.0.0/18

I know the pod IP is set in range by --cluster-cidr. eg. 10.244.0.0/18

我的问题是如何从k8s集群外部访问pod IP.

My question is how to access the pod IP from outside the k8s cluster.

我听说有两种方法可以做到这一点:

I heard of 2 ways to do that:

  1. 使 Docker 桥使用自定义的Linux桥,使用/etc/docker/daemon.json 中的一些技巧,然后通过在路由器设备上添加路由记录> ip路由通过{k8sNodeIp} (或类似的方法,我不知道详细信息)添加10.244.0.0/18.
  1. Make Docker bridge use a self defined Linux bridge, some tricks in /etc/docker/daemon.json, then add route records at the router device by ip route add 10.244.0.0/18 via {k8sNodeIp}(or something like that, I dont know details).

    1. 类似于上一个,但是他们似乎完成了没有桥梁技巧"的工作,只需添加一些路线记录(如果我错了,请告诉我).

  • 这些解决方案来自两个不同的团队.

    These solutions are from two different teams.

    我不知道是否涉及k8s网络插件,第一个使用 flannel ,最后一个使用 calico .

    I dont know if the k8s network plugin got involved, the first one uses flannel and the last one uses calico.

    关于这个的任何文档吗?

    Any docs about that?

    推荐答案

    答案

    您可以使用 kubectl port-forward 直接与Pods 中的容器进行对话,以进行调试/开发 .

    Answer

    You can use kubectl port-forward to talk directly to containers in Pods for the purposes of debugging / development.

    例如 kubectl port-forward mypod 5000:6000

    此处中查看文档>

    此命令将在您的工作站上设置代理,以便您可以运行,例如:

    This command will set up a proxy on your workstation so that you can run, for example:

    curl localhost:5000/api/v1/status
    

    此请求将转发到API服务器,然后将其转发到您在 port-forward 命令中指定的Pod.

    This request will be forwarded to the API Server, which will then forward your request to the Pod you specify in the port-forward command.

    这篇关于如何从外部访问Pod IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆