两年前,当我参加CKA考试时,我已经有了这个问题。当时我只能看到k8s.io的官方文档。现在,我对通过纯kubectl生成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: {}
或者运行单个吊舱的类似逻辑:
$ 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
编辑:请注意,我看起来有任何快速的方法来生成正确的pv / pvc / storageClass模板,而不需要通过cli记住特定的语法,也不需要通过kubectl。
发布于 2021-05-03 16:40:04
TL;DR:
看,在考试前,将你的大脑建立在这个Github目录(内容/en/ exam /pods)的所有yaml文件中,并建立索引。根据CKA课程100%合法。
https://github.com/kubernetes/website/tree/master/content/en/examples/pods/storage/pv-volume.yaml
然后在考试中使用此表格:
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%的法律页面写在书签上:
https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#creating-a-cron-job
https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/
请注意:
kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml
然后,在挖掘上面的“pods/storage/pv-volme.yaml”代码后,链接指向:
直接涉及:
https://github.com/kubernetes/website/tree/master/content/en/examples/pods
因此,https://k8s.io是一个缩短的uri,也是一个http 301重定向到https://github.com/kubernetes/website/tree/master/content/en,以帮助考生容易产生(而不是复制-n-粘贴)在考试终端。
发布于 2021-04-19 08:19:29
没有kubectl命令来创建像PV、PVC和存储类这样的资源。
从证书的角度来看,您已经浏览了k8.io,并在任务链接下查找PV、PVC和存储类。在任务链接下,大多数YAML都是相同的,就目前而言,这是考试最快的方式之一。
https://stackoverflow.com/questions/67165380
复制