Kubernetes 从kubectl生成persistentVolume、persistentVolumeClaim和storageClass正确的yaml文件的最快方法是什么?

Kubernetes 从kubectl生成persistentVolume、persistentVolumeClaim和storageClass正确的yaml文件的最快方法是什么?,kubernetes,kubectl,persistent-volumes,Kubernetes,Kubectl,Persistent Volumes,两年前,当我参加CKA考试时,我已经有了这个问题。当时我唯一能做的就是看k8s.io官方文档。现在只想通过纯kubectl cli生成pv/pvc/storageClass。我所寻找的与部署类似的逻辑,例如: $ 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

两年前,当我参加CKA考试时,我已经有了这个问题。当时我唯一能做的就是看k8s.io官方文档。现在只想通过纯kubectl cli生成pv/pvc/storageClass。我所寻找的与部署类似的逻辑,例如:

$ 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: {}
或类似逻辑来运行单个pod:

$ 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: {}
那么,为了生成pv/pvc/storageClass yaml,我应该键入什么?当前唯一的声明性最快方式:

cat <<EOF | kubectl create -f -
<PV / PVC / storageClass yaml goes here>
EOF

cat没有kubectl命令来创建PV、PVC和storage类等资源

从证书的角度来看,您必须在任务链接下查找PV、PVC和存储类

在任务链接下,大多数YAML都是相同的,目前,这是考试中最快的方法之一

TL;博士: 在考试之前,在Github目录(content/en/examples/pods)中的所有yaml文件中查看、添加书签并建立大脑索引。根据CKA课程,100%合法

然后在考试期间使用此表格:

kubectl create -f https://k8s.io/examples/pods/storage/pv-volume.yaml
如果需要编辑和应用:

# 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
故事: 事实上,在我找到自己的答案后,有一篇文章建议我将这些100%合法的页面加入书签:

请注意:

kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml
  • kubectl可以从URL创建对象
  • 原文指向哪里
  • 我还能从中受益吗
  • 然后,在挖掘“pods/storage/pv volume.yaml”代码上方的页面后,链接指向:

    直接寄往:


    缩短uri和http 301重定向也可以帮助考生在考试终端中轻松生成(而不是复制粘贴)。

    @Ming-sheeh-你得到我问题的答案了吗。如果是,请接受并投票。它给了我们动力。你说“你得到我问题的答案了吗?”?我的意思是,我的答案对你有帮助吗?