本文介绍了使用Nginx-Ingress在Kubernetes中将TCP端口暴露出集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我已经使用Kubernetes在Google云上设置了我的应用程序.我有一个Pod,我想将其暴露在期望TCP请求的群集之外.

So I have setup my application on Google cloud using Kubernetes. I have a Pod which I want to expose out of the cluster that expects TCP requests.

我知道可以通过 ingress-nginx 并对此进行了研究.如在此处提供文档,可以通过设置如下的configMap来完成:

I came to know that this is possible via ingress-nginx and researched about it. As mentioned in the docs here, it can be done by setting up a configMap like below:

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-configmap-example
data:
  9000: "default/my-service-name:7051

,但是它的完整用法没有明确描述,我也无法在文档中找到完整的示例.

, but it's full usage is not clearly described nor I could find a complete example in the docs properly.

我已经按照安装指南所述安装了ingress-nginx我不确定下一步要暴露我的Pod.

I have installed ingress-nginx as mentioned in the Installation Guide but I am unsure what the next steps are to expose my Pod.

其他信息

  • 我要从群集中公开的Pod中的端口是 7051
  • 我有一个针对我Pod端口的NodePort服务,该端口可与Ingress一起使用来公开.

推荐答案

因此,要实现此目的,您可以执行以下操作:

So, in order to achieve this you can do this:

  1. 首先创建您添加到帖子中的configMap.
apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-configmap-example
data:
  9000: "default/my-service-name:7051
  1. 然后通过将此标志添加到容器args中来编辑您的nginx-ingress-controller部署,如下所示:

  1. Then edit your nginx-ingress-controller deployment by adding this flag to container args like below:

...
containers:
- name: nginx-ingress-controller
  image: "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.26.1"
  imagePullPolicy: "IfNotPresent"
  args:
    - /nginx-ingress-controller
    - --default-backend-service=nginx-ingress/nginx-ingress-default-backend
    - --election-id=ingress-controller-leader
    - --ingress-class=nginx
    - --configmap=nginx-ingress/nginx-ingress-controller
    - --tcp-services-configmap=default/tcp-configmap-example
    ...

  • 通过向您的LoadBalancer添加端口来编辑LoadBalancer服务

  • Edit LoadBalancer service by adding port to your LoadBalancer

    ...
    ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
    - name: some-service-port
      port: 7051
      protocol: TCP
    

  • 希望有帮助!

    这篇关于使用Nginx-Ingress在Kubernetes中将TCP端口暴露出集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-01 22:05