kubernetes 容器内获取Pod信息
本文讲述Pod能获取Pod自身运行的容器信息以及Node信息(kubernetes 自从1.7开始)
1.编译busybox-env.yaml
文件
apiVersion: v1 kind: Pod metadata: name: busybox-env spec: containers: - name: busybox-container image: busybox command: - sleep - "3600" env: - name: MY_NODE_NAME # 获取node名称 valueFrom: fieldRef: fieldPath: spec.nodeName - name: MY_POD_NAME # 获取pod名称 valueFrom: fieldRef: fieldPath: metadata.name - name: MY_POD_NAMESPACE # 获取pod的namespace valueFrom: fieldRef: fieldPath: metadata.namespace - name: MY_POD_IP # 获取pod IP valueFrom: fieldRef: fieldPath: metadata.name
2.应用yaml
$ kubectl apply -f busybox-env.yaml
3.进入容器内部查看变量是否存在
$ kubectl exec -it busybox-env sh $ env | egrep "MY_POD" MY_POD_NAMESPACE=default MY_POD_IP=busybox-env MY_POD_NAME=busybox-env $ env | egrep "MY_NODE" MY_NODE_NAME=k8s-node01
可以看到变量是已经加载到容器的环境变量中了
相关推荐
远远的山 2020-11-09
kaidiphp 2020-10-13
JustHaveTry 2020-09-29
cloudvtech 2020-09-18
BigDataMining 2020-08-21
akcsdno 2020-07-21
XiaoMuFireAnt 2020-09-02
IT兄弟团 2020-08-01
孝平 2020-07-18
JustHaveTry 2020-07-17
kjh00abc 2020-07-08
Dxiaoru 2020-07-06
breezegao 2020-07-02
xiunai 2020-06-28
薛正华 2020-06-21
JustHaveTry 2020-06-21
丽丽 2020-06-14
shurenyun 2020-06-14
JustHaveTry 2020-06-12