|NO.Z.00024|——————————|CloudNative|——|Kubernetes&持久化存储.V02|——|PV/PVC|

一、持久化存储pv/pvc

二、持久化存储pv/pvc实验
### --- 删除历史创建

[root@k8s-master pv]# kubectl delete -f nfs-nginx.yaml 
deployment.apps "nginx-dep1" deleted
### --- 创建一个pvc和pv

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-dep1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    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
### --- 执行pvc

[root@k8s-master pv]# kubectl apply -f pvc.yaml     
deployment.apps/nginx-dep1 created
persistentvolumeclaim/my-pvc created
[root@k8s-master pv]# kubectl get pods
nginx-dep1-58b7bf955f-n2jn7                     0/1     Running     0          34s
nginx-dep1-58b7bf955f-s4v79                     0/1     Running     0          37s
nginx-dep1-58b7bf955f-tlprc                     0/1     Running     0          34s

[root@k8s-master pv]# kubectl apply -f pv.yaml 
pdeployment.apps/nginx-dep1 created
persistentvolumeclaim/my-pvc created
### --- pv里面绑定了PVC

[root@k8s-master pv]# kubectl get pv,pvc            
NAME                     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM            STORAGECLASS   REASON   AGE
persistentvolume/my-pv   5Gi        RWX            Retain           Bound    default/my-pvc                           44s

NAME                           STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/my-pvc   Bound    my-pv    5Gi        RWX                           2m7s
### --- 进入到服务查看

[root@k8s-master pv]# kubectl exec -it nginx-dep1-58b7bf955f-n2jn7 bash
root@nginx-dep1-58b7bf955f-n2jn7:/# ls /usr/share/nginx/html
index.html

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(29)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示