首页 > 解决方案 > 如何使用“kubectl”CLI 在 pod 内挂载卷

问题描述

我想使用kubectlCLI 创建一个 pod,它将/etc/os-release在 pod 容器内安装 hostpath 并显示/etc/os-release文件内容。是否可以使用单行kubectl命令来做到这一点?

标签: kuberneteskubectlkubernetes-podpersistent-volumes

解决方案


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

推荐阅读