<p>I am trying to create the following:</p>
<ol>
<li><code>Deployment</code> for mongo</li>
<li><code>Deployment</code> for mongo-express</li>
<li><code>ClusterIp</code> for mongo</li>
<li><code>ClusterIp</code> for mongo-express</li>
<li>An Ingress Service to route request to mongo-express</li>
</ol>
<p>I want to be able to go to <code>xyz.com/admin/auth-db-gui</code> and see the mongo-express gui.</p>
<p>I am running this on Linux minikube.</p>
<p>When going to <code>xyz.com/admin/auth-db-gui</code>, I get 503 Service Temporarily Unavailable, however when executing <code>kubectl get pods</code>, I can see 2 pods running.</p>
<p><em>I will setup the mapping for <code>xyz.com</code> in <code>/etc/hosts</code> manually as this is for only dev purpose</em></p>
<p>db.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-deployment
spec:
  selector:
    matchLabels:
      app: auth-db
  template:
    metadata:
      labels:
        app: auth-db
    spec:
      containers:
        - name: auth-db
          image: mongo
---
apiVersion: v1
kind: Service
metadata:
  name: auth-db-service
spec:
  selector:
    app: auth-db
  ports:
    - name: auth-db
      protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<p>db-gui</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-gui-deployment
spec:
  selector:
    matchLabels:
      app: auth-db-gui
  template:
    metadata:
      labels:
        app: auth-db-gui
    spec:
      containers:
        - name: auth-db-gui
          image: mongo-express
          env:
            - name: ME_CONFIG_MONGODB_SERVER
              value: auth-db-service
---
apiVersion: v1
kind: Service
metadata:
  name: auth-db-gui-service
spec:
  selector:
    app: auth-db-gui
  ports:
    - name: auth-db-gui
      protocol: TCP
      port: 27017
      targetPort: 27017
</code></pre>
<p>ingress.yaml</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: xyz-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /admin/auth-db-gui
            backend:
              serviceName: auth-db-gui-service
              servicePort: 8081
</code></pre>
<p><em>Sorry if there is an obvious mistake above.</em></p>

keemahs
<p>I notice that in <a href="https://serverfault.com/questions/868281/kubernetes-always-gives-503-service-temporarily-unavailable-with-multiple-tls-in">some cases</a> 503 means that ports on configured correctly.</p>
<p>I've tested your ingress, along with the service and the deployment and after correcting the mistake with port in the ingress object it works great:</p>
<pre class="lang-sh prettyprint-override"><code>curl -H &quot;Host:  xyz.com&quot;  &quot;192.168.49.2/admin/auth-db-gui&quot;   
{
  &quot;path&quot;: &quot;/admin/auth-db-gui&quot;,
  &quot;headers&quot;: {
    &quot;host&quot;: &quot;xyz.com&quot;,
    &quot;x-request-id&quot;: &quot;ff272df6d729af6c1fb4d5f510de88f4&quot;,
    &quot;x-real-ip&quot;: &quot;192.168.49.1&quot;,
    &quot;x-forwarded-for&quot;: &quot;192.168.49.1&quot;,
    &quot;x-forwarded-host&quot;: &quot;xyz.com&quot;,
    &quot;x-forwarded-port&quot;: &quot;80&quot;,
    &quot;x-forwarded-proto&quot;: &quot;http&quot;,
    &quot;x-scheme&quot;: &quot;http&quot;,
    &quot;user-agent&quot;: &quot;curl/7.52.1&quot;,
    &quot;accept&quot;: &quot;*/*&quot;
  },
  &quot;method&quot;: &quot;GET&quot;,
  &quot;body&quot;: &quot;&quot;,
  &quot;fresh&quot;: false,
  &quot;hostname&quot;: &quot;xyz.com&quot;,
  &quot;ip&quot;: &quot;192.168.49.1&quot;,
  &quot;os&quot;: {
    &quot;hostname&quot;: &quot;auth-db-gui-deployment-555c77cf75-fjbf2&quot;
</code></pre>
<p>For testing purposes I highly recommend <code>mendhak/http-https-echo</code>. I swapped the image in your deployed and fix the port. You can test the ingress yourself with the below yaml files:</p>
<pre class="lang-yaml prettyprint-override"><code>#ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: xyz-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /admin/auth-db-gui
            backend:
              serviceName: auth-db-gui-service
              servicePort: 27017
</code></pre>
<p>Notice the how the port are being set. The <code>servicePort</code> in ingress corresponds to service <code>port</code> which is 27017.  I changed the target port of the service since echo-server works on 80</p>
<pre class="lang-yaml prettyprint-override"><code>#sevice.yaml

apiVersion: v1
kind: Service
metadata:
  name: auth-db-gui-service
spec:
  selector:
    app: auth-db-gui
  ports:
    - name: auth-db-gui
      protocol: TCP
      port: 27017
      targetPort: 80
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>#deployment.yaml
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-gui-deployment
spec:
  selector:
    matchLabels:
      app: auth-db-gui
  template:
    metadata:
      labels:
        app: auth-db-gui
    spec:
      containers:
        - name: auth-db-gui
          image: mendhak/http-https-echo
</code></pre>
<p>Please have a look at the docs about <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">services</a> for more examples.</p>
