<p>I have a frontend React application and a Go backend service as the API for the frontend. Both are Kubernetes services in the same namespace. How can I communicate with the Go backend service without having to use an external IP? I got it to work with an external ip, but, I can't get the fqdn to resolve correctly like it should. The frontend service is built from the <code>nginx:1.15.2-alpine</code> docker image. How can I get the frontend React app to communicate with the backend Go server?</p>

<p>Frontend service.yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: ui
  namespace: client
  labels:
    app: ui
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: http
    - name: https
      port: 443
      targetPort: https
  selector:
    app: ui
</code></pre>

<p>Frontend deployment.yaml:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ui
  namespace: client
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 2
  template:
    metadata:
      labels:
        app: ui
    spec:
      containers:
        - name: ui
          image: #######
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
</code></pre>

<p>Backend service.yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: api
  namespace: client
  labels:
    app: api
spec:
  type: NodePort
  ports:
    - port: 8001
      protocol: TCP
      targetPort: http
      name: http
  selector:
    app: api
</code></pre>

<p>Backend deployment.yaml:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: api
  namespace: client
  labels:
    name: api
spec:
  replicas: 1
  revisionHistoryLimit: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: ####
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8001
</code></pre>

jrkt
<p><strong>The React application does not run in Kubernetes.</strong>  Maybe you have a dev server running in Kubernetes, but it just serves up HTML and Javascript files to a browser running outside the cluster.  The application in the browser has no idea about this "Kubernetes" thing and can't resolve the Kubernetes-internal <code>...svc.cluster.local</code> hostnames; it needs a way to talk back to the cluster.</p>

<p>Since you have the backend configured as a NodePort type service, you can look up the backend's externally visible port, then configure the backend URL in the served browser application to be that port number on some node in your cluster.  This is a little bit messy and manual.</p>

<p>A better path is to configure an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="noreferrer">ingress</a> so that, for example, <code>https://.../</code> serves your browser application and <code>https://.../api</code> goes to your back-end.  Then the backend URL can just be the bare path <code>/api</code>, and it will be interpreted with the same host name and scheme as the UI.</p>
