1
votes

I am learning Kubernetes and i run into trouble reaching an API in my local Minikube (Docker driver). I have a pod running an angluar-client which tries to reach a backend pod. The frontend Pod is exposed by a NodePort Service. The backend pod is exposed to the Cluster by a ClusterIP Service.

But when i try to reach the clusterip service from the frontend the dns transpile-svc.default.svc.cluster.local cannot get resolved. error message in the client

the dns should work properly. i followed this https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/ and deployed a dnsutils pod from where i can nslookup.

winpty kubectl exec -i -t dnsutils -- nslookup transpile-svc.default
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   transpile-svc.default.svc.cluster.local
Address: 10.99.196.82

This is the .yaml file for the clusterIP Service

apiVersion: v1
kind: Service
metadata:
  name: transpile-svc
  labels: 
    app: transpile
spec:
  selector:
    app: transpile
  ports:
  - port: 80
    targetPort: 80

Even if i hardcode the IP into the request of the frontend i am getting an empty response. I verified, that the backend pod is working correctly and when i expose it as a NodePort i can reach the api with my browser.

What am i missing here? Im stuck with this problems for quite some time now and i dont find any solution.

2

2 Answers

2
votes

Since your frontend application is calling your application from outside the cluster you need to expose your backend application to outside network too.

There are two ways: either expose it directly by changing transpile-svc service to loadbalancer type or introduce an ingress controller(eg Nginx ingress controller with an Ingres object) which will handle all redirections

Steps to expose service as loadbalancer in minikube

1.Change your service transpile-svc type to LoadBalancer 2.Run command minikube service transpile-svc to expose the service ie an IP will be allocated. 3. Run kubectl get services to get external IP assigned. Use IP:POST to call from frontend application

0
votes

DNS hostnames *.*.svc.cluster.local is only resolvable from within the kubernetes cluster. You should use http://NODEIP:NODEPORT or url provided by minikube service transpile-svc --url in the frontend javascript code which is running in a browser outside the kubernetes cluster.

If the frontend pod is nginx then you can configure the backend service name as below in the nginx configuration file as described in the docs

upstream transpile {
    server transpile;
}

server {
    listen 80;

    location / {
        proxy_pass http://transpile-svc;
    }
}