1.随记
存储:
简单存储:EmptyDir HostPath NFS`
高级存储:pv pvc
配置存储:configMap Secret
------------------emptydir------------------------------
apiVersion: v1
kind: Pod
metadata:
name: emptydir-volume
namespace: uat
spec:
containers:
- name: emptydir-nginx
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
- name: emptydir-busybox
image: busybox:1.30
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","tail -f /logs/access.log"]
volumeMounts:
- name: logs-volume
mountPath: /logs
volumes:
- name: logs-volume
emptyDir: {}
kubectl logs -f emptydir-volume -n uat -c emptydir-busybox
查看emptydir-volume pod里面的emptydir-busybox容器的日志
------------------emptydir------------------------------
------------------hostPath------------------------------
apiVersion: v1
kind: Pod
metadata:
name: emptydir-volume
namespace: uat
spec:
containers:
- name: emptydir-nginx
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
- name: emptydir-busybox
image: busybox:1.30
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","tail -f /logs/access.log"]
volumeMounts:
- name: logs-volume
mountPath: /logs
volumes:
- name: logs-volume
hostPath:
path: /root/logs
type: DirectoryOrCreate
type:
DirectoryOrCreate: 目录存在就使用,不存在就先创建后使用
Directory: 目录必须存在
FileOrCreate: 文件存在就使用,不存在就先创建后使用
File: 文件必须使用
Socket:unix套接字必须存在
CharDevice: 字符设备必须存在
BlockDevice: 块设备必须存在
------------------hostPath------------------------------
------------------NFS------------------------------
yum install nfs-utils -y
mkdir /root/data/nfs -pv
vim /etc/exports
/root/data/nfs 192.168.56.0/24(rw,no_root_squash)
systemctl start nfs
apiVersion: v1
kind: Pod
metadata:
name: emptydir-volume
namespace: uat
spec:
containers:
- name: emptydir-nginx
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
- name: emptydir-busybox
image: busybox:1.30
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","tail -f /logs/access.log"]
volumeMounts:
- name: logs-volume
mountPath: /logs
volumes:
- name: logs-volume
nfs:
server: 192.168.56.108
path: /root/data/nfs
------------------NFS------------------------------
------------------------------pv---------------------
持久卷: 对底层存储的抽象,一般由k8s管理员进行管理
存储类型:
存储能力:
访问模式:ReadWriteOnce(RWO) 读写权限 但只能被单个节点挂载 不同底层支持的模式是不同的
ReadOnlyMany(ROM) 只读权限 可以被多个节点挂载
ReadWriteMany(RWX) 读写权限,可以被多个节点挂载
回收策略:Retain 保留
Recycle 回收
Delete: 删除
存储类别:pv可以通过storageClassname参数指定pv的一个存储类别
具有特定类别的pv只能和请求该类别的pvc进行绑定
未设定类别的pv只能与不请求任何类别的pvc进行绑定
status:
一个pv的生命周期
Available 可用 可用状态,还没有和任何pvc绑定
Bound 已绑定 也和pvc进行绑定
Released 已释放 对应的pvc已经删除了,但是资源还未被集群重新声明
Failed 失败 该pv已经被自动回收失败
more /etc/exports
/root/data/pv1 192.168.56.0/24(rw,no_root_squash)
/root/data/pv2 192.168.56.0/24(rw,no_root_squash)
/root/data/pv3 192.168.56.0/24(rw,no_root_squash)
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: voluem-pv1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv1
server: 192.168.56.108
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: voluem-pv2
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv2
server: 192.168.56.108
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: voluem-pv3
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv3
server: 192.168.56.108
kubectl get pv -o wide
------------------------------pv---------------------
------------------------------pvc---------------------
持久卷声明:用户向k8s发出的一种资源申请
对pv使用的申请
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: volume-pvc
namespace: uat
spec:
accessModes: #访问模式
selector:#采用标签对pv选择
storageClassName: #存储类别
resources: #空间
requests:
storage: 5Gi
------------configMap----------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: volume-configMap
namespace: uat
data:
info: |
username: slq
password: 123456789
------------configMap----------------------------
------------secret----------------------------
base64编码 一下
------------secret----------------------------