<p>I installed kubernete in several raspberry pi 4 without using cloud.
I follow tutorial to deploy mongodb and mongo express and I can
get inside the mongo express website using node port mode.
However, when I change to use nignx controller, it works when I
type ip address:port  (192.168.1.194:30574 It is my master node ip and the port is where the ingress-nginx-controller expose) or domain:port (mymongo.com:30574).
But if I just use domain name (mymongo.com) without port, it cannot get inside the website. Do I miss something? Thank you!
Here is my yaml</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: 
  name: mongo-express-ingress
spec:
  rules:
   - host: &quot;mymongo.com&quot;
   - http:
      paths:
      - pathType: Prefix
        path: &quot;/&quot;
        backend:
          service:
            name: mongo-express-service
            port:
              number: 8081
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
        - name: mongo-express
          image: mongo-express
          ports:
            - containerPort: 8081
          env:
            - name: ME_CONFIG_MONGODB_ADMINUSERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-username
            - name: ME_CONFIG_MONGODB_ADMINPASSWORD 
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-password
            - name: ME_CONFIG_MONGODB_SERVER
              valueFrom:
                configMapKeyRef:
                  name: mongodb-configmap
                  key: database_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
spec:
  selector:
    app: mongo-express
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081

</code></pre>
<pre><code>ubuntu@master:~/k8s-config$ kubectl get services --all-namespaces
NAMESPACE              NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
default                kubernetes                           ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP                      8d
default                mongo-express-service                ClusterIP   10.107.95.131   &lt;none&gt;        8081/TCP                     6d19h
default                mongodb-service                      ClusterIP   10.101.118.57   &lt;none&gt;        27017/TCP                    6d19h
ingress-nginx          ingress-nginx-controller             NodePort    10.96.94.30     &lt;none&gt;        80:30574/TCP,443:31882/TCP   6d4h
ingress-nginx          ingress-nginx-controller-admission   ClusterIP   10.104.121.41   &lt;none&gt;        443/TCP                      6d4h
kube-system            kube-dns                             ClusterIP   10.96.0.10      &lt;none&gt;        53/UDP,53/TCP,9153/TCP       8d
kubernetes-dashboard   dashboard-metrics-scraper            ClusterIP   10.99.4.159     &lt;none&gt;        8000/TCP                     6d22h
kubernetes-dashboard   kubernetes-dashboard                 NodePort    10.98.92.238    &lt;none&gt;        443:31044/TCP             
</code></pre>

benben520
<p>In your current configuration, it works as expected.</p>
<p>Your <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">Nginx Ingress Controller</a> is configured as <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">NodePort Type</a></p>
<blockquote>
<p><strong>NodePort:</strong> Exposes the <code>Service</code> on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the <code>NodePort Service</code>, from outside the cluster, by requesting <strong>:</strong>.</p>
</blockquote>
<p>So if you are using <code>NodePort</code> type, you will be able to connect only when you will specify &lt;<strong>NodeIP:NodePort</strong>&gt;, in your case <code>mymongo.com:30574</code> (<code>NodeIP</code>: mymongo.com, <code>NodePort</code>: 30574).</p>
<p>If you would like to use only a domain, you would need to consider <code>ServiceType</code> as <code>LoadBalancer</code>.</p>
<blockquote>
<p><strong>LoadBalancer:</strong> Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.</p>
</blockquote>
<p><strong>To achieve that without using <code>Cloud LoadBalancer</code> you can use</strong> <a href="https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#a-pure-software-solution-metallb" rel="nofollow noreferrer">MetalLB solution</a>.</p>
<p><strong>Your current configuration</strong> is also described in <code>Nginx Ingress Documentation</code> as <a href="https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#over-a-nodeport-service" rel="nofollow noreferrer">Over a NodePort Service</a>.</p>
<p><strong>You can also consider using</strong> <a href="https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#via-the-host-network" rel="nofollow noreferrer">host network solution</a> as alternative for <code>baremaetal solution</code>.</p>
<blockquote>
<p>In a setup where there is no external load balancer available but using NodePorts is not an option, one can configure ingress-nginx Pods to use the network of the host they run on instead of a dedicated network namespace. The benefit of this approach is that the NGINX Ingress controller can bind ports 80 and 443 directly to Kubernetes nodes' network interfaces, without the extra network translation imposed by NodePort Services.</p>
</blockquote>
<pre><code>template:
  spec:
    hostNetwork: true
</code></pre>
