<p>I'm trying to configure kubernetes and in my project I've separeted UI and API.
I created one Pod and I exposed both as services.</p>

<p>How can I set API_URL inside pod.yaml configuration in order to send requests from user's browser?</p>

<p>I can't use localhost because the communication isn't between containers.</p>

<p>pod.yaml</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: project
  labels:
    name: project
spec:
  containers:
  - image: 'ui:v1'
    name: ui
    ports:
    - name: ui
      containerPort: 5003
      hostPort: 5003
    env:
    - name: API_URL
      value: &lt;how can I set the API address here?&gt;
  - image: 'api:v1'
    name: api
    ports:
    - name: api
      containerPort: 5000
      hostPort: 5000
    env:
    - name: DATABASE_URL
      valueFrom:
      secretKeyRef:
        name: postgres-url
        key: url
</code></pre>

<p>services.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: api
  labels:
    name: api
spec:
  type: NodePort
  ports:
  - name: 'http'
    protocol: 'TCP'
    port: 5000
    targetPort: 5000
    nodePort: 30001
  selector:
    name: project
---
apiVersion: v1
kind: Service
metadata:
  name: ui
  labels:
    name: ui
spec:
  type: NodePort
  ports:
  - name: 'http'
    protocol: 'TCP'
    port: 80
    targetPort: 5003
    nodePort: 30003
  selector:
    name: project
</code></pre>

<p>I created an Ingress to solve this issue and point to DNS instead of IP.</p>

<p>ingres.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: project
spec:
  tls:
  - secretName: tls
  backend:
    serviceName: ui
    servicePort: 5003
  rules:
  - host: www.project.com
    http:
      paths:
      - backend:
          serviceName: ui
          servicePort: 5003
  - host: api.project.com
    http:
      paths:
      - backend:
          serviceName: api
          servicePort: 5000
</code></pre>

<p>deployment.yaml</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: project
  labels:
    name: project
spec:
  containers:
  - image: 'ui:v1'
    name: ui
    ports:
    - name: ui
      containerPort: 5003
      hostPort: 5003
    env:
    - name: API_URL
      value: https://api.project.com
  - image: 'api:v1'
    name: api
    ports:
    - name: api
      containerPort: 5000
      hostPort: 5000
    env:
    - name: DATABASE_URL
      valueFrom:
      secretKeyRef:
        name: postgres-url
        key: url
</code></pre>
