<p>I have been struggling for a few hours on this one. I have a very simple 2 tier  dotnet core skeleton app (mvc and webapi) hosted on Azure using Kubernetes with Windows as the orchestrator.
The deployment works fine and I can pass basic environment variables over. The challenge I have is that I cannot determine how to pass the backend service IP address over to the frontend variables.
if I stage the deployments, I can manually pass the exposed IP of the backend into the frontend. Ideally, this needs to be deployed as a service.</p>

<p>Any help will be greatly appreciated.</p>

<p><strong>Deployment commands:</strong></p>

<p>1 - kubectl create -f backend-deploy.yaml</p>

<p>2 - kubectl create -f backend-service.yaml</p>

<p>3 - kubectl create -f frontend-deploy.yaml</p>

<p>4 - kubectl create -f frontend-service.yaml</p>

<p><strong>backend-deploy.yaml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: acme
spec:
  replicas: 5
  template:
metadata:
  labels:
    app: acme-app
    tier: backend
spec:
  containers:
    - name: backend-container
      image: "some/image"
  imagePullSecrets:
    - name: supersecretkey
      env:
      - name: Config__AppName
        value: "Acme App"
      - name: Config__AppDescription
        value: "Just a backend application"
      - name: Config__AppVersion
        value: "1.0"
      - name: Config__CompanyName
        value: "Acme Trading Limited"</code></pre>
</div>
</div>
</p>

<p><strong>backend-service.yaml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>kind: Service
apiVersion: v1
metadata:
  name: acme-app
spec:
  selector:
    app: acme-app
    tier: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer</code></pre>
</div>
</div>
</p>

<p><strong>frontend-deploy.yaml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: frontend
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: acme-app
        tier: frontend
    spec:
      containers:
        - name: frontend-container
          image: "some/image"
      imagePullSecrets:
        - name: supersecretkey
          env:
          - name: Config__AppName
            value: "Acme App"
          - name: Config__AppDescription
            value: "Just a frontend application"
          - name: Config__AppVersion
            value: "1.0"
          - name: Config__AppTheme
            value: "fx-theme-black"
          - name: Config__ApiUri
            value: ***THIS IS WHERE I NEED THE BACKEND SERVICE IP***
          - name: Config__CompanyName
            value: "Acme Trading Limited"</code></pre>
</div>
</div>
</p>

<p><strong>frontend-service.yaml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>kind: Service
apiVersion: v1
metadata:
  name: frontend
spec:
  selector:
    app: acme
    tier: frontend
  ports:
    - protocol: "TCP"
      port: 80
      targetPort: 80
  type: LoadBalancer</code></pre>
</div>
</div>
</p>

<p>If your backend service was created BEFORE the frontend pods, you should have the environment variables <code>ACME_APP_SERVICE_HOST</code> and <code>ACME_APP_SEVICE_PORT</code> inside the pods.</p>

<p>If your backend service was created AFTER the frontend pods, then delete the pods and wait for them to be restarted. The new pods should have those variables.</p>

<p>To check the environment variables do:</p>

<pre><code>$ kubectl exec podName env
</code></pre>
