[英]How to make an HTTP request from a K8 pod to a NodePort service in the same cluster
I need for a service in a K8 pod to be able to make HTTP calls to downstream services, load balanced by a NodePort, within the same cluster and namespace. 我需要在K8 pod中提供服务,以便能够在相同的集群和命名空间内对下游服务进行HTTP调用,由NodePort进行负载平衡。
My constraints are these: 我的约束是:
Is this possible, and, if so, how? 这是可能的,如果是的话,怎么样?
It probably can be done but it will not be straight forward and you might have to add some custom automation. 它可能已经完成,但它不会直截了当,您可能需要添加一些自定义自动化。 A NodePort
service is meant to be used by an entity outside your cluster. NodePort
服务旨在由群集外的实体使用。
For inter-cluster communication, a regular service (with a ClusterIP) will work as designed. 对于群集间通信,常规服务(使用ClusterIP)将按设计工作。 Your service can reach another service using DNS service discovery . 您的服务可以使用DNS服务发现到达其他服务。 For example. 例如。 svc-name.mynamespace.svc.cluster.local
would be the DNS entry for a svc-name
in the mynamespace
namespace. svc-name.mynamespace.svc.cluster.local
将是mynamespace
命名空间中svc-name
的DNS条目。
If you can only do a NodePort
which essentially is a port on your K8s nodes, you could create another Deployment or Pod of something like nginx or haproxy . 如果你只能做一个NodePort
基本上是你的K8S节点的端口,你可以创建另一个部署的类似或吊舱的nginx或HAProxy的 。 Then have this deployment being serviced by regular K8s service with a ClusterIP. 然后使用ClusterIP通过常规K8s服务为此部署提供服务。 Then have nginx or haproxy point to the NodePort on all your nodes in your Kubernetes cluster. 然后让nginx或haproxy指向Kubernetes集群中所有节点上的NodePort。 Also, have it configured so that it only forwards to listening NodePorts with some kind of healthcheck. 此外,配置它以便它只通过某种健康检查转发到监听NodePorts。
The above seems like an extra necessary step, but if NodePort from within the cluster is what you need (for some reason), it should do the trick. 上面看起来似乎是一个额外的必要步骤,但如果集群内的NodePort是您需要的(出于某种原因),它应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.