<p>I've deployed locally a k8s cluster with kind. The firebase emulator runs on a pod inside the cluster and has a ClusterIp Service assigned. When I'm sending a request to <em><strong>kind-firebase.yaml</strong></em> pod from the <em><strong>service.yaml</strong></em> pod, the request fails because connection cannot be established.</p>
<p><strong>the error</strong>:</p>
<pre><code>failed to establish a connection:
 Post \&quot;http://firebase-service:9099/identitytoolkit.googleapis.com/v1/projects/demo-test
</code></pre>
<p><strong>CONFIGS:</strong></p>
<ul>
<li><em><strong>firebase.json:</strong></em></li>
</ul>
<pre class="lang-json prettyprint-override"><code>{
  &quot;emulators&quot;: {
    &quot;auth&quot;: {
      &quot;port&quot;: 9099,
      &quot;host&quot;: &quot;0.0.0.0&quot;
    },
    &quot;ui&quot;: {
      &quot;enabled&quot;: true,
      &quot;host&quot;: &quot;0.0.0.0&quot;,
      &quot;port&quot;: 4000
    }
  }
}
</code></pre>
<ul>
<li><em><strong>kind-firebase.yaml:</strong></em></li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Namespace
metadata:
  name: firebase-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: firebase-depl
  namespace: firebase-system
spec:
  selector:
    matchLabels:
      app: firebase-emulator
  replicas: 1
  template:
    metadata:
      labels:
        app: firebase-emulator
    spec:
      containers:
      - name: firebase-emulator
        image: fb-emulator
        resources:
          limits:
            cpu: &quot;1000m&quot; # Up to 1 full core
          requests:
            cpu: &quot;1000m&quot; # Use 1 full core
        imagePullPolicy: IfNotPresent
        ports:
        - name: auth
          containerPort: 9099
        - name: emulator-ui
          containerPort: 4000
---
apiVersion: v1
kind: Service
metadata:
  name: firebase-service
  namespace: firebase-system
spec:
  type: ClusterIP
  selector:
    app: firebase-emulator
  ports:
    - name: auth
      port: 9099
      targetPort: auth
    - name: emulator-ui
      port: 4000
      targetPort: emulator-ui

</code></pre>
<ul>
<li><em><strong>service.yaml:</strong></em></li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Namespace
metadata:
  name: auth-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
  namespace: auth-system
spec:
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      terminationGracePeriodSeconds: 60
      volumes:
      - name: google-cloud-key
        secret:
          secretName: firebase-sacc
      containers:
      # auth-api container configuration
          - name: auth-api
            image: auth-api-image
            volumeMounts:
             - name: google-cloud-key
               mountPath: /var/secrets/google
               readOnly: true
            ports:
            - name: auth-api
              containerPort: 3000
            - name: auth-api-debug
              containerPort: 8080
            readinessProbe: # readiness probes mark the service available to accept traffic.
              httpGet:
                path: /debug/readiness
                port: 8080
              initialDelaySeconds: 15
              periodSeconds: 15
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 2
            livenessProbe: # liveness probes mark the service alive or dead (to be restarted).
              httpGet:
                path: /debug/liveness
                port: 8080
              initialDelaySeconds: 30
              periodSeconds: 30
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 2
            env:
              - name: KUBERNETES_NAMESPACE
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.namespace
              - name: KUBERNETES_PODNAME
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.name
              - name: KUBERNETES_NAMESPACE_POD_IP
                valueFrom:
                  fieldRef:
                    fieldPath: status.podIP
              - name: KUBERNETES_NODENAME
                valueFrom:
                  fieldRef:
                    fieldPath: spec.nodeName 
              - name: GOOGLE_APPLICATION_CREDENTIALS
                value: /var/secrets/google/sacc.json
              - name: FIREBASE_AUTH_EMULATOR_HOST 
                value: firebase-service:9099
              - name: GCLOUD_PROJECT
                value: demo-test
---
apiVersion: v1
kind: Service
metadata:
  name: auth-service
  namespace: auth-system
spec:
  type: ClusterIP
  selector:
    app: auth
  ports:
  - name: auth-api
    port: 3000
    targetPort: auth-api
  - name: auth-api-debug
    port: 8080
    targetPort: auth-api-debug
</code></pre>
<ul>
<li>in the file you'll see these env variables:</li>
</ul>
<pre><code>- name: FIREBASE_AUTH_EMULATOR_HOST 
  value: firebase-service:9099
- name: GCLOUD_PROJECT
  value: demo-test
</code></pre>
<p>by using them, the firebase sdk used inside the app that represent <em><strong>service.yaml</strong></em>, will set the sdk for using the firebase emulator and not the one in the cloud.</p>
<p><strong>Screenshots with the cluster:</strong></p>
<ol>
<li>Here we can see the namespaces available.</li>
</ol>
<ul>
<li>In the auth-system the <em><strong>service.yaml</strong></em> pod will be present.</li>
<li>In the firebase-system the <em><strong>kind-firebase.yaml</strong></em> pod will be present.</li>
</ul>
<p><a href="https://i.stack.imgur.com/s5dcS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s5dcS.png" alt="enter image description here" /></a></p>
<ol start="2">
<li><em><strong>service.yaml</strong></em> pod</li>
</ol>
<p><a href="https://i.stack.imgur.com/zPwcD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zPwcD.png" alt="enter image description here" /></a></p>
<ol start="3">
<li><em><strong>kind-firebase.yaml</strong></em> pod</li>
</ol>
<p><a href="https://i.stack.imgur.com/x7cWw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x7cWw.png" alt="enter image description here" /></a></p>
<ol start="4">
<li>Here we can see the logs inside <em><strong>service.yaml</strong></em> pod when I send a request to the <em><strong>kind-firebase.yaml</strong></em> pod... the error:</li>
</ol>
<pre><code>failed to establish a connection:
 Post \&quot;http://firebase-service:9099/identitytoolkit.googleapis.com/v1/projects/demo-test
</code></pre>
<p><a href="https://i.stack.imgur.com/j2nck.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j2nck.png" alt="enter image description here" /></a></p>
<p>Thx for any help!</p>

Robert Mihai
<p>After connecting to the firebase pod and checking DNS Resolution, the service name must be:</p>
<pre><code>firebase-service.firebase-system.svc.cluster.local:9099
</code></pre>
<p>So the env variable from <em><strong>kind-firebase.yaml</strong></em> must be:</p>
<pre class="lang-yaml prettyprint-override"><code>
- name: FIREBASE_AUTH_EMULATOR_HOST 
  value: firebase-service.firebase-system.svc.cluster.local:9099

</code></pre>
<p>Everything works fine now.</p>
