【问题标题】:How to mount volume inside pod using "kubectl" CLI如何使用“kubectl”CLI 在 pod 内挂载卷
【发布时间】:2020-05-14 17:04:39
【问题描述】:

我想使用 kubectl CLI 创建一个 pod,它将在 pod 容器内挂载主机路径 /etc/os-release 并显示 /etc/os-release 文件的内容。 是否可以使用单行kubectl 命令来做到这一点?

【问题讨论】:

    标签: kubernetes kubectl kubernetes-pod persistent-volumes


    【解决方案1】:
    kubectl run -i --rm busybox --image=busybox --overrides='{
                   "apiVersion": "v1",
                   "spec": {
                      "containers": [
                         {
                            "image": "busybox",
                            "name": "busybox",
                            "command": ["cat", "/etc/os-release"],
                            "resources": {},
                            "volumeMounts": [
                               {
                                  "mountPath": "/etc/os-release",
                                  "name": "release"
                               }
                            ]
                         }
                      ],
                      "volumes": [
                         {
                            "name": "release",
                            "hostPath": {
                               "path": "/etc/os-release",
                               "type": "File"
                            }
                         }
                      ],
                      "dnsPolicy": "ClusterFirst",
                      "restartPolicy": "Never"
                   },
                   "status": {}
                }'
    NAME=Buildroot
    VERSION=2019.02.10
    ID=buildroot
    VERSION_ID=2019.02.10
    PRETTY_NAME="Buildroot 2019.02.10"
    pod "busybox" deleted
    

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      相关资源
      最近更新 更多