01 雲原生儲存概述(轉載)
阿新 • • 發佈:2022-12-01
目錄
【
【
雲原生儲存概述
kubernetes
資料持久化
鬆耦合的方式,pod與儲存分離,三種方式:
-
volume
:需要知道後端儲存的細節,對接難度大 -
PV/PVC
:管理員定義PV
,PersistentVolume
,使用者通過PVC使用PersistentVolumeClaim
-
storageclass
:靜態+動態,通過PVC
宣告使用的空間,自動建立PV
和後端驅動的對接
【儲存卷】
【PV
和PVC
】
【StorageClass
】
kubernetes
儲存對接
volume
定義
apiVersion: v1 kind: Pod metadata: name: volume-rbd-demo spec: containers: - name: pod-with-rbd image: nginx:1.7.9 imagePullPolicy: IfNotPresent ports: - name: www containerPort: 80 protocol: TCP volumeMounts: - name: rbd-demo mountPath: /data volumes: - name: rbd-demo rbd: monitors: - 10.254.100.101:6789 - 10.254.100.102:6789 - 10.254.100.103:6789 pool: kubernetes image: rbd.img fsType: ext4 user: kubernetes secretRef: name: ceph-secret
PV
和PVC
apiVersion: v1 kind: PersistentVolume metadata: name: rbd-demo spec: accessModes: - ReadWriteOnce capacity: storage: 10G rbd: monitors: - 10.254.100.101:6789 - 10.254.100.102:6789 - 10.254.100.103:6789 pool: kubernetes image: demo-1.img fsType: ext4 user: kubernetes secretRef: name: ceph-secret persistentVolumeReclaimPolicy: Retain storageClassName: rbd
PVC
呼叫PV
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-demo
spec:
accessModes:
- ReadWriteOnce
volumeName: rbd-demo
resources:
requests:
storage: 10G
storageClassName: rbd
Pod
中引用PVC
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
spec:
containers:
- name: demo
image: nginx:1.7.9
imagePullPolicy: IfNotPresent
ports:
- name: www
protocol: TCP
containerPort: 80
volumeMounts:
- name: rbd
mountPath: /data
volumes:
- name: rbd
persistentVolumeClaim:
claimName: pvc-demo
StorageClass
StorageClass
儲存定義
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-rbd-sc
provisioner: rbd.csi.ceph.com
parameters:
clusterID: 760da58c-0041-4525-a8ac-1118106312de
pool: kubernetes
csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
csi.storage.k8s.io/provisioner-secret-namespace: default
csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
csi.storage.k8s.io/node-stage-secret-namespace: default
imageFeatures: layering
reclaimPolicy: Delete
mountOptions:
- discard
使用者端直接使用靜態建立
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: raw-block-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Block
resources:
requests:
storage: 1Gi
storageClassName: csi-rbd-sc
使用者端直接使用靜態建立
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "csi-rbd-sc"
resources:
requests:
storage: 1Gi