简体   繁体   English

如何从K8 pod向同一群集中的NodePort服务发出HTTP请求

[英]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: 我的约束是:

  • I can do this only through manipulation of deployment and service entities (no ingress. I don't have that level of access to the cluster) 我只能通过操纵部署和服务实体来做到这一点(没有入口。我没有那种级别的集群访问权限)
  • I cannot add any K8 plugins 我无法添加任何K8插件
  • The port that the NodePort exposes must be randomized, not hard coded NodePort公开的端口必须是随机的,而不是硬编码的
  • This whole thing must be automated. 整个事情必须是自动化的。 I can't set the deployment with the literal value of the exposed port. 我无法使用公开端口的文字值设置部署。 It needs to be set by some sort of variable, or similar process. 它需要通过某种变量或类似过程来设置。

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节点的端口,你可以创建另一个部署的类似或吊舱的nginxHAProxy的 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.

相关问题 在 RPI 上运行的 K8 集群中无法访问 NGINX 节点端口服务 - Unable to access NGINX nodePort service in K8 cluster running on RPI 如果没有为定义为 NodePort 的 k8 服务定义 nodeport no 会发生什么? - What will happen if nodeport no is not define for k8 service which defined as NodePort? 如何创建 Pod 模板容器以部署在 K8 集群中 - How to create Pod template container to deploy in K8 cluster 如何使用nodeport服务类型在k8s环境下制作redis集群? - How to make a redis cluster in k8s environment using nodeport service type? 如何以编程方式将文件从 k8 pod 复制到 GCP 存储? - How to copy file from k8 pod to GCP storage programmatically? 负载分布:所有 HTTP 请求都被重定向到 k8 集群中的单个 pod - Load distribution: All HTTP requests are getting redirected to a single pod in a k8 cluster pod如何向k8s中的其他服务发出http请求 - How can pod make http request to other service in k8s k8s如何为nodePort服务设置固定的集群端口 - How set a fixed cluster port for nodePort service in k8s 如何通过Jenkins在k8集群中部署K8应用程序? - How to deploy K8 apps in k8 Cluster through Jenkins? K8 中服务内的 Envoy Pod 到 Pod 通信 - Envoy Pod to Pod communication within a Service in K8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM