pod重啟,資料依然存在
1、找一台伺服器作為nfs服務端
(1)安裝nfs
yum install -y nfs-utils
(2)設定掛載路徑
vi /etc/exports
/data/nfs *(rw,no_root_squash)
(3)設定的掛載路徑首先保證有這個路徑,沒有則建立
mkdir data
mkdir nfs
2、在k8s集群node節點上安裝nfsyum install -y nfs-utils
3、在nfs伺服器啟動nfs服務systemctl start nfs
//檢視nfs程序
ps -ef | grep nfs
4、在k8s集群部署應用,使用nfs網路儲存mkdir pv
cd pv
vi nfs-nginx.yaml
kind: deployment
metadata:
name: nginx-dep1
spec:
replicas: 1
selector:
matchlabels:
template:
metadata:
labels:
spec:
containers:
- name: nginx
image: nginx
volumemounts:
- name: wwwroot
mountpath: /usr/share/nginx/html
ports:
- containerport: 80
volumes:
- name: wwwroot
nfs:
server: 192.168.44.134 #nfs伺服器ip
path: /data/nfs
kubectl describe pod (pod名稱)
//進入pod
kubectl exec -it (pod名稱) bash
ls /usr/share/nginx/html
kubectl expose deployment nginx-dep1 --port=80 --target-port=80 --type=nodeport
pv:持久化儲存(生產者)對儲存的資源進行抽象,對外提供可以呼叫的地方
pvc:持久化儲存呼叫(消費者)用於呼叫。不需要關心內部實現的細節
kind: deployment
metadata:
name: nginx-dep1
spec:
replicas: 3
selector:
matchlabels:
template:
metadata:
labels:
spec:
containers:
- name: nginx
image: nginx
volumemounts:
- name: wwwroot
mountpath: /usr/share/nginx/html
ports:
- containerport: 80
volumes:
- name: wwwroot
persistentvolumeclaim:
claimname: my-pvc
---apiversion: v1
kind: persistentvolumeclaim
metadata:
name: my-pvc
spec:
accessmodes:
- readwritemany
resources:
requests:
storage: 5gi
apiversion: v1
kind: persistentvolume
metadata:
name: my-pv
spec:
capacity:
storage: 5gi
accessmodes:
- readwritemany
nfs:
path: /k8s/nfs
server: 192.168.44.134
kubectl get pv,pvc
kubectl get pods
kubectl exec -it pod名稱 bash
k8s持久化儲存PV PVC部署
安裝nfs utils rpcbindyum install nfs utils rpcbind nfs utils所有節點都需要安裝 啟動systemctl restart rpcbind nfs編輯共享配置檔案 在主機節點編輯 vim etc exports寫入 mnt share rw 如果沒...
K8S持久化儲存PV PVC筆記
kubernetes 使用persistent volume和persistent volume claim 兩種api資源來管理儲存。可以通過兩種方式配置pv 靜態或動態。關於persistentvolume的訪問方式 在cli 命令列介面 中,訪問模式縮寫為 特別注意 卷只能一次使用一種訪問模式...
K8S 使用cephfs 作為持久化儲存
1 檢視ceph的key 進入ceph集群的管理主機 ceph auth get key client.admin base64 得到這個串,下面使用 2 k8s裡面新增乙個密碼 cat apiversion v1 kind secret metadata name ceph secret data...