1

I am trying to connect react application that is available through ingress to my kubectl backend service. How should I go about it without exposing the backend with ingress?

Here is the ingress yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  defaultBackend:
    service:
      name: frontend
      port:
        number: 80
  rules:
    - host: myapp-hello.me
    - http:
        paths:
        - path: /frontend
          pathType: Prefix
          backend:
            service:
              name: frontend
              port:
                number: 80

Backend service:

NAMESPACE    NAME             TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S) 
default      service/backend  ClusterIP  10.107.95.144    <none>        5000/TCP

And inside react app:

fetch('http://') // what address to put here?
      .then(response => {
        response.text().then(text => {
          console.log(text);
          setData(text);
        })
      })
Seiteros
  • 191
  • 1
  • 2
  • 6
  • Your fetch call would be coming from a browser which is outside of your Kubernetes cluster, so the only way for it to reach your backend service would be to expose your backend using an ingress. However, if your frontend could make the request from inside the pod instead of the browser, you would want to hit the following url: backend.default.svc:5000 – ericfossas Jun 28 '22 at 13:50

0 Answers0