简体   繁体   English

如何在 Kubernetes 中配置 ingress-nginx?

[英]How to configure ingress-nginx in Kubernetes?

I am testing a Kubernetes cluster version 1.11 and need to make POD to be accessed externally by the master server IP and by the POD port (in this case an nginx image through port 80) and I am trying to enable and configure ingress-nginx to get this access.我正在测试 Kubernetes 集群 1.11 版,需要使主服务器 IP 和 POD 端口(在本例中为通过端口 80 的 nginx 映像)从外部访问 POD,我正在尝试启用和配置 ingress-nginx获得此访问权限。

To run the tests, I added ingress-nginx to the cluster with the command:为了运行测试,我使用以下命令将 ingress-nginx 添加到集群中:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml

Then I tried to create an ingress as described in this example: https://koudingspawn.de/install-kubernetes-ingress/ - I just did not do the LoadBalancer portion of Digital Ocean.然后我尝试按照本示例中的描述创建一个入口: https : //koudingspawn.de/install-kubernetes-ingress/ - 我只是没有做 Digital Ocean 的 LoadBalancer 部分。

It happened that it did not work, I could not access the IP or host configured and because of this, I was in doubt if I made the right addition of ingress-nginx in the cluster, if the example has a failure or if I have to follow another path?碰巧它不起作用,我无法访问配置的 IP 或主机,因此,我怀疑我是否在集群中正确添加了 ingress-nginx,如果示例失败或者我有走另一条路?

Neither of the canonical approaches will give you exactly what you want here.两种规范方法都不会给你你想要的东西。

The typical solution involves either using LoadBalancer service type or NodePort and manualy configuring your network LB to point to the ports of the NodePort service.典型的解决方案包括使用 LoadBalancer 服务类型或 NodePort 并手动配置您的网络 LB 以指向 NodePort 服务的端口。

I will make 3 assumptions here :我将在这里做出 3 个假设:

  • you have no LB service available so you want to connect with HTTP(S) to the IP of your master您没有可用的 LB 服务,因此您想使用 HTTP(S) 连接到您的主站的 IP
  • your master hosts kube api on port like 6443, or anything else but 80/443 that you want to use for web traffic您的 master 在 6443 等端口上托管 kube api,或者您想用于网络流量的 80/443 以外的任何其他端口
  • you are talking about single master and using it for the traffic.您正在谈论单个主并将其用于流量。 It's an obvious SPOF, so I assume you do not care about HA that much这是一个明显的 SPOF,所以我假设你不太关心 HA

With that in mind, you need to adapt your ingress deployment to fit your needs.考虑到这一点,您需要调整您的入口部署以满足您的需求。

Nginx ingress, within it's network namespace, listens on standard ports (80/443). Nginx 入口在其网络命名空间内侦听标准端口 (80/443)。 If, instead of exposing it with a Service , you run tham with hostNetwork: true , you will see the ingress listening directly on 80/443.如果不是使用Service公开它,而是使用hostNetwork: true运行hostNetwork: true ,您将看到直接在 80/443 上侦听的入口。 To be certain it's running on your master, you need to allow it to be scheduled on master (probably via tolerations) and make sure it is scheduled on master and not some other node (nodeSelector/NodeAffinity or DaemonSet to run it on ~every node in cluster)为了确定它在你的主节点上运行,你需要允许它在主节点上调度(可能通过容忍)并确保它被调度在主节点上而不是其他节点(nodeSelector/NodeAffinity 或 DaemonSet 在 ~每个节点上运行它在集群中)

Another solution can be to actually go the canonical way and have the ingress listening on some nodeports, and then have another piece of software act as loadbalancer deployed to master either by means of kube ( hostNetwork ) or by completely autonomous mechanism (ie. as systemd service unit), that would listen on 80/443 and tcp forward the traffic to the nodeports.另一种解决方案可以是实际采用规范方式并让入口监听某些节点端口,然后让另一块软件充当负载均衡器,通过 kube( hostNetwork )或完全自主的机制(即作为 systemd服务单元),它将侦听 80/443 并将流量转发到节点端口。

I'm not sure what errors you are seeing, and it would be helpful to post them, but starting with this is correct:我不确定您看到了什么错误,发布它们会有所帮助,但从这里开始是正确的:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml

as described in the main documentation page for the nginx ingress controller.如 nginx 入口控制器的主文档页面中所述。 If you are using Digital Ocean you can just follow the NodePort/Bare-metal instructions as there's no support for Digital Ocean load balancers yet.如果您使用的是 Digital Ocean,您只需按照NodePort/Bare-metal 说明进行操作,因为目前尚不支持 Digital Ocean 负载均衡器。

After that, you want to check that your nginx ingress controller is running:之后,您要检查您的 nginx 入口控制器是否正在运行:

$ kubectl -n ingress-nginx get pods
NAME                                        READY     STATUS    RESTARTS   AGE
default-http-backend-xxxxxxxxxx-xxxxx       1/1       Running   0          1h
nginx-ingress-controller-xxxxxxxxxx-xxxxx   1/1       Running   0          1h

You can also check the logs:您还可以查看日志:

$ kubectl -n ingress-nginx nginx-ingress-controller-xxxxxxxxxx-xxxxx

Then later you can create an Ingress and a Service that services that Ingress.然后,您可以创建一个Ingress和一个服务于该 Ingress 的服务。

Then you can create whatever deployments and services that use that Ingress using the kubernetes.io/ingress.class: "nginx" annotation.然后,您可以使用kubernetes.io/ingress.class: "nginx"注释创建使用该 Ingress 的任何部署和服务。

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

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