Connect back-end with front-end over rest api call running on kubernetes
It's because you're using headless service
I guess you don't need a headless service for this job. Because DNS server won't return a single IP address if there are more than one pod match by the label selector. Remove the spec.ClusterIP
field from your service.
apiVersion: v1kind: Servicemetadata: name: mywebapi-svc namespace: defaultspec: # clusterIP: None <-- remove ports: - name: mywebapiport port: 5000 protocol: TCP targetPort: 5000 selector: app: mywebapi type: ClusterIP
Now you can call at http://service-name.namespace-name.svc:port
endpoint from your front-end. It should work.
In case your webapi is stateful, then you should use statefulset
instead of deployment
.