<p>I'm trying to run in kubernetes mern application (<a href="https://github.com/ibrahima92/fullstack-typescript-mern-todo/" rel="nofollow noreferrer">https://github.com/ibrahima92/fullstack-typescript-mern-todo/</a>). I have a client and a server container, and I need to replace the path to the url client in the backend, so I defined variables in the backend code, but they don't replace the values of the variables from the manifest files. There are variables inside the container, but the backend does not use them.
I tried such options 1. ${FRONT_URL}, ${process.env.FRONT_URL}, process.env.FRONT_URL. If I directly insert the URL of the service with the port number in backend code then everything works. How to correctly define variables in a container?</p>
<p><strong>I need replace http://localhost:${PORT} to url of service from K8S and
the same thing need to do with ${MONGO_URL}</strong></p>
<pre><code>import express, { Express } from 'express'
import mongoose from 'mongoose'
import cors from 'cors'
import todoRoutes from './routes'

const app: Express = express()

const PORT: string | number = process.env.PORT || 4000

app.use(cors())
app.use(todoRoutes)

const uri: string = `mongodb://${MONGO_URL}?retryWrites=true&amp;w=majority`
const options = { useNewUrlParser: true, useUnifiedTopology: true }
mongoose.set('useFindAndModify', false)

mongoose
    .connect(uri, options)
    .then(() =&gt;
        app.listen(PORT, () =&gt;
            console.log(`Server running on http://localhost:${PORT}`)
        )
    )
    .catch((error) =&gt; {
        throw error
    })

</code></pre>
<p><strong>Manifest</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-server-app-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: todo-server-app
  template:
    metadata:
      labels:
        app: todo-server-app
    spec:
      containers:
        - image: repo/todo-server-app:24
          name: container1
          ports:
          - containerPort: 4000
          env:
            - name: FRONT_URL 
              value: a1ecab155236d4c7fba8b0c6a1b6ad2b-549550669.us-east-1.elb.amazonaws.com:80
            - name: MONGO_URL
              value: todo-mongo-service:27017
          imagePullPolicy: IfNotPresent
              



</code></pre>

<p>You can create a <a href="https://kubernetes.io/docs/concepts/configuration/configmap/" rel="nofollow noreferrer">config map</a>, giving your container run time variables,
Or alternatively, build your own docker image using the <code>ENV</code></p>
<p>You can also acheive that using kustomization.</p>
<ul>
<li>kustomization.yml</li>
</ul>
<pre><code>secretGenerator: 
   - name: my-secret 
     behavior: create 
     env: .env
</code></pre>
<ul>
<li>Deployment.yml</li>
</ul>
<pre><code>
envFrom: 
- secretRef: 
  name: my-secret

</code></pre>
