试图在Kubernetes Bare Metal上使用nginx入口控制器公开纯TCP



我目前正在学习kubernetes库,我想在集群之外公开一个mongodb。我已经设置了我的nginx入口控制器,并遵循此文档来公开纯TCP连接。

这是我的入口服务配置:

apiVersion: v1
kind: Service
metadata:
annotations:
labels:
helm.sh/chart: ingress-nginx-4.0.15
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 1.1.1
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
type: NodePort
ipFamilyPolicy: SingleStack
externalIPs:
- 172.30.63.51
ipFamilies:
- IPv4
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
appProtocol: http
- name: https
port: 443
protocol: TCP
targetPort: https
appProtocol: https
- name: proxied-tcp-27017
port: 27017
protocol: TCP
targetPort: 27017
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/component: controller

代理TCP连接的配置映射:

apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
27017: "global-stack/global-stack-mongo-svc:27017"

我的入口控制器在端口80和443上运行良好,以暴露我的服务,但我无法访问端口27017

kubectl获取svc-n入口nginx:的结果

NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP    PORT(S)                                
ingress-nginx-controller             NodePort    10.97.149.93    172.30.63.51   80:30159/TCP,443:32585/TCP,27017:30098/TCP
ingress-nginx-controller-admission   ClusterIP   10.107.33.165   <none>         443/TCP                                  

外部IP对curl 172.30.63.51:80 反应良好

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

但无法响应端口27017:

curl: (7) Failed to connect to 172.30.63.51 port 27017: Connection refused

我的mongo服务:

apiVersion: v1
kind: Service
metadata:
name: global-stack-mongo-svc
namespace: global-stack
labels:
app: global-stack-mongo-app
spec:
type: ClusterIP
ports:
- name: http
port: 27017
protocol: TCP
targetPort: 27017
selector:    
app: global-stack-mongo-app

服务的集群IP为10.244.1.57,响应良好

>> curl 10.244.1.57:27017
It looks like you are trying to access MongoDB over HTTP on the native driver port.

如果有人能帮助我,我将不胜感激。感谢

吉姆。

经过一些研究,我解决了我的问题。

在nginxingress文档中,没有对其进行描述,但您需要将带有ingress控制器容器的TCP配置映射映射到部署文件中:

args:
- /nginx-ingress-controller
- --election-id=ingress-controller-leader
- --controller-class=k8s.io/ingress-nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
- --tcp-services-configmap=ingress-nginx/tcp-services

相关内容

  • 没有找到相关文章

最新更新