<p>I am creating a micro services infrastructure with Kubernetes. I have two services, an authentication module and client service. The client service make some requests to authentication module in order to get information about the user, the authentication cookie and etc. etc. etc.</p>
<p>This is the infraestructure:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: theimage
          env:
            - name: JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: jwt-secret
                  key: JWT_KEY
          resources:
            limits:
              cpu: &quot;1&quot;
              memory: &quot;512Mi&quot;
            requests:
              cpu: &quot;1&quot;
              memory: &quot;512Mi&quot;
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>
<p>Apparently working properly. Then, the client module:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
        - name: client
          image: theimage
---
apiVersion: v1
kind: Service
metadata:
  name: client-srv
spec:
  selector:
    app: client
  ports:
    - name: client
      protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>
<p>In order to maintain API consistency, I am using nginx-ingress. It seems to work perfectly and here is the configuration:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  rules:
    - host: kome.dev
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: client-srv
                port:
                  number: 3000
</code></pre>
<p>The problem is that my client, written in nextjs, has to make a request to a specific route of the authentication module:</p>
<pre><code>Index.getInitialProps = async () =&gt; {
 if (typeof window === 'undefined') {
    // server side
    const response = await axios.get('http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser')
    return response
 } else {
    // client side
    const response = await axios.get('/api/users/currentuser')
    return response
 }
}
</code></pre>
<p>is getting a 404 error, but the endpoint exists and works fine outside of ingress-nginx.</p>

Diesan Romero
<p>You can keep the <code>- host: kome.dev</code>, your axios call can include the header like:</p>
<pre><code>await axios.get('...', {
  headers: {
    'Host': 'kome.dev'
  }
})
</code></pre>
