Home > front end >  Vanilla JS ERR_NAME_NOT_RESOLVED on minikube cluster
Vanilla JS ERR_NAME_NOT_RESOLVED on minikube cluster

Time:09-17

I have a minimal web application running on local minikube cluster. The backend is exposing an API at /be/test/hi and service name is also be. When I send a GET request from frontend to backend i get:

main.js:15 GET http://be/be/test/hi net::ERR_NAME_NOT_RESOLVED

If I run nslookup be from the frontend POD i get the correct dns resolution, and running curl be/be/test/hi I get the right response from backend (a simple 'Hello world' string)

What am I missing?

backend.yaml

apiVersion: v1
kind: Service
metadata:
  name: be
spec:
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: be
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: be
spec:
  replicas: 1
  selector:
    matchLabels:
      app: be
  template:
    metadata:
      labels:
        app: be
    spec:
      containers:
      - name: be
        image: kubebe
        imagePullPolicy: Never
        ports:
          - containerPort: 8080

frontend.yaml

apiVersion: v1
kind: Service
metadata:
  name: fe
spec:
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: fe
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fe
  template:
    metadata:
      labels:
        app: fe
    spec:
      containers:
      - name: fe
        image: kubefe
        imagePullPolicy: Never
        ports:
          - containerPort: 8080

main.js

const URL="http://be/be/test/hi"

  function httpGetAsync(){
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            console.log(xmlHttp.responseText);
    }
    xmlHttp.open("GET", URL, true); 
    xmlHttp.send(null);
}

frontend Dockerfile (kubefe image):

FROM centos/httpd-24-centos7:2.4
RUN mkdir -p /var/www/html/fe
COPY ./index.html ./main.js /var/www/html/fe/

EDIT: I've resolved my issues but I think the actual question is still unanswered.

To solve this I've simple removed the protocol and host from my url and set up proxy rules in /etc/httpd/conf.d/default-site.conf

default-site.conf

<VirtualHost *:8080> 
  ProxyPreserveHost Off
  ProxyRequests Off
  ProxyPass /be/ http://be/be/
</VirtualHost> 

CodePudding user response:

Your frontend code (javascript) is executing in your browser, not inside the kubernetes cluster (nginx pod)

You have 3 options here,

  1. Create a NodePort Service for your frontend
  2. Rely on kubeproxy for doing a port forward
  3. Create an ingress
  • Related