简体   繁体   English

Minikube 服务公开 IP

[英]Minikube service expose to public IP

I am learning Kubernetes and trying to deploy an app using MiniKube.我正在学习 Kubernetes 并尝试使用 MiniKube 部署应用程序。

I have managed to expose the service mapped to nginx pod on Minikube IP.我已经设法在 Minikube IP 上公开映射到 nginx pod 的服务。 I can access the nginx service on url $(minikube ip):$(serviceport).我可以访问 url $(minikube ip):$(serviceport) 上的 nginx 服务。 which is fine, however I am looking to expose this to the public network.这很好,但是我希望将其公开给公共网络。 Currently this service is only accessible via my local machine, any other machine on my wifi network is not able to access it as it is exposed only on minikube ip.目前,该服务只能通过我的本地机器访问,我的 wifi 网络上的任何其他机器都无法访问它,因为它仅在 minikube ip 上公开。 I dont want to forward the port in my local linux via IPtables, and I am looking for a built in solution to expose the port to world (and not just on minikube ip).我不想通过 IPtables 在我的本地 linux 中转发端口,我正在寻找一个内置的解决方案来向世界公开端口(而不仅仅是在 minikube ip 上)。 I know it can be achieved as minikube dashboard by default expose the service on localhost, this implies that minikube can talk to other network adapters and can register the port, I am not sure how.我知道它可以作为 minikube 仪表板实现,默认情况下在 localhost 上公开服务,这意味着 minikube 可以与其他网络适配器通信并可以注册端口,我不确定如何。

Here is my service yaml:这是我的服务 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

You have to create ingress.您必须创建入口。 Follow the steps in this doc - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/按照本文档中的步骤进行操作 - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/

@subudear is right - you need Ingress . @subudear 是对的 - 你需要Ingress

An API object that manages external access to the services in a cluster, typically HTTP.管理对集群中服务的外部访问的 API object,通常是 HTTP。 Ingress may provide load balancing, SSL termination and name-based virtual hosting. Ingress 可以提供负载平衡、SSL 终止和基于名称的虚拟主机。

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Ingress 将 HTTP 和 HTTPS 路由从集群外部公开到集群内的服务。 Traffic routing is controlled by rules defined on the Ingress resource.流量路由由 Ingress 资源上定义的规则控制。

在此处输入图像描述

To be able use regularly use ingress(Im not talking about minikube right now) - it is not enough simply create Ingress object.为了能够经常使用 ingress(我现在不是在谈论minikube )——仅仅创建Ingress object 是不够的。 You should first install related ingress controller .您应该首先安装相关的入口 controller

There are lot of them, most popular are:它们有很多,最受欢迎的是:

First 2 are very similar, but use absolutely different annotations.前 2 个非常相似,但使用完全不同的注释。 It often happens people confuse them人们经常会混淆他们


Talking about minikube : As per guidelines , in order to install ingress the only you have to do is谈论minikube :根据指南,为了安装 ingress,你唯一需要做的就是

minikube addons enable ingress

Please note that by default, minikube installing exactly NGINX Ingress controller请注意,默认情况下, minikube完全安装NGINX Ingress controller

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM