Skip to content

Commit 2cc50a5

Browse files
committed
Fix cluster metadata env variables
1 parent 1470006 commit 2cc50a5

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

applications/python-echo-server/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ COPY . .
3737

3838
RUN chmod +x /app/main.py
3939

40-
4140
# Switch to the non-privileged user to run the application.
4241
USER appuser
4342

43+
RUN apt-get -y update; apt-get -y install curl dnsutils
44+
4445
# Expose the port that the application listens on.
4546
EXPOSE 8080
4647

applications/python-echo-server/deploy/manifest.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ spec:
3232
- env:
3333
- name: PORT
3434
value: "8080"
35+
- name: NODE_NAME
36+
valueFrom:
37+
fieldRef:
38+
fieldPath: spec.nodeName
39+
- name: POD_NAME
40+
valueFrom:
41+
fieldRef:
42+
fieldPath: metadata.name
43+
- name: NAMESPACE
44+
valueFrom:
45+
fieldRef:
46+
fieldPath: metadata.namespace
47+
- name: POD_IP
48+
valueFrom:
49+
fieldRef:
50+
fieldPath: status.podIP
51+
envFrom:
52+
- configMapRef:
53+
name: cluster-metadata
3554
image: docker.io/library/python-echo-server:latest
3655
name: python-echo-server
3756
ports:

applications/python-echo-server/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ def ping():
3333
def echo():
3434
kubernetes_info = [
3535
"Kubernetes Info: ",
36-
"\tHostname: " + os.environ.get("HOSTNAME", "N/A"),
3736
"\tCluster Name: " + os.environ.get("CLUSTER_NAME", "N/A"),
38-
"\tNamespace: " + os.environ.get("POD_NAMESPACE", "N/A"),
37+
"\tNamespace: " + os.environ.get("NAMESPACE", "N/A"),
3938
"\tNode Name: " + os.environ.get("NODE_NAME", "N/A"),
4039
"\tPod Name: " + os.environ.get("POD_NAME", "N/A"),
4140
"\tPod IP: " + os.environ.get("POD_IP", "N/A"),

scripts/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ fi
4646
while IFS= read -r target
4747
do
4848
kubectl --context $target create namespace "$NAMESPACE" 2>/dev/null || true
49+
kubectl --context $target -n $NAMESPACE create configmap cluster-metadata --from-literal="CLUSTER_NAME=$target"
4950
krane deploy $NAMESPACE $target -f $DEPLOY_PATH
5051
done < $DEPLOY_PATH/TARGETS

0 commit comments

Comments
 (0)