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!
I managed to solve this myself. In case anyone else is having the same issue with Docker Desktop/WSL2/Kubernetes, here is what worked for me:
Web app service YAML:
apiVersion: v1
kind: Service
metadata:
name: webapp-service
namespace: default
spec:
type: NodePort
selector:
app: webapp
ports:
- name: web
protocol: TCP
port: 80
targetPort: 5173
nodePort: 30080
Rest API service YAML:
apiVersion: v1
kind: Service
metadata:
name: api-service
namespace: default
spec:
type: NodePort
selector:
app: api
ports:
- name: restapi
protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30081
Get the WSL IP by running:
ip addr show eth0 | grep inet
Then use that IP with the node port of the API in the fetch command, E.g.:
fetch(http://172.23.233.198:30081/Job/jobs?userId=3)