k8s - 存储
ConfigMap
将配置文件已键值对的形式保存到ConfigMap 中, 并且可以在Pod 中以文件或者环境变量的形式使用。ConfigMap 可以存储不敏感的配置信息, 如程序的配置文件。
EmptyDir
是一个空目录, 在Pod 中存储临时数据, Pod 被删除的时候, 该目录也会被删除。
Local
将本地的文件系统目录或者文件映射到Pod 中的一个Volume 中, 可以用来在Pod 中共享数据或文件。
NFS
将网络上的一个多个NFS 共享目录挂载到Pod 中的Volume 中, 可以用来在多个Pod 之间共享数据。
Secret
将敏感信息以密文的形式保存在Secret 中, 并且可以在Pod 中以文件或者环境变量使用, 如密码, 证书。
`
apiVersion: v1
kind: Pod
metadata:
name: configmap-pod
spec:
containers:
- name: test
image: busybox:1.28
volumeMounts:
....
volumnes:
`
搭建nfs
yum install -y nfs-utils
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
执行以下命令, 启动
mkdir -p /nfs/data
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
exportfs -r
exportfs
配置nfs-client
showmount -e xxxxx
mkdir -p /nfs/data
mount -t nfs xxxxx:/nfs/data /nfs/data
Volumn 点我展开 / 折叠
PersistentVolumne
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv01-10m
spec:
capacity:
storage: 10M
accessModes:
-ReadWriteMany
storageClassName: nfs
nfs:
path: /nfs/data/01
server: 192.168.19.129
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv01-10m
spec:
capacity:
storage: 1Gi
accessModes:
-ReadWriteMany
storageClassName: nfs
nfs:
path: /nfs/data/01
server: 192.168.19.129
Deployment 点我展开 / 折叠
PersistentVolumne
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-pv-demo
name: nginx-pv-demo
spec:
replicas: 2
selector:
matchLables:
app: nginx-pv-demo
template:
metadata:
labels:
app: nginx-pv-demo
sepc:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: html
mountPath: /user/share/nginx/html
volumes:
- name: html
nfs:
server: 192.168.11.101
path: /nfs/data/nginx-pv
浙公网安备 33010602011771号