1

If I curl to the container: kubectl exec <my-nginx-> -- curl localhost:80

It displays no version number, just:

<html>
<head>
  <title>Welcome to my Nginx page</title>
</head>
<body>
  <h1>Hello World!</h1>
  <p>This is version  of my site.</p>
</body>
</html>

I'd expect to see the literal string ${VERSION} in the output.

Update:

I can see the environment variable is set using kubectl describe deployment my-nginx. Maybe it has something to do with reading envoronment variable from HTML.

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-configmap
data:
  index.html: |
    <html>
    <head>
      <title>Welcome to my Nginx page</title>
    </head>
    <body>
      <h1>Hello World!</h1>
      <p>This is version ${VERSION} of my site.</p>
    </body>
    </html>
  version: "1.0"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      app: my-nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        env:
        - name: VERSION
          valueFrom:
            configMapKeyRef:
              name: my-configmap
              key: version
        ports:
        - containerPort: 80
        volumeMounts:
        - name: html
          mountPath: /usr/share/nginx/html
      volumes:
      - name: html
        configMap:
          name: my-configmap
Chris G.
  • 23,930
  • 48
  • 177
  • 302
  • 1
    What should perform the environment-variable substitution in the static HTML file? I'd expect to see the literal string `${VERSION}` in the output. – David Maze Feb 26 '23 at 14:29
  • 1
    I don't think this might be natively supported in current ConfigMap implementation. See [this](https://stackoverflow.com/questions/64113850/how-to-get-environment-variable-in-configmap) SO thread. – Sibtain Feb 26 '23 at 16:05
  • By using Javascript we can get env variable into an HTML file **or** Are you looking to get through HTML only? – Dharani Dhar Golladasari Feb 27 '23 at 12:18

0 Answers0