宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述#yyds干货盘点#--k8s-存储相关的知识,希望能为你提供帮助。
容器部署过程中一般有以下三种数据:
- 启动时需要的初始数据,可以是配置文件
- 启动过程中产生的临时数据,该临时数据需要多个容器间共享
- 启动过程中产生的持久化数据
volumes:
启动依赖数据:configmap secret
临时存储数据:emptyDir hostPath
持久化数据:nfs cephfs GlutserFS cloud等
存储系统与应用系统区分开,单独资源对象, 它不直接和Pod发生关系,通过另一个资源对象PersistentVolumeClaim来绑定关联,生命周期与POD关联。
举例几个典型的类型:
emptyDir
apiVersion: v1
kind: Pod
metadata:
name: demo
labels:
purpose: demonstrate-envars
spec:
volumes: - name: volume1
emptyDir:{}
containers: - name: demo1
image: busybox
command: [sh,-c,sleep 5000]
volumeMounts: - mountPath:/xx
name: volume1 - name: demo2
image: busybox
command: [sh,-c,sleep 5000]
volumeMounts: - mountPath:/xx
name: volume1
hostpath
apiVersion: v1
kind: Pod
metadata:
name: demo
labels:
purpose: demonstrate-envars
spec:
volumes: - name: volume1
hostPath:
path:/zz
containers: - name: demo1
image: busybox
command: [sh,-c,sleep 5000]
volumeMounts: - mountPath:/xx
name: volume1 - name: demo2
image: busybox
command: [sh,-c,sleep 5000]
volumeMounts: - mountPath:/xx
name: volume1
NFS
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
spec:
volumes: - name: nfs
nfs:
server: 192.168.26.102
path:"/123" containers: - image: nginx
name: nginx
volumeMounts: - name: nfs
mountPath:"/usr/share/nginx/html"
issci存储
apiVersion: v1
kind: Pod
metadata:
name: iscsipd
spec:
containers: - name: iscsipd-rw
image: nginx
volumeMounts: - mountPath:"/mnt/iscsipd"
name: iscsipd-rw
volumes: - name: iscsipd-rw
iscsi:
targetPortal: 192.168.26.102:3260
iqn: iqn.2018-10.cc.rhce:disk
lun: 0
fsType: xfs
readOnly: fals
主要来讲讲持久化存储PV:
PV的预制创建有两种模式:静态模式和动态模式。
静态模式:除创建PVC外,还需手动创建PV。
动态模式:只需创建PVC,系统根据PVC自动创建PV。
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
mountOptions:
- hard
- nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
那么对于用户来说更关心的是什么呢?存储访问模式,存储大小,甚至类型适配能力等。这就需要我们申明存储,所以引入持久化存储申明(PVC)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-pv-claim
labels:
app: redis
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName:sata
【#yyds干货盘点#--k8s-存储】下面放一个示例,当然你也可以k8s官网文档去看。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: sata
volume.beta.kubernetes.io/storage-provisioner:
flexvolume-huawei.com/fuxivol
labels:
failure-domain.beta.kubernetes.io/region:
southchina
failure-domain.beta.kubernetes.io/zone: kvmxen.dc1
name: test
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
spec:
containers:
- image: nginx:latest
imagePullPolicy: IfNotPresent
name: container-0
volumeMounts:
- name: test
mountPath: /tmp
volumes:
- persistentVolumeClaim:
claimName: test
name: test
PS:代码块YAML格式缩进有问题。
推荐阅读
- kubernetes port-forward
- #yyds干货盘点# MySQL数据库语句进阶--随手笔记
- 面试官(手撕LRU缓存了解一下#2021年底大盘点#)
- MySQL性能测试之insert&deleteFunTester框架#yyds干货盘点#
- Python包管理 pip教程 | 解决用pip更新pip失败 #yyds干货盘点#
- #私藏项目实操分享#Maven实战技巧「插件使用专题」Maven-Archetype插件创建自定义maven项目骨架
- Go 语言入门很简单 -- 12. Go 方法 #私藏项目实操分享#
- #私藏项目实操分享# SAP 软件的精髓之一(各种各样的决定机制 - Determination Logic)
- 大厂高频面试题Spring Bean生命周期最详解