首页 文章

使用nginx-Ingress在Kubernetes中将TCP端口暴露出群集

提问于
浏览
1

所以我使用Kubernetes在Google Cloud 上设置我的应用程序 . 我有一个Pod,我希望从需要TCP请求的群集中公开 .

我开始知道这可以通过ingress-nginx进行研究并进行研究 . 如docs here中所述,可以通过设置如下的configMap来完成:

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

,但它的完整用法没有明确描述,也没有在文档中找到一个完整的例子 .

我已经安装了_1110508中提到的ingress-nginx,但我不确定接下来的步骤是什么暴露我的Pod .

Extra Info

  • 我想要从群集中公开的Pod中的端口是 7051

  • 我有一个NodePort服务,它针对我的Pod端口,可以与Ingress一起使用来暴露 .

1 回答

  • 0

    在Google Cloud Platform中,您可以使用 type: LoadBalancer 在集群外部公开您的服务 . 你可以在这里看到例子Exposing Applications using Services .

    这是一个简单的例子:

    $ kubectl run hello --image=test/hello-world
    deployment "hello" created
    
    $ kubectl expose deployment hello --port=8080 --type=LoadBalancer
    service "hello" exposed
    
    $ kubectl get service 
    NAME         TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
    hello        LoadBalancer   10.11.251.34   35.192.25.112   8080:33107/TCP   2m
    
    $ curl 35.192.25.112:8080
    <html><head><title>hello world</title></head><body>hello world!</body></html>
    

    您也可以按照Kubernetes文档中的说明进行操作Exposing an External IP Address to Access an Application in a Cluster

相关问题