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