OpenShift :: 我们如何在自定义端口(非 Web/非 http)上启用进入 pod 的流量 [英] OpenShift :: How do we enable traffic into pod on a custom port (non-web / non-http)

查看:94
本文介绍了OpenShift :: 我们如何在自定义端口(非 Web/非 http)上启用进入 pod 的流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在自定义端口(非网络/非 http)上启用进入 pod 的流量.

How do we enable traffic into pod on a custom port (non-web / non-http).

例如考虑端口 12121.

For example consider the port 12121.

我尝试通过路由公开端口.但无法从同一命名空间内的另一个 Pod 访问此 Pod.

I tried exposing the port through route. But could not reach this pod from another pod within the same namespace.

OpenShift 支持此功能吗?

Is this feature supported in OpenShift ?

如果有人以前尝试过,请分享您是如何做到这一点的.

If anybody has tried this before, please share how you managed to achieve this.

谢谢.

推荐答案

根据您要实现的目标,您有几个选择,但我不会为此使用 Route.

You have a few options depending on what you are trying to achieve but I wouldn't use a Route for this.

  • 如果您不关心端口号是什么,那么您可以使用 NodePort 服务.NodePorts 是由集群管理员定义的一系列端口(默认为 30000-32767),可以分配给服务并在集群中的每个节点上公开,它适用于 TCP 和 UDP 流量.此示例指定要使用的 NodePort,但如果您不提供,服务控制器将分配一个可用的.
  • If you do not care about what the port number is then you can use a NodePort service. NodePorts are a range of ports defined by the cluster administrator (default is 30000-32767) that can be assigned to a service and are exposed on every node in the cluster and it works for TCP and UDP traffic. This example specifies a NodePort to use but if you do not give one, the service controller will assign one that is available.
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  type: NodePort
  ports:
    - port: 3306
      nodePort: 30306
      name: http
  selector:
    name: mysql

OpenShift 文档:https://docs.openshift.com/container-platform/3.11/dev_guide/expose_service/expose_internal_ip_nodeport.html

OpenShift documentation: https://docs.openshift.com/container-platform/3.11/dev_guide/expose_service/expose_internal_ip_nodeport.html

如果您需要公开特定端口,那么您可以:

If you need to expose a specific port then you can:

  • 使用 LoadBalancer 服务,它允许您在负载均衡器 IP 上公开端口.请注意,这需要使用可以使用的 IP 列表设置集群(这是主服务器上的配置),并且 IP 被路由到集群中的节点(这可以通过 OpenShift 的 ipfailover 自动化实现).
  • Use a LoadBalancer service which will allow you to expose a port on the load balancer IP. Note that this requires the cluster being set up with a list of IPs that can be used (this is configuration on the master) AND the IPs are routed to nodes in the cluster (this can be achieved with OpenShift's ipfailover automation).
apiVersion: v1
kind: Service
metadata:
  name: egress-2 
spec:
  ports:
  - name: db
    port: 3306 
  loadBalancerIP:
  type: LoadBalancer 
  selector:
    name: mysql 

OpenShift 文档:https://docs.openshift.com/container-platform/3.11/dev_guide/expose_service/expose_internal_ip_load_balancer.html

OpenShift documentation: https://docs.openshift.com/container-platform/3.11/dev_guide/expose_service/expose_internal_ip_load_balancer.html

  • 不太理想的情况是,您可以使用 hostport 并直接在运行 pod 的主机上公开端口,但这仅在您想将流量路由到没有流量平衡的主机时才有效.这种方法违背了最佳做法,但可以作为最后的手段.
  • Less ideally, you could use hostport and expose the port directly on the host that the pod is running on but this only works if you want to route traffic to the host with no traffic balancing. This method goes against best practices but can be used as a last resort.
apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
  - image: mysql
    name: mysql
    ports:
    - name: mysql
      containerPort: 3306
      hostPort: 3306

这篇关于OpenShift :: 我们如何在自定义端口(非 Web/非 http)上启用进入 pod 的流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆