<p>Two years ago while I took CKA exam, I already have this question. At that time I only could do was to see k8s.io official documentation. Now just curious on generating pv / pvc / storageClass via pure kubectl cli. What I look for is similar to the similar logic as deployment, for example:</p>
<pre><code>$ kubectl create deploy test --image=nginx --port=80 --dry-run -o yaml
W0419 23:54:11.092265   76572 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: test
  name: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}
</code></pre>
<p>Or similar logic to run a single pod:</p>
<pre><code>$ kubectl run test-pod --image=nginx --port=80 --dry-run -o yaml
W0419 23:56:29.174692   76654 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: test-pod
  name: test-pod
spec:
  containers:
  - image: nginx
    name: test-pod
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
</code></pre>
<p>So what should I type in order to generate pv / pvc / storageClass yaml? The current only declarative fastest way:</p>
<pre><code>cat &lt;&lt;EOF | kubectl create -f -
&lt;PV / PVC / storageClass yaml goes here&gt;
EOF
</code></pre>
<p>Edited: Please note that I look any fast way to generate correct pv / pvc / storageClass template without remembering specific syntax thru cli, and not necessary via kubectl.</p>

<h2>TL;DR:</h2>
<p>Look, bookmark and build index your brain in all yaml files in this Github directory (content/en/examples/pods) before the exam. 100% legal according to CKA curriculum.</p>
<p><a href="https://github.com/kubernetes/website/tree/master/content/en/examples/pods/storage/pv-volume.yaml" rel="nofollow noreferrer">https://github.com/kubernetes/website/tree/master/content/en/examples/pods/storage/pv-volume.yaml</a></p>
<p>Then use this form during exam:</p>
<pre><code>kubectl create -f https://k8s.io/examples/pods/storage/pv-volume.yaml
</code></pre>
<p>In case you need edit and apply:</p>
<pre><code># curl
curl -sL https://k8s.io/examples/pods/storage/pv-volume.yaml -o /your/path/pv-volume.yaml
# wget
wget -O /your/path/pv-volume.yaml https://k8s.io/examples/pods/storage/pv-volume.yaml

vi /your/path/pv-volume.yaml
kubectl apply -f /your/path/pv-volume.yaml
</code></pre>
<h2>Story:</h2>
<p>Actually after look around for my own answer, there's an article floating around that suggest me to bookmark these 100% legal pages:</p>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume</a></p>
<p><a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#creating-a-cron-job" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#creating-a-cron-job</a></p>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/</a></p>
<p>Note that:</p>
<pre><code>kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml
</code></pre>
<ol>
<li>kubectl could create objects from URL</li>
<li>Where is the original <a href="https://k8s.io" rel="nofollow noreferrer">https://k8s.io</a> pointing to?</li>
<li>What else I could benefit from?</li>
</ol>
<p>Then after digging up the page above &quot;pods/storage/pv-volume.yaml&quot; code, the link points to:</p>
<p><a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/storage/pv-volume.yaml" rel="nofollow noreferrer">https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/storage/pv-volume.yaml</a></p>
<p>Which direct to:</p>
<p><a href="https://github.com/kubernetes/website/tree/master/content/en/examples/pods" rel="nofollow noreferrer">https://github.com/kubernetes/website/tree/master/content/en/examples/pods</a></p>
<p>So <a href="https://k8s.io" rel="nofollow noreferrer">https://k8s.io</a> is a shorten uri as well as a http 301 redirect to <a href="https://github.com/kubernetes/website/tree/master/content/en" rel="nofollow noreferrer">https://github.com/kubernetes/website/tree/master/content/en</a> to help the exam candidate easy to produce (not copy-n-paste) in the exam terminal.</p>
