Minikube 服务公开 public IP

Minikube service expose to public IP

我正在学习 Kubernetes 并尝试使用 MiniKube 部署应用程序。

我已经设法在 Minikube IP 上公开映射到 nginx pod 的服务。我可以在 url $(minikube ip):$(serviceport) 上访问 nginx 服务。这很好,但是我希望将其公开给 public 网络。目前此服务只能通过我的本地机器访问,我的 wifi 网络上的任何其他机器都无法访问它,因为它仅在 minikube ip 上公开。我不想通过 IPtables 转发我本地 linux 中的端口,我正在寻找一个内置的解决方案来将端口公开给世界(而不仅仅是在 minikube ip 上)。我知道它可以实现,因为 minikube 仪表板默认在本地主机上公开服务,这意味着 minikube 可以与其他网络适配器通信并可以注册端口,我不确定如何。

这是我的服务 yaml:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  name: nginxservice
  labels:
    app: nginxservice
spec:
  type: NodePort
  ports:
  - port: 80
    name: http
    targetPort: 80
    nodePort: 32756
  selector:
    app: nginxcontainer

您必须创建入口。 按照此文档中的步骤操作 - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/

@subudear 是对的 - 你需要 Ingress.

An API object that manages external access to the services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.

为了能够经常使用入口(我现在不是在谈论 minikube)- 仅仅创建 Ingress 对象是不够的。您应该先安装相关的 ingress controller.

有很多,最受欢迎的是:

前两个非常相似,但使用完全不同的注释。经常发生people confuse them


谈论minikube: 根据 guidelines,要安装 ingress,您唯一需要做的就是

minikube addons enable ingress

请注意,默认情况下,minikube 完全安装 NGINX Ingress 控制器

nginx-ingress-controller-5984b97644-rnkrg 1/1 Running 0 1m