[英]get device mounts info on kubernetes node using pod
Team,团队,
I have below pod.yaml that outputs the pod's mount info but now I want it to show me the node's mount info instead or also that info.我在 pod.yaml 下方有输出 pod 的挂载信息,但现在我希望它显示节点的挂载信息或该信息。 any hint how can I give privilege to the pod such that it runs the same command on the k8s hosts on which the pod is running and list that in output of pods logs?
任何提示我如何为 pod 授予特权,使其在运行 pod 的 k8s 主机上运行相同的命令,并在 pods 日志的输出中列出?
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 logs pod/command-demo kubectl 记录 pod/command-demo
command-demo
Mounts are less than 64, that is found 0
expected output:预期输出:
k8s_node1 << this is hostname of the k8s node on which above pod us running
Mounts are more than 64, that is found 65
what change do i need to do in my pod.yaml such that it runs the shell command on node and not on pod?我需要在我的 pod.yaml 中做哪些更改,以便它在节点上而不是在 pod 上运行 shell 命令?
You cannot access host filesystem inside the docker container unless you mount part's of the host filesystem as volume.除非您将主机文件系统的一部分安装为卷,否则您无法访问 docker 容器内的主机文件系统。 You can try mounting the whole host filesytem into the pod as follows.
您可以尝试将整个主机文件系统挂载到 pod 中,如下所示。 You might need to privileged securityContext for the pod depending on what you are trying to do.
根据您要执行的操作,您可能需要为 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
Alternative method and probably better way is to SSH into the host machine from the pod and run the command.替代方法和可能更好的方法是从 pod SSH 到主机并运行命令。 You can get the host IP using downward API - https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
您可以使用向下 API 获取主机 IP - https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.