skip to Main Content

I have two Kubernetes pods, running under Docker Desktop in WSL2 (local dev test PC).
One pod contains a web app and the other a REST API.

I can successfully login a user in the browser, and the REST API’s logs show that the POST request at http://restapi-service:8080/User was accepted.

However, when I then try to send a GET request to http://restapi-service:8080/Job/jobs?userId=3, I’m getting a “net::ERR_NAME_NOT_RESOLVED” error.

I have verified that the same GET request is working fine when not running in Kubernetes.

It seems to be also working when testing with wget from the web app pod:

$ wget http://restapi-service:8080/Job/jobs?userId=3
Connecting to restapi-service:8080 (10.100.127.206:8080)
saving to 'jobs?userId=3'
jobs?userId=3        100% |******************************************************************************************************************************************|  1809  0:00:00 ETA
'jobs?userId=3' saved

I also tried with the fully qualified domain name restapi-service.default.svc.cluster.local but it made no difference.

Services descriptions:

$ kubectl describe service webui
Name:                     webui-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=webui
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.104.148.120
IPs:                      10.104.148.120
Port:                     http  80/TCP
TargetPort:               5173/TCP
NodePort:                 http  32000/TCP
Endpoints:                10.1.0.95:5173
Session Affinity:         None
External Traffic Policy:  Cluster
Internal Traffic Policy:  Cluster
Events:                   <none>

$ kubectl describe service restapi
Name:                     restapi-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=restapi
Type:                     ClusterIP
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.100.127.206
IPs:                      10.100.127.206
Port:                     8080  8080/TCP
TargetPort:               8080/TCP
Endpoints:                10.1.0.92:8080
Port:                     8081  8081/TCP
TargetPort:               8081/TCP
Endpoints:                10.1.0.92:8081
Session Affinity:         None
Internal Traffic Policy:  Cluster
Events:                   <none>

Any help would be greatly appreciated!

2

Answers


  1. The simplest hack to get your local dev setup working is to force your OS to resolve the container names back to localhost.

    sounds like you’re on windows. temporarily edit c:windowssystem32driversetchosts

    with

    127.0.0.1  restapi-service
    127.0.0.1  webui-service
    

    you could even shim / extend a slightly more useful setup using something like dnsmasq to catch a hostname glob pattern.

    The other comments present a myriad of options suited to non local dev environments.

    Login or Signup to reply.
  2. Your post request is simple:

    http://restapi-service:8080/User
    

    However your get request has additional things in it:

    http://restapi-service:8080/Job/jobs?userId=3
    

    So, if you configured ingress to run for http://restapi-service:8080/User you should also configure it to run for http://restapi-service:8080/Job.

    A better way would be to have the same request pattern:

    http://restapi-service:8080/<your app name here>/.*
    

    In case you specify /.* allow regex by adding:

    nginx.ingress.kubernetes.io/use-regex: "true"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search