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"