【问题标题】:How can I access the Kubernetes service from the Internet?如何从 Internet 访问 Kubernetes 服务?
【发布时间】:2018-10-24 07:47:12
【问题描述】:

我在 Linux Mint 上安装了 Kubernetes (minikube) 集群。然后我部署演示Example: Deploying WordPress and MySQL with Persistent Volumes

apiVersion: v1
kind: Service
metadata:
  name: wordpress
labels:
  app: wordpress
spec:
  ports:
    - port: 80
      nodePort: 30375
  selector:
    app: wordpress
    tier: frontend
  type: NodePort
  externalIPs:
    - 178.54.220.175
    - 192.168.1.10

如果外部ip 178.54.220.175仅在路由器中,主机ip为Linux 192.168.1.10,ip Kubernetes 192.168.99.100:30375,如何从互联网访问Kubernetes服务。

如何将这些 ip 地址与 178.54.220.175 -> 192.168.1.10 -> 192.168.99.100:30375 关联

【问题讨论】:

  • 一般情况下,当服务类型为负载均衡器时,您使用 mysql 的示例中会给出相同的外部 ips。
  • 我可以删除外部 IP。但这并不能改变现状。
  • 您可以将类型更改为负载均衡器或使用您公开的节点端口 http://:
  • 如你所说。我想输入一个专用的外部 IP 并使用我的 Kubernetes 服务。
  • 您可以通过创建入口来制作特定的url

标签: linux kubernetes ip minikube


【解决方案1】:

如果您使用 minikube,此功能将被禁用。

当使用 VirtualBox 作为管理程序时,您还可以使用 VirtualBox 的 NAT 端口转发功能来允许从外部访问通过 NodePorts 公开的服务。

类似这样的事情(范围有限,暴露整个默认的 NodePort 范围 30000-32767 需要永远...):

for port in {30000..30100}; do VBoxManage controlvm minikube natpf1 "NodePort$port,tcp,,$port,,$port"; done

您可以将其与通往 VPS 的反向 SSH 隧道相结合,以便任何人都可以从公共互联网临时访问:

R_ARGS=$(for port in {30000..30100}; do echo -n "-R $port:localhost:$port "; done)

autossh -M 0 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o ServerAliveInterval=5 -o ServerAliveCountMax=3 user@examplevps.com -N $R_ARGS

删除 VirtualBox 端口转发规则:

for port in {30000..30100}; do VBoxManage controlvm minikube natpf1 delete "NodePort$port"; done

虽然 SSH 转发方法更简单,而且我想与虚拟机管理程序无关,所以谢谢!

https://github.com/kubernetes/minikube/issues/877

https://cwienczek.com/reaching-minikube-from-your-machines-public-ip-aka-network-bridge/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 2020-11-23
    • 2021-11-24
    • 2020-07-28
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多