如何通过互联网访问Kubernetes服务?

How can I access the Kubernetes service from the Internet?

我在 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为Linux192.168.1.10,ip Kubernetes 192.168.99.100:30375.

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

如果您使用 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 隧道相结合,这样任何人都可以从 public 互联网临时访问:

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/