0

I have an Angular app running on Nginx deployed along with Spring Boot rest service. When I launch docker containers locally everything works fine so my only guess is that something wrong with Kubernetes configuration.

I receive this error in Chrome console with IP address provided Failed to load resource: net::ERR_CONNECTION_TIMED_OUT However, with DNS name I get: Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Strangely, I am able to curl my service from radial/busyboxplus:curl pod but I cannot ping my service from my front pod (don't have a curl in build).

I am accessing front through ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: main-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: front
              servicePort: 80

My frontend:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-adviser-front-deployment
  labels:
    app: angular-front
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      name: product-adviser-front-deployment
  template:
    metadata:
      labels:
        name: product-adviser-front-deployment
    spec:
      containers:
        - name: product-adviser-front-app
          image: aurrix/seb:product-adviser-front
          imagePullPolicy: Always
          ports:
            - containerPort: 80
          env:
            - name: API_URL
              value: http://back.default.svc.cluster.local/
          readinessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /healthz
              port: 80
          livenessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /healthz
              port: 80
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: front
spec:
  selector:
    name: product-adviser-front-deployment
  ports:
    - port: 80
  type: NodePort

My backend:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-adviser-back-deployment
  labels:
    app: backend-service
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      name: product-adviser-back-deployment
  template:
    metadata:
      labels:
        name: product-adviser-back-deployment
    spec:
      containers:
        - name: product-adviser-back-deployment
          image: aurrix/seb:product-adviser
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          readinessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /actuator/health
              port: 8080
          livenessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /actuator/health
              port: 8080
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: back
spec:
  selector:
    name: product-adviser-back-deployment
  ports:
    - port: 80
      targetPort: 8080
Alisher
  • 480
  • 5
  • 16
  • What address is the browser application trying to connect to? Remember that the Angular application actually runs in the browser, and the browser knows nothing about Kubernetes. – David Maze Apr 09 '20 at 09:57
  • It seems to be fine in this case too, I see below: ```http://back.default.svc.cluster.local/products```and respective error ```Failed to load resource: net::ERR_NAME_NOT_RESOLVED ``` – Alisher Apr 09 '20 at 10:08
  • Your browser can't reach that URL. It'd have to be something exposed through your Ingress. – David Maze Apr 09 '20 at 10:10
  • Do a ```kubectl get svc ``` to get the external ip of your application. – Chris Apr 09 '20 at 10:27
  • @DavidMaze Ok, that actually makes sense. Can you post that answer? – Alisher Apr 09 '20 at 10:31
  • On which platform your k8s running ? is it local, cloud ? please share more details as well as the configuration of the cni plugin – Mickey Hovel Apr 09 '20 at 11:09
  • It runs on Google Cloud. I resolved the problem as per @DavidMaze suggestion. – Alisher Apr 09 '20 at 17:48

1 Answers1

3

You have set value: http://back.default.svc.cluster.local/ as env, are you calling this endpoint for backend service from your front-end app? If so, this will not work as frontend application runs on browser and it is the browser that will make the API call. In this case you will have to add another rule in the ingress and route the requests to backend pod.

I also noticed the frontend service is set to nodePort and from ingress you are calling the service directly. You may want to set the service to cluster-IP(default) like the backend service.

Naveen Kulkarni
  • 633
  • 6
  • 16