<p>Need some serious help here ! Thanks in advance.</p>
<p>I am trying to deploy a microservice based Java application. I am able to get to the frontend service(webapp) on my browser, but I am unable to connect it with the backend (auth service) and hence it shows authentication failure.</p>
<p><strong>HTML LOGIN FORM form points to &quot;/login?referrerURL=&quot;</strong></p>
<p>I checked the ingress nginx logs :</p>
<pre><code>Service &quot;default/auth-srv&quot; does not have any active Endpoint.
Service &quot;default/voice-srv&quot; does not have any active Endpoint.
Service &quot;default/reporting-srv&quot; does not have any active Endpoint.
Service &quot;default/webapp-srv&quot; does not have any active Endpoint.
</code></pre>
<p>The ingress nginx config file:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    name: ingress-service
    annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
    rules:
        - host: &lt;domain_name&gt;
          http:
            paths:
                - path: /auth/?(.*)
                  backend:
                    serviceName: auth-srv
                    servicePort: 8080
                - path: /emotion/?(.*)
                  backend:
                    serviceName: emotion-srv
                    servicePort: 8080
                - path: /storage/?(.*)
                  backend:
                    serviceName: storage-srv
                    servicePort: 8080
                - path: /voice/?(.*)
                  backend:
                    serviceName: voice-srv
                    servicePort: 8080
                - path: /backend/?(.*)
                  backend:
                    serviceName: backend-srv
                    servicePort: 8080
                - path: /reporting/?(.*)
                  backend:
                    serviceName: reporting-srv
                    servicePort: 8080
                ## frontend
                - path: /?(.*)
                  backend:
                    serviceName: webapp-srv
                    servicePort: 8080

</code></pre>
<blockquote>
<p>How is the webapp(frontend) connecting to auth service internally?</p>
</blockquote>
<p><em>Using the below endpoint</em></p>
<pre><code>http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/auth
</code></pre>
<p><em>Above endpoint obtained from:</em>
<em>Using the pattern</em> === <a href="http://name-of-service.namespace.svc.cluster.local" rel="nofollow noreferrer">http://name-of-service.namespace.svc.cluster.local</a></p>
<blockquote>
<p>namespaces :</p>
</blockquote>
<pre><code>$ kubectl get namespace
NAME              STATUS   AGE
default           Active   10h
ingress-nginx     Active   10h
kube-node-lease   Active   10h
kube-public       Active   10h
kube-system       Active   10h

$ kubectl get service -n ingress-nginx
NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP                                                                     PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.100.99.130    &lt;loadbalancer&gt;.amazonaws.com   80:32794/TCP,443:30053/TCP   10h
ingress-nginx-controller-admission   ClusterIP      10.100.230.126   &lt;none&gt;                                                                          443/TCP 
</code></pre>
<blockquote>
<p>Webapp (frontend) pod logs :</p>
</blockquote>
<pre><code>2020-07-28 20:57:08.139  INFO 1 --- [io-8080-exec-10] com.symtrain.controller.AdminController  : Auth Controller User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
2020-07-28 20:57:08.139  INFO 1 --- [io-8080-exec-10] com.symtrain.controller.AdminController  : Auth Controller URL: http://testprod.symtrain.com/index
2020-07-28 20:57:08.139  INFO 1 --- [io-8080-exec-10] com.symtrain.controller.AdminController  : Auth Controller flag:::::: Not IE
2020-07-28 20:57:08.139  INFO 1 --- [io-8080-exec-10] com.symtrain.controller.AdminController  : Auth Controller URL inside normal return:

</code></pre>
<p>Some extra information for deployments :</p>
<pre><code>$ kubectl get deploy
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
auth-depl        2/2     2            2           4h40m
backend-depl     2/2     2            2           4h40m
emotion-depl     2/2     2            2           4h40m
reporting-depl   2/2     2            2           4h40m
storage-depl     2/2     2            2           4h40m
voice-depl       2/2     2            2           4h40m
webapp-depl      2/2     2            2           4h40m


$ kubectl get svc
NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
auth-srv        ClusterIP   10.100.258.118   &lt;none&gt;        8080/TCP   4h41m
backend-srv     ClusterIP   10.100.132.251   &lt;none&gt;        8080/TCP   4h41m
emotion-srv     ClusterIP   10.100.32.154    &lt;none&gt;        8080/TCP   4h41m
kubernetes      ClusterIP   10.100.0.1       &lt;none&gt;        443/TCP    10h
reporting-srv   ClusterIP   10.100.64.80     &lt;none&gt;        8080/TCP   4h41m
storage-srv     ClusterIP   10.100.36.25     &lt;none&gt;        8080/TCP   4h41m
voice-srv       ClusterIP   10.100.212.180   &lt;none&gt;        8080/TCP   4h41m
webapp-srv      ClusterIP   10.100.21.170    &lt;none&gt;        8080/TCP   4h41m


</code></pre>
<blockquote>
<p>Endpoints</p>
</blockquote>
<pre><code>kubectl get endpoints
NAME            ENDPOINTS                                 AGE
auth-srv        192.168.14.60:8080,192.168.44.116:8080    4h53m
backend-srv     192.168.32.14:8080,192.168.37.180:8080    4h53m
emotion-srv     192.168.58.110:8080,192.168.6.148:8080    4h53m
kubernetes      192.168.118.66:443,192.168.82.184:443     10h
reporting-srv   192.168.31.233:8080,192.168.33.218:8080   4h53m
storage-srv     192.168.23.217:8080,192.168.38.48:8080    4h53m
voice-srv       192.168.4.211:8080,192.168.59.186:8080    4h53m
webapp-srv      192.168.31.164:8080,192.168.62.143:8080   4h53m

</code></pre>
<blockquote>
<p>Auth backend Deployment and Service :</p>
</blockquote>
<pre><code>$ kubectl describe deploy auth-depl
Name:                   auth-depl
Namespace:              default
CreationTimestamp:      Tue, 28 Jul 2020 16:32:44 +0000
Labels:                 &lt;none&gt;
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=auth
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=auth
  Containers:
   auth:
    Image:        &lt;my_image_name&gt;
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  &lt;none&gt;
    Mounts:       &lt;none&gt;
  Volumes:        &lt;none&gt;
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  &lt;none&gt;
NewReplicaSet:   auth-depl-787446c4db (2/2 replicas created)
Events:          &lt;none&gt;


#####################################

$ kubectl describe svc auth-srv
Name:              auth-srv
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=auth
Type:              ClusterIP
IP:                10.100.218.108
Port:              auth  8080/TCP
TargetPort:        8080/TCP
Endpoints:         192.168.14.60:8080,192.178.44.136:8080
Session Affinity:  None
Events:            &lt;none&gt;


</code></pre>
<p>NOTE: <em>I am altering the IPs here for security purposes</em>.</p>

Karan Kumar
<p>As per the error messages, it could be that the labels you are using inside of the Service may be a cause for concern. Your service will lookup pods based on their pod labels.</p>
<ol>
<li>Fetch the labels of pods of your deployments, example below (app: nginx).</li>
</ol>
<p><code>kubectl get pods --show-labels</code></p>
<pre><code>nginx     1/1       Running   0          16m      app=nginx
</code></pre>
<ol start="2">
<li>Edit you service yaml to match the labels of pods in your deployment, ensure they are pod labels.</li>
</ol>
<pre><code>    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
</code></pre>
<ol start="3">
<li>test if you are able to use the Service, spin a temporary busy box pod with the same labels (app:nginx) and test using wget.</li>
</ol>
<p><code>Kubectl run bb --image=busybox - it - - wget - o- auth-serv:8080 </code></p>
<ul>
<li>If the above does not solve your problem, you may also need to ensure that the containerPort defined inside of your deployment is matching with the service port you are exposing (8080 in your case)</li>
</ul>
<p>controllers/nginx-deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 8080
</code></pre>
<p>if the above does not resolve the problem, then you might want to look at policies. Maybe, you could create a new ingress network policy policy based on your pod labels to ensure that traffic hits your pods. (<a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/network-policies/</a>)</p>
