代码之家  ›  专栏  ›  技术社区  ›  Compozitor

如何从Internet访问Kubernetes服务?

  •  0
  • Compozitor  · 技术社区  · 6 年前

    我在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中,如何从Internet访问Kubernetes服务。

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

    1 回复  |  直到 6 年前
        1
  •  2
  •   Compozitor    6 年前

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

    当使用VirtualBox作为虚拟机监控程序时,您还可以使用VirtualBox NAT端口转发功能来允许从外部访问通过节点报告公开的服务。

    类似这样的情况(范围有限,公开30000-32767的整个默认NodePort范围需要很长时间……):

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

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

    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转发方法更简单,但我认为它与hypervisor无关,所以感谢您!

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

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