Mayank Sachan
Mayank Sachan

Reputation: 75

How to mount volume inside pod using "kubectl" CLI

I want to create a pod using kubectl CLI which will mount hostpath /etc/os-release inside pod container and display content of /etc/os-release file. Is is possible to do it in using one-liner kubectl command?

Upvotes: 3

Views: 3793

Answers (1)

hariK
hariK

Reputation: 3069

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

Upvotes: 6

Related Questions