简体   繁体   English

使用 pod 在 kubernetes 节点上获取设备挂载信息

[英]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.

相关问题 使用 pod 名称执行 kubernetes pod - Executing a kubernetes pod with the use of pod name Kubernetes worker pod 中的 Shell 脚本 - Shell script in Kubernetes worker pod 如何删除 Kubernetes 命名空间中的每个 Pod - How to delete every Pod in a Kubernetes namespace 在 pod 远程 openshift 或 kubernetes 中运行 shell 脚本 - Run shell script in pod remotely openshift or kubernetes 如何在 Kubernetes Pod 中执行 mq 脚本文件? - How to execute a mq script file in a Kubernetes Pod? 是否有 kubectl filter 命令来获取 PVC - 它的卷 - 安装在 pod 中 - 托管在节点字段中? - Is there kubectl filter command to get the PVC - it's volume - mounted in pod -hosted in node fields? Jenkins 将参数作为 env 传递给 shell 脚本,以便将 sh 传递给 kubernetes pod - Jenkins pass paramater as an env to the shell script for passing sh to kubernetes pod 如何在 Kubernetes 的交互式 bash pod 上执行 shell 脚本作为输入? - How to execute a shell script as input on an interactive bash pod in Kubernetes? 如果 pod 名称随每次部署而更改,如何在 shell 脚本中执行 kube.netes 中的 pod - How to exec a pod in kubernetes in a shell script if the pod name changes with every deployment Kubernetes 在 pod 中执行 cat 从脚本块执行 - Kubernetes execute cat in a pod from a script blocks execution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM