队员们,
我在下面的pod.yaml中输出了pod的挂载信息,但现在我想让它显示节点的挂载信息,或者也显示该信息。有什么提示吗?我怎样才能赋予pod权限,让它在运行pod的k8s主机上运行相同的命令,并在pod日志的输出中列出该命令?
apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["/bin/bash", "-c"]
args:
- |
echo $HOSTNAME && mount | grep -Ec '/dev/sd.*\<csi' | awk '$0 <= 64 { print "Mounts are less than 64, that is found", $0 ;} $0 > 64 { print "Mounts are more than 64", $0 ;}'
restartPolicy: OnFailure
kubectl日志pod/command-demo
command-demo
Mounts are less than 64, that is found 0
预期输出:
k8s_node1 << this is hostname of the k8s node on which above pod us running
Mounts are more than 64, that is found 65
我需要在pod.yaml中做什么更改才能让它在节点上而不是pod上运行外壳命令?
发布于 2019-12-31 15:32:23
您不能访问docker容器内的主机文件系统,除非您将主机文件系统的一部分挂载为卷。您可以尝试将整个主机文件系统挂载到pod中,如下所示。您可能需要为pod设置特权securityContext,具体取决于您要执行的操作。
apiVersion: v1
kind: Pod
metadata:
name: dummy
spec:
containers:
- name: busybox
image: busybox
command: ["/bin/sh"]
args: ["-c", "sleep 3600"]
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
type: Directory
另一种可能更好的方法是从pod通过SSH连接到主机,然后运行该命令。您可以使用下行接口- https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/获取宿主机IP
https://stackoverflow.com/questions/59540144
复制相似问题