• 欢迎访问本站,本站记录博主日常编程遇到的问题,知识,惊奇软件等。如有问题还请留言


    Deprecated: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/gschaos.club/wp-content/themes/Git-alpha-6h0SRk/header.php on line 294

外网访问minikube内的pod

k8s mysticalycc 3年前 (2022-06-05) 1501次浏览 已收录 0个评论
文章目录[隐藏]

minikube 是一款基于 Kubernetes 的定位于快速验证功能的小型容器编排环境。

由于它的定位特性,我们在使用中会发现 minikube 虚拟出了一个 IP 作为自身的节点 IP,该 IP 和宿主机不同。对于 NodePort 类型的 Service 也没有办法通过 127.0.0.1 访问。

Host 内访问

The minikube VM is exposed to the host system via a host-only IP address, that can be obtained with the minikube ip command.

我们必须通过 minikube ip 找到 minikube 的 IP 并通过它来访问 NodePort 类型的 service

另外可以留意到 LoadBalancer 类型的 service 在默认情况下 external IP 为 <pending>,为了要能够访问到 service,需要通过 minikube tunnel 建立隧道和服务通信。在执行 minikube tunnel 后,可以发现 external IP 被设置成和 cluster IP 一样的值,这时候就可以通过 <minikube-ip>:<service-port> 来访问 service 了。

Host 外访问

通过 minikube 可以很方便地在本机访问,同时避免了对宿主机端口的占用。但是也带来了另一个问题:无法直接通过访问宿主机的端口来访问 services 进行调试。

比如我的实验机是一台云服务虚拟机,我在自己的电脑上可以访问这台虚拟机,但是不能访问虚拟机上 minikube 暴露的服务。

虽然没有办法让 minikube 直接通过宿主机端口对外暴露 services,但是如果我们把问题换个角度思考,就很容易找到解决办法:如何将一个 service(不特定类型)暴露到本机。

这时候最简单的办法就是通过 kubectl port-forward 转发端口。

假设我有 service/istio-ingressgateway,service 监听 80 端口,我希望暴露在宿主机的 31303 端口,就可以使用以下命令1:·

使用启动minikube的用户执行以下命令

kubectl port-forward --address 0.0.0.0 -n istio-system service/istio-ingressgateway 31303:80

MysticalYcc , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:外网访问minikube内的pod
喜欢 (0)
mysticalycc
关于作者:
简短的个人签名

Warning: Attempt to read property "comment_author_email" on null in /www/wwwroot/gschaos.club/wp-content/themes/Git-alpha-6h0SRk/comments.php on line 47
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到