79614136

Date: 2025-05-09 12:47:45
Score: 0.5
Natty:
Report link

I ended up finding that what David said was on the right track, apparently the file env.js cant be in the same folder as the application, but if you set it in a subfolder for example env/env.js and configuring the ConfigMap to write the file actually works.

ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:    
  name: cfg-map
data:
  env.js: |
    window.env = {
      "API_URL": "http://ip:port"
    }

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment
spec:
  ...
  selector:
    spec:
      ...
      volumeMounts:
      - name: storage
        mountPath: /usr/share/nginx/html/env
    volumes:
    - name: storage
      configMap:
        name: cfg-map
        items:
        - key: "env.js"
          path: "env.js"
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Federico Stefini