Use context: kubectl config use-context k8s-c1-H

Create a new PersistentVolume named safari-pv. It should have a capacity of 2Gi, accessMode ReadWriteOnce, hostPath /Volumes/Data and no storageClassName defined.

Next create a new PersistentVolumeClaim in Namespace project-tiger named safari-pvc . It should request 2Gi storage, accessMode ReadWriteOnce and should not define a storageClassName. The PVC should bound to the PV correctly.

Finally create a new Deployment safari in Namespace project-tiger which mounts that volume at /tmp/safari-data. The Pods of that Deployment should be of image httpd:2.4.41-alpine.


译文:

创建一个新的PersistentVolume,名为safari-pv。它的容量为2Gi,访问模式为ReadWriteOnce,主机路径为/Volumes/Data,不定义存储类别名称。

接下来在namespace project-tiger创建一个新的PersistentVolumeClaim,命名为safari-pvc。它应该请求2Gi存储,访问模式 ReadWriteOnce,并且不应该定义存储类名称。PVC应该正确地绑定到PV上。

最后在名字空间project-tiger中创建一个新的部署safari,将该卷挂载在/tmp/safari-data。该部署Pod的镜像是httpd:2.4.41-alpine


解答:

pv可参考 https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-pv

vim 6_pv.yaml

6_pv.yaml

# 6_pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
 name: safari-pv
spec:
 capacity:
  storage: 2Gi
 accessModes:
  - ReadWriteOnce
 hostPath:
  path: "/Volumes/Data"

创建pv

k -f 6_pv.yaml

pvc可参考 https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-pvc

vim 6_pvc.yaml

6_pvc.yaml

# 6_pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: safari-pvc
  namespace: project-tiger
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
     storage: 2Gi

创建pvc

k -f 6_pvc.yaml create

检查pv,pvc绑定情况

 k -n project-tiger get pv,pvc

file

创建一个部署并挂载卷,可以参考 https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-pod

k -n project-tiger create deploy safari \
  --image=httpd:2.4.41-alpine $do > 6_dep.yaml
vim 6_dep.yaml

6_dep.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: safari
  name: safari
  namespace: project-tiger
spec:
  replicas: 1
  selector:
    matchLabels:
      app: safari
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: safari
    spec:
      volumes:                                      # add
      - name: data                                  # add
        persistentVolumeClaim:                      # add
          claimName: safari-pvc                     # add
      containers:
      - image: httpd:2.4.41-alpine
        name: container
        volumeMounts:                               # add
        - name: data                                # add
          mountPath: /tmp/safari-data               # add

创建pod

k -f 6_dep.yaml create

检查pod挂载情况

 k -n project-tiger describe pod safari-xxx-xxx  | grep -i -A2 mounts

file


Killer.sh CKA模拟题目 汇总