[CKA-Exercises]Storage

259 阅读2分钟
原文链接: blog.kii.la

Storage(7%) [占比 7%]

kubernetes.io > Documentation > Reference > kubectl CLI > kubectl Cheat Sheet

kubernetes.io > Documentation > Concepts > Storage > Volumes

kubernetes.io > Documentation > Concepts > Storage > Types of Volumes

kubernetes.io > Documentation > Concepts > Storage > Persistent Volumes

kubernetes.io > Documentation > Concepts > Storage > Persistent Volume Claims

Understand Persistent Volumes and know how to create them [理解持久卷,并知道他们如何创建]

show

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: Pod
metadata:
    name: persistent-pod
spec:
    containers:
    - name: alpine
      image: alpine
      command: ["/bin/sh", "-c"]
      args: ["shuf -i 0-100 -n 1 >> /opt/number.out;"]
      volumeMounts:
      - mountPath: /opt
        name: data-volume
    volumes:
    - name: data-volume
      hostPath:
        path: /data
        type: Directory
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: PersistentVolume
metadata:
    name pv-vol1
spec:
    accessModes:
        - ReadWriteOnce
    capacity:
        storage: 1Gi
    hostPath:
        path: /tmp/data

Understand access modes for volumes [理解卷的访问模式]

show - ReadWriteOnce: 卷可以由单个节点以读写的方式挂载 - ReadOnlyMany: 卷可以由许多节点以只读的方式挂载 - ReadWriteMany: 卷可以由许多节点以读写的方式挂载

Understand persistent volume claims primitive [理解持久卷声明的原语]

show

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: myclaim
spec:
    accessModes:
    - ReadWriteOnce
        persistentVolumeReclaimPolicy: Retain
    
    resources:
        requests:
            storage: 500Mi

持久卷回收策略: - Retain: 没有其他 Claim 可以 Claim 该卷 - Delete: 删除该卷 - Recycle: 删除数据,并使卷在次可用

1
2
$ kubectl get pvc
$ kubectl delete pvc myclaim
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: Pod
metadata:
    name: webapp
spec: 
    containers:
    - name: event-simulator
      image: kodecloud/event-simulator
      env:
      - name: Log_Handler
        value: file
      volumeMounts:
      - mountPath: /log
        name: log-volume
    volumes:
    - name: log-vol
      persistentVolumeClaim:
        claimName: claim-log-1

Understand Kubernetes Storage object [理解 Kubernetes 存储对象]

show Kubernetes 支持以下几种类型的卷: - awsElasticBlockStore - azureDisk - azureFile - cephfs - cinder - configMap - csi - downwardAPI - emptyDir - fc(fiber channel) - flexVolume - flocker - gcePersistentDisk - gitRepo(deprecated) - glusterfs - hostPath - iscsi - local - nfs - persistentVolumeClaim - projected - portworxVolume - quobyte - rbd - scaleIO - secret - storageos - vsphereVolume

Know how to configure applications with persistent storage

show - 创建持久性卷声明 - 在 Pod 中使用持久性卷声明