javascriptnginxkuberneteskube-dns

Can't resolve service URL in fetch on nginx server HTML


I run in kubernetes:

A JavaScript fetch in the HTML gives me net::ERR_NAME_NOT_RESOLVED

<script>
    fetch("http://backend-service.default.svc.cluster.local")) // net::ERR_NAME_NOT_RESOLVED
</script>

However, the URL can be resolved when I use curl on the image:

$ kubectl exec frontend-deployment-75f7d9775b-pxgkx -- curl http://backend-service.default.svc.cluster.local

<expected json response>

Why can the URL be resolved with curl, but JavaScript fetch fails with net::ERR_NAME_NOT_RESOLVED?


Solution

  • I figured it out!

    In the scenario I described: