Kubectl:如何从命令行创建持久卷的清单?

Jum*_*ode 2 kubernetes kubectl persistent-volumes

是否可以从命令行创建(启动清单)pv/pvc?

IE。创建部署

kubectl create deployment abc --image=logger:1 --dry-run=client -o yaml > abc.yml
Run Code Online (Sandbox Code Playgroud)

IE。创建一个 Pod

kubectl run pod xyz --image=logger:1 --dry-run=client -o yaml > xyz.yml
Run Code Online (Sandbox Code Playgroud)

我正在尝试做什么

kubectl create persitentvolume --name my-pv spec.capacity.storage=1Gi --dry-run=client -o yaml > my-pv.yml
Run Code Online (Sandbox Code Playgroud)

使用的参考文献: https ://kubernetes.io/docs/reference/ generated/kubectl/kubectl-commands

P..*_*... 6

We cannot create the manifest file for `pv` using the command line. For only the following objects created using the command line(imperatively) is possible. 

     --->kubectl create [press tab] [press tab] 
    clusterrole          cronjob              namespace            quota                secret               
    clusterrolebinding   deployment           poddisruptionbudget  role                 service              
    configmap            job                  priorityclass        rolebinding          serviceaccount   
Run Code Online (Sandbox Code Playgroud)

或者您可以使用--helpwithkubectl create检查可用选项。

Available Commands:
  clusterrole           Create a cluster role
  clusterrolebinding    Create a cluster role binding for a particular cluster role
  configmap             Create a config map from a local file, directory or literal value
  cronjob               Create a cron job with the specified name
  deployment            Create a deployment with the specified name
  ingress               Create an ingress with the specified name
  job                   Create a job with the specified name
  namespace             Create a namespace with the specified name
  poddisruptionbudget   Create a pod disruption budget with the specified name
  priorityclass         Create a priority class with the specified name
  quota                 Create a quota with the specified name
  role                  Create a role with single rule
  rolebinding           Create a role binding for a particular role or cluster role
  secret                Create a secret using specified subcommand
  service               Create a service using a specified subcommand
  serviceaccount        Create a service account with the specified name
  token                 Request a service account token
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. 以上信息适用于v1.24.2或以下。这可能与未来的版本有所不同。
  2. kubectl create token在1.24版本中添加。