<p>The ingress I config to run with the controller ingress-nginx.</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - hosts:
    - XXX.XX.com
    secretName: app-tls
  rules:
  - host: XXX.XX.com
    http:
      paths:
      - path: /my-api(/|$)(.*)
        backend:
          serviceName: app
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-api
spec:
  selector:
    app: my-api
  ports:
  - name: app
    port: 3000
    targetPort: 3000

</code></pre>
<p>I can run the api locally <code>curl localIP:3000/testapi</code>, but it can not run remotely.</p>
<pre><code># kubectl describe ingress app-ingress
Name:             app-ingress
Namespace:        default
Address:          XX.XX.XX.XX
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
TLS:
  app-tls terminates www.daichenchen.cn
Rules:
  Host                Path  Backends
  ----                ----  --------
  XXX.XX.com
                      /my-api(/|$)(.*)   app:80 (&lt;error: endpoints &quot;app&quot; not found&gt;)
</code></pre>
<p>I already succeed install the ingress-nginx and all the pod work without error.</p>

<p>Your defined <code>serviceName</code> in <code>Ingress</code> rules and <code>Service</code> should be same.</p>
<p>Like this :</p>
<pre class="lang-yaml prettyprint-override"><code>...
  rules:
  - host: XXX.XX.com
    http:
      paths:
      - path: /my-api(/|$)(.*)
        backend:
          serviceName: app
          servicePort: 80
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  selector:
    app: my-api
  ports:
  - name: app
    port: 3000
    targetPort: 3000
</code></pre>
<p>If <code>Ingress</code> and the <code>Service</code> is in different namespace, you can also add the service name to the ingress rule. In this case you need to use dns name for service <code>&lt;service-name&gt;.&lt;namespace&gt;</code>.</p>
<p>For example:</p>
<pre class="lang-yaml prettyprint-override"><code>  rules:
  - host: example.com
    http:
      paths:
      - path: /my-api
        backend:
          serviceName: test-service.test-namespace
          servicePort: 80
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: test-namespace
</code></pre>
