Kubernetes Ingress | could not resolve hostname

11/28/2019

I created a ingress cluster and a ingress service first and then to route a request to point to NodePort-serviceA (resources-service) and NodePort-serviceB (staffing-service) in a k8s-cluster, an ingress file (by name of staffing-ingress.yaml) is applied mentioned below.

Resources-service and Staffing-service can communicate with each other from inside the container and while hitting a curl command “curl –v http://staffing-service:8080/swagger/index.html” from resources container returns accurate result with HTTP 200 and vice versa. However if the incomplete URL is hit like this http://staffing-service:8080/, it throws a 404 error.

I have a doubt the way paths routing is done in the staffing-ingress.yaml file below. Any suggestions are welcome.

Here are the details

Accessing the services (staffing or resources) using nginx load balancer IP does not return the results and throw 404 error.

Curl –v http:// a5b9f45d4119a11eabbd90a9c35f3125-1159448980.us-east-2.elb.amazonaws.com:80/api/resources throws the below error
* TCP_NODELAY set
* Connected to a5b9f45d4119a11eabbd90a9c35f3125-1159448980.us-east-2.elb.amazonaws.com (3.134.165.38) port 80 (#0)

< HTTP/1.1 404 Not Found
< Server: openresty/1.15.8.2
< X-Response-Time-ms: 0

Staffing-Ingress.YAML

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: staffing-ingress
  namespace: default
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
    http:
      paths:
      - path: /api/resources
        backend:
          serviceName: resources-service
          servicePort: 8001
      - path: /api/staffing
        backend:
          serviceName: staffing-service
          servicePort: 8080

Expected result is that while hitting from ingress using external LB having URI‘/api/resources/’ it should call the api-service http://resources-service:8001/swagger/index.html.

-- Tarun Narang
kubernetes
kubernetes-ingress

2 Answers

11/28/2019

Ingress does not remove the context path!

So your call to www.xxx.yyy/api/resources/ before Ingress is not equal to www.xxx.yyy/ after ingress. The idea is that your backing service will also require to have the same context path.

The thing that you need to do is to add a context path to both services:

resources-service: www.xxx.yyy/api/resources/swagger/index.html
staffing-service: www.xxx.yyy/api/staffing/swagger/index.html
-- BogdanSucaciu
Source: StackOverflow

11/28/2019

Everything is working properly in term of routing. You are using the URL wrong. You have to use this url

http:// a5b9f45d4119a11eabbd90a9c35f3125-1159448980.us-east-2.elb.amazonaws.com:80/api/resources/swagger/index.html

You have to append swagger/index.html in your url just like you are doing it while accessing it via service.

curl –v http://staffing-service:8080/swagger/index.html


curl –v http:// a5b9f45d4119a11eabbd90a9c35f3125-1159448980.us-east-2.elb.amazonaws.com:80/api/resources/swagger/index.html
-- Muhammad Abdul Raheem
Source: StackOverflow