<p>I want to expose my two API service by ingress in one 80 port.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: my-api
spec:
  selector:
    app: my-api
  ports:
  - name: api1
    port: 3000
    targetPort: 3000
  - name: api2
    port: 4000
    targetPort: 4000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - hosts:
    - example.com
    secretName: app-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /my-api(/|$)(.*)
        backend:
          serviceName: my-api
          servicePort: 80
</code></pre>
<p>But when I try to reach the <code>https://example.com/my-api</code>, it always returns 503 status code.</p>

ccd
<p><code>servicePort: 80</code> doesn't mean that the nginx ingress is serving on port <code>80</code>. That's actually the port on your backend service, it sounds like you have 2 ports: <code>3000</code> and <code>4000</code>.</p>
<p>The nginx ingress controller by default serves on port <code>80</code> and if you have TLS enabled also or/and <code>443</code>. In your case, if you want to serve both APIs you can simply separate the paths.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - hosts:
    - example.com
    secretName: app-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /my-api1(/|$)(.*)
        backend:
          serviceName: my-api
          servicePort: 3000
      - path: /my-api2(/|$)(.*)
        backend:
          serviceName: my-api
          servicePort: 4000
</code></pre>
<p>✌️</p>
