<p>I am a newbie to this k8s ingress, please help.
Current problem is I am trying to use k8s to create mongo-express service which inturn will connect to MongoDB service. Now when I tried to expose mongo-express to an external service by setting <code>type: LoadBalancer</code> it quickly creates up an IP and I am able to access my db via it. But same when I am trying to do expose it to a domain name via ingress I am not getting assigned an address</p>
<p>Mongo DB Deployment :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-deployments
  labels:
    app: mongodb
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name:  mongodb
        image: mongo
        ports:
        - containerPort: 27017
        env:
          - name: MONGO_INITDB_ROOT_USERNAME
            valueFrom: 
              secretKeyRef:
                name: mongo-secrets
                key: mongo-root-username
          - name: MONGO_INITDB_ROOT_PASSWORD
            valueFrom: 
              configMapKeyRef:
                name: mongo-coi
                key: mongo-root-password
</code></pre>
<p>Mongo DB Service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
spec:
    selector:
      app: mongodb
    ports:
      - protocol: TCP
        port : 27017
        targetPort: 27017
</code></pre>
<p>Mongo express deployment :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express-deployments
  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: mongo-secrets
                key: mongo-root-username
          - name: ME_CONFIG_MONGODB_ADMINPASSWORD
            valueFrom: 
              secretKeyRef:
                name: mongo-secrets
                key: mongo-root-password
          - name: ME_CONFIG_MONGODB_SERVER 
            valueFrom: 
              configMapKeyRef:
                name: mongo-config-map
                key:  database-url

</code></pre>
<p>Mongo express service file</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
spec:
    selector:
      app: mongo-express
    # type: LoadBalancer
    ports:
      - protocol: TCP
        port : 8081
        targetPort: 8081
        # nodePort : 31313
</code></pre>
<p>mongo ingress file :</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mongo-express-dashboard
  namespace: default
  annotations:
    kubernetes.io/ingress.class: public
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: mongo-jainva.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: mongo-express-service
            port:
              number: 8081

</code></pre>
<p>I am attaching how my current k8s structure looks like :</p>
<pre><code>NAME                                            READY   STATUS    RESTARTS   AGE
pod/mongo-deployments-66764645fc-jpjf2          1/1     Running   0          3d2h
pod/mongo-express-deployments-976669559-l4s7h   1/1     Running   0          3d

NAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
service/kubernetes              ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP     40d
service/mongo-express-service   ClusterIP   10.109.215.229   &lt;none&gt;        8081/TCP    3d
service/mongodb-service         ClusterIP   10.103.145.203   &lt;none&gt;        27017/TCP   3d2h

NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mongo-deployments           1/1     1            1           3d2h
deployment.apps/mongo-express-deployments   1/1     1            1           3d1h

NAME                                                   DESIRED   CURRENT   READY   AGE
replicaset.apps/mongo-deployments-66764645fc           1         1         1       3d2h
replicaset.apps/mongo-express-deployments-59f9544cf7   0         0         0       3d1h
replicaset.apps/mongo-express-deployments-854b7f8b86   0         0         0       3d
replicaset.apps/mongo-express-deployments-976669559    1         1         1       3d
</code></pre>
<p>Attaching current ingress status</p>
<pre><code>NAME                      CLASS    HOSTS              ADDRESS   PORTS   AGE
mongo-express-dashboard   &lt;none&gt;   mongo-jainva.com             80      33m
</code></pre>
<p>And also sharing description of ingres file</p>
<pre><code>Name:             mongo-express-dashboard
Labels:           &lt;none&gt;
Namespace:        default
Address:
Ingress Class:    &lt;none&gt;
Default backend:  &lt;default&gt;
Rules:
  Host              Path  Backends
  ----              ----  --------
  mongo-jainva.com
                    /   mongo-express-service:8081 (172.17.0.4:8081)
Annotations:        kubernetes.io/ingress.class: public
                    nginx.ingress.kubernetes.io/rewrite-target: /
Events:             &lt;none&gt;
</code></pre>
<p><strong>NOTE</strong> - I have already tried mentioned IP <code>172.17.0.4:8081</code> its not working and also I am not able to understand what IP address it is specifying</p>

Vaibhav Jain
<p>Thank you guys whosoever responded, I have figured out the problem
Problem is that in ingress file I have mentioned 2 ingress classes somehow the first one <code>kubernetes.io/ingress.class: public</code> is creating a problem after removing it I was able to see the address</p>
<p>For now, I am closing this question but still I have one question if anyone can kindly answer
When I use below showned ingress-controller to route my mongo-express in ingress file I see all JS and other styling files are not coming with mongo-express due to which I could see mongo-express buttons but completely ruined UI</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /$1
</code></pre>
<p>But if I change the above code line to</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /
</code></pre>
<p>It gives me a clean and stable UI what does this <code>$1</code> specifies due to which I am seeing this behaviour</p>
