Kubernetes PersistentVolumes PersistentVolumeClaims and Examples

92 篇文章 0 订阅
35 篇文章 0 订阅

在这里插入图片描述

Figure: PersistentVolumes, like cluster Nodes, do not belong to any namespace, unlike Pods and PersistentVolumeClaims

Access Modes

A PersistentVolume can be mounted on a host in any way supported by the resource provider.

The access modes are:

  • ReadWriteOnce – the volume can be mounted as read-write by a single node
  • ReadOnlyMany – the volume can be mounted read-only by many nodes
  • ReadWriteMany – the volume can be mounted as read-write by many nodes
Schedule

A PV can specify node affinity to define constraints that limit what nodes this volume can be accessed from. Pods that use a PV will only be scheduled to nodes that are selected by the node affinity.

pv

aep-pv-volume.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: aep-pv-volume
  labels:
    type: local
spec:
  capacity:
    storage: 4Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/pv/"


创建PV
kubectl apply -f aep-pv-volume.yaml

pvc

aep-pv-claim.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: aep-pv-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi

创建
kubectl apply -f aep-pv-claim.yaml

pod using pvc

kind: Pod
apiVersion: v1
metadata:
  name: aep-pv-pod
spec:
  volumes:
    - name: aep-pv-storage
      persistentVolumeClaim:
       claimName: aep-pv-claim

  containers:
    - name: aep-pv-container
      image: zhixingheyitian/sparkthrift:0425
      volumeMounts:
      - mountPath: "/mnt/pem1"
        name: aep-pv-storage

创建
kubectl apply -f aep-pv-pod.yaml

查看结果信息

aep-pv-claim
# kubectl describe pvc aep-pv-claim
Name:          aep-pv-claim
Namespace:     default
StorageClass:  
Status:        Bound
Volume:        aep-pv-volume
Labels:        <none>
Annotations:   kubectl.kubernetes.io/last-applied-configuration:
                 {"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"aep-pv-claim","namespace":"default"},"spec":{"acces...
               pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      4Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Events:        <none>
Mounted By:    aep-pv-pod
aep-pv-pod
# kubectl describe pod aep-pv-pod
Name:               aep-pv-pod
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               sr535/10.1.2.135
Start Time:         Tue, 14 May 2019 17:02:51 +0800
Labels:             <none>
Annotations:        kubectl.kubernetes.io/last-applied-configuration:
                      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"aep-pv-pod","namespace":"default"},"spec":{"containers":[{"image":"zh...
Status:             Running
IP:                 10.32.0.10
Containers:
  aep-pv-container:
    Container ID:   docker://2361d808acfbdd7d33f5612f3bf4a54b441164e7c93c7e5e4c16076cf00b421f
    Image:          zhixingheyitian/sparkthrift:0425
    Image ID:       docker-pullable://zhixingheyitian/sparkthrift@sha256:8695d876dc3bff9806302fb04f3469e29c8dab957b439d4326bcaff804b2abb8
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Tue, 14 May 2019 17:02:52 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /mnt/pem1 from aep-pv-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-qqr9h (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  aep-pv-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  aep-pv-claim
    ReadOnly:   false
  default-token-qqr9h:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-qqr9h
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值