Create kubernetes pod with volume using kubectl run

前端 未结 1 1133
名媛妹妹
名媛妹妹 2020-12-15 03:46

I understand that you can create a pod with Deployment/Job using kubectl run. But is it possible to create one with a volume attached to it? I tried running this command:<

相关标签:
1条回答
  • 2020-12-15 04:22

    Your JSON override is specified incorrectly. Unfortunately kubectl run just ignores fields it doesn't understand.

    kubectl run -i --rm --tty ubuntu --overrides='
    {
      "apiVersion": "batch/v1",
      "spec": {
        "template": {
          "spec": {
            "containers": [
              {
                "name": "ubuntu",
                "image": "ubuntu:14.04",
                "args": [
                  "bash"
                ],
                "stdin": true,
                "stdinOnce": true,
                "tty": true,
                "volumeMounts": [{
                  "mountPath": "/home/store",
                  "name": "store"
                }]
              }
            ],
            "volumes": [{
              "name":"store",
              "emptyDir":{}
            }]
          }
        }
      }
    }
    '  --image=ubuntu:14.04 --restart=Never -- bash
    

    To debug this issue I ran the command you specified, and then in another terminal ran:

    kubectl get job ubuntu -o json
    

    From there you can see that the actual job structure differs from your json override (you were missing the nested template/spec, and volumes, volumeMounts, and containers need to be arrays).

    0 讨论(0)
提交回复
热议问题