Kubectl : How to create manifest of persistentvolume from command line?

Viewed 909

Is it possible to create (start the manifest) of a pv/pvc from command line?

ie. Creating a deployment

kubectl create deployment abc --image=logger:1 --dry-run=client -o yaml > abc.yml

ie. Creating a pod

kubectl run pod xyz --image=logger:1 --dry-run=client -o yaml > xyz.yml

What I'm trying to do

kubectl create persitentvolume --name my-pv spec.capacity.storage=1Gi --dry-run=client -o yaml > my-pv.yml

References used : https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

1 Answers
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   

or you can use --help with kubectl create to check the available options.

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

Note:

  1. Info above is for v1.24.2 or below. This might differ with future releases.
  2. kubectl create token is added in version 1.24.
Related