-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathpod_use_downwardAPI.yaml
44 lines (44 loc) · 1.19 KB
/
pod_use_downwardAPI.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 此模板演示了如何使用 环境变量和存储卷 方式注入Pod信息到Pod内部
apiVersion: v1
kind: Pod
metadata:
name: busybox-use-downwardapi
labels:
app: busybox
label_test: some_value
spec:
containers:
- name: write
image: busybox
command: [ "sh", "-c" ]
# 通过命令行可以读取环境变量
args: [ 'echo "hellok8s, downwardAPI! PodName=${POD_NAME} LIMITS_CPU=${LIMITS_CPU} POD_IP=${POD_IP}"; sleep infinity' ]
resources:
limits:
cpu: "0.1"
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: LIMITS_CPU
valueFrom:
resourceFieldRef:
resource: limits.cpu
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- mountPath: /config/downward_api_info
name: volume-downward
volumes:
- name: volume-downward
downwardAPI:
items:
- path: "POD_NAME"
fieldRef:
fieldPath: metadata.name
- path: "LABELS"
fieldRef:
fieldPath: metadata.labels