题目要求
- 在 node02 节点上创建一个文件 /opt/KDSP00101/data/index.html ,内容为 WEPKEY=7789
- 使用 hostPath 创建一个名为 task-pv-volume 的 PersistentVolume ,并分配 2Gi 容量,指定该卷位于集群节点上的 /opt/KDSP00101/data ,访问模式 ReadWriteOnce 。它应该为 PersistentVolume 定义 StorageClass 名称为 keys ,它将被用来绑定 PersistentVolumeClaim 请求到这个 PersistenetVolume 。
- 创建一个名为 task-pv-claim 的 PersistentVolumeClaim ,请求容量 200Mi ,并指定访问模式 ReadWriteOnce
- 创建一个 pod,使用 PersistentVolmeClaim 作为一个卷,带有一个标签 app:my-storage-app ,将卷挂载到 pod 内的 /usr/share/nginx/html
参考
https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 2Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/**data**"
|
解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| sudo mkdir -p /opt/KDSP00101/data/ echo "**WEPKEY=7789**" > **/opt/KDSP00101/data/index.html**
cat task-pv-volume.yaml apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: **keys** capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "**/opt/KDSP00101/data**"
kubectl apply -f task-pv-volume.yaml
cat task-pvc-volume.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: task-pv-claim spec: storageClassName: keys accessModes: - ReadWriteOnce resources: requests: storage: **200Mi**
kubectl apply -f task-pvc-volume.yaml ****
kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE task-pv-claim Bound task-pv-volume 10Gi RWO keys <unset> 7s
cat test-pvc-pod.yaml apiVersion: v1 kind: Pod metadata: name: task-pv-pod labels: app: **my-storage-app** spec: volumes: - name: task-pv-storage persistentVolumeClaim: claimName: task-pv-claim containers: - name: task-pv-container image: nginx ports: - containerPort: 80 name: "http-server" volumeMounts: - mountPath: "/usr/share/nginx/html" name: task-pv-storage
kubectl appp -f test-pvc-pod.yaml
|