使用kubectl run创建具有卷的kubernetes pod [英] Create kubernetes pod with volume using kubectl run

查看:639
本文介绍了使用kubectl run创建具有卷的kubernetes pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解您可以使用kubectl run在Deployment/Job中创建一个pod.但是是否可以创建一个附加了卷的卷呢?我尝试运行此命令:

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:

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

但是该音量没有出现在交互式bash中.

But the volume does not appear in the interactive bash.

是否有更好的方法来创建具有可附加音量的吊舱?

Is there a better way to create a pod with volume that you can attach to?

推荐答案

您的JSON覆盖指定不正确.不幸的是,kubectl运行只是忽略了它不理解的字段.

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

从那里您可以看到实际的作业结构与json重写不同(您缺少嵌套的模板/规范,并且卷,volumeMount和容器必须是数组).

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).

这篇关于使用kubectl run创建具有卷的kubernetes pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆