以下是使用ceph RBD作为persistent volume的例子:
A PersistentVolume
(PV) is a piece of networked storage in the cluster that has been provisioned by an administrator. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual pod that uses the PV. This API object captures the details of the implementation of the storage, be that NFS, iSCSI, or a cloud-provider-specific storage system.
A PersistentVolumeClaim
(PVC) is a request for storage by a user. It is similar to a pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., can be mounted once read/write or many times read-only).
1. 先创建image在pool里。
2. 创建 PV
[root@testnew kube]# cat pv_ceph.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: ceph-pv
spec:
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
rbd:
monitors:
- 10.0.200.11:6789
- 10.0.200.13:6789
- 10.0.200.14:6789
pool: kube
image: vol2
user: kube
secretRef:
name: ceph-secret
fsType: ext4
readOnly: false
persistentVolumeReclaimPolicy: Recycle
kubectl create -f pv_ceph.yaml
[root@testnew kube]# kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
ceph-pv 50Gi RWO Recycle Bound default/ceph-claim 4d
pvc-ac668f99-3b8b-11e7-8af9-fa163e01317b 20Gi RWO Delete Bound default/ceph-claim-sc 4d
3. 创建pvc
[root@testnew kube]# cat pvc_ceph.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ceph-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
note: pvc和pv是一一对应的,所以storage在这设20G没用
kubectl create -f pvc_ceph.yaml
[root@testnew kube]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
ceph-claim Bound ceph-pv 50Gi RWO 4d
4. 创建pod
[root@testnew kube]# cat frontend-pvc-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: frontendpvc
labels:
name: frontendpvc
spec:
replicas: 1
selector:
name: frontendpvc
template:
metadata:
labels:
name: frontendpvc
spec:
containers:
- name: frontendpvc
image: kubeguide/guestbook-php-frontend
env:
- name: GET_HOSTS_FROM
value: env
ports:
- containerPort: 80
volumeMounts:
- mountPath: /mnt/rbd
name: ceph-vol
volumes:
- name: ceph-vol
persistentVolumeClaim:
claimName: ceph-claim