I'm struggling to make Http calls from the frontend app to the backend app in Kubernetes.
So basically I have deployment,service and ingress rules for both frontend and backend application and the frontend service can't connect to backend service.
This is the error message Im getting
GET http://spring-boot-vuejs:8080/api/courses net::ERR_NAME_NOT_RESOLVED
I am trying to create a simple web application using Vuejs as frontend and Spring boot as backend. The backend exposes REST api's on /api/courses/* endpoint and the frontend consumes it.
I have deployed two separate pods, one for frontend and one for backend on a bare metal Kubernetes cluster. I have also installed Nginx ingress controller.
if I run both docker images in my local machine, everything works fine because Im using "http://localhost:8080" as the backend end point but the moment I deploy the apps on Kubernetes, it wont work anymore as it can resolve the service name "http://spring-boot-vuejs:8080"
I already referred to issues mentioned here, here, here but none of them helped me.
Below are the respective yaml files. Please correct me if Im making mistake in any yaml files or the ingress rules.
Backend:
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-vuejs
labels:
app: spring-boot-vuejs
spec:
replicas: 1
selector:
matchLabels:
app: spring-boot-vuejs
template:
metadata:
labels:
app: spring-boot-vuejs
spec:
containers:
- name: spring-boot-vuejs
imagePullPolicy: ifNotPresent
image: <my docker hub username>/spring-boot-vuejs:0.0.1
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: spring-boot-vuejs
labels:
app: spring-boot-vuejs
spec:
clusterIP: None
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: spring-boot-vuejs
selector:
app: spring-boot-vuejs
Ingress rules
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: spring-boot-vuejs
annotations:
kubernetes.io/ingress.class: nginx
spec:
backend:
serviceName: default-http-backend
servicePort: 80
rules:
- host: spring-boot-vuejs
- http:
paths:
- path: /api/.*
backend:
serviceName: spring-boot-vuejs
servicePort: 8080
Yaml files for frontend
Deployment and service
apiVersion: apps/v1
kind: Deployment
metadata:
name: vuejs-frontend
labels:
app: vuejs-frontend
spec:
replicas: 1
selector:
matchLabels:
app: vuejs-frontend
template:
metadata:
labels:
app: vuejs-frontend
spec:
containers:
- name: vuejs-frontend
imagePullPolicy: ifNotPresent
image: <my dockerhub username>/vuejs-frontend:0.0.1
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: vuejs-frontend
labels:
app: vuejs-frontend
spec:
clusterIP: None
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: vuejs-frontend
selector:
app: vuejs-frontend
Ingress rules
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: vuejs-frontend
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: default-http-backend
servicePort: 80
rules:
- host: spring-boot-vuejs
- http:
paths:
- path: /
backend:
serviceName: vuejs-frontend
servicePort: 8080
ngress-nginx nginx-ingress-controller-6879cf6459-8cg44 1/1 Running 0 64d
Nginx serviceingress-nginx ingress-nginx NodePort 10.105.123.73 <none> 80:32372/TCP,443:30907/TCP 64d
– rakeshkubectl exec pod/<frontend-pod-name> cat /etc/resolv.conf
What does that return? You should see a list of k8s cluster search domains? – TuxInvader/etc/resolv.conf
on frontend pod.# cat /etc/resolv.conf nameserver 10.96.0.10 search vuejs.svc.cluster.local svc.cluster.local cluster.local lswv130.leasewebcloud.com options ndots:5
I removed the ingress for backend – rakesh