How access MongoDB in Kubernetes from outside the cluster
Ingress controllers are designed for HTTP connections, as the error hinted, the ingress is not the way to access mongodb.
None of the information in an ingress definition makes much sense for a plain TCP connection, host
names and http URL paths
don't apply to plain TCP connections.
Some ingress controllers (like nginx-ingress) can support plain TCP load balancers but not via an ingress definition. They use custom config maps.
Use a Service with type: loadBalancer
if your hosting environment supports it or type: nodePort
if not. There is an example in the stable mongodb helm chart and it's associated values.
apiVersion: v1kind: Servicemetadata: name: {{ template "mongodb.fullname" . }} labels: app: {{ template "mongodb.name" . }}spec: type: loadBalancer ports: - name: mongodb port: 27017 targetPort: mongodb - name: metrics port: 9216 targetPort: metrics