kubernetes的ceph RBD volume(5): 创建动态的volume绑定随replica scale的扩容和缩容的pod
有些需求需要有绑定的动态的volume, 当scale pod时。下面是一个例子,使用stateful来创建pod和动态的volume.1. 先建立storage class, 这个是ceph的[root@testnew kube]# cat storageclass_ceph.yamlapiVersion: storage.k8s.io/v1beta1kind: StorageC
有些需求需要有绑定的动态的volume, 当scale pod时。下面是一个例子,使用stateful来创建pod和动态的volume.
1. 先建立storage class, 这个是ceph的
[root@testnew kube]# cat storageclass_ceph.yaml
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: kubepool
annotations:
storageclass.beta.kubernetes.io/is-default-class: 'true'
provisioner: kubernetes.io/rbd
parameters:
monitors: 10.0.200.11:6789
adminId: kube
adminSecretName: ceph-secret
adminSecretNamespace: default
pool: kube
userId: kube
userSecretName: ceph-secret
2. 创建statefulSet
[root@testnew kube]# cat mango_statefull.yaml
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
command:
- mongod
- "--replSet"
- rs0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "kubepool"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
3. 创建service:
[root@testnew kube]# cat mango_service.yaml
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
4. 检查
[root@testdisk ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
mongo-0 2/2 Running 0 1h
mongo-1 2/2 Running 0 1h
mongo-2 2/2 Running 0 1h
[root@testdisk ~]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
mongo-persistent-storage-mongo-0 Bound pvc-51360827-ad90-11e7-ab3b-fa163e01317b 1Gi RWO 1h
mongo-persistent-storage-mongo-1 Bound pvc-513d5857-ad90-11e7-ab3b-fa163e01317b 1Gi RWO 1h
mongo-persistent-storage-mongo-2 Bound pvc-514625d2-ad90-11e7-ab3b-fa163e01317b 1Gi RWO 1h
[root@testdisk ~]# kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
pvc-51360827-ad90-11e7-ab3b-fa163e01317b 1Gi RWO Delete Bound default/mongo-persistent-storage-mongo-0 1h
pvc-513d5857-ad90-11e7-ab3b-fa163e01317b 1Gi RWO Delete Bound default/mongo-persistent-storage-mongo-1 1h
pvc-514625d2-ad90-11e7-ab3b-fa163e01317b 1Gi RWO Delete Bound default/mongo-persistent-storage-mongo-2 1h
===========================
DNS name is:
kubectl scale --replicas=5 statefulset mongo
|
Delete the StatefulSet:
kubectl delete statefulset mongo
|
kubectl delete svc mongo
|
kubectl delete pvc -l role=mongo
|
更多推荐
所有评论(0)