Kubernetes service doesn't properly configure environment variables

36 views Asked by At

I have two applications both running in containers, but are deployed separately on the same host and namespace.

The main application is talking to the supporting application using REST APIs. For that it needs a host and a port for the supporting application. I have a service running to expose the supporting application.

apiVersion: v1
kind: Service
metadata:
  name: my-app
  namespace: my-ns
  labels:
    app: my-app
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: <container port>
  selector:
    app: my-app

For the main application I have a values.yaml and a deployment.yaml with environment variables for supporting application host and port.

values.yaml snippet:

my-app-host: my-app
my-app-port: 80

deployment.yaml snippet:

 env:
        - name: my-app-host
          value: '{{ index .Values "my-app-host" }}'
        - name: my-app-port
          value: {{ index .Values "my-app-port" }}

When I'm running the main application, I'm seeing that it is trying to reach the supporting application on an empty host, like so: http://:my-app-port/REST-API-endpoint

I suspect that it is not pulling either host or port properly. Although the port looks correct, when I tried to change it to a dummy number in the service.yaml (above), it was still showing the correct port.

I would appreciate any help correcting my service set up.

Thank you for your time!

0

There are 0 answers