关于k8s:k8s-存储随记

43次阅读

共计 3880 个字符,预计需要花费 10 分钟才能阅读完成。

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----------------------------

正文完
 0