如何在Kubernetes集群中使用OpenStack Cinder创建存储类并动态提供持久卷 [英] How to use OpenStack Cinder to create storage class and dynamically provision persistent volume in Kubernetes Cluster
问题描述
最近在练习 kubernetes 时,发现没有文档和示例专门解释如何在 kubernetes 中正确使用 cinder.
Recently when practicing kubernetes , I found there is no doc and example specifically explaining how to use cinder correctly in kubernetes.
那么如何设置在 kubernetes 中使用的 cinder 呢?
So how to setup cinder to be used in kubernetes ?
推荐答案
我做了一些实验并研究了如何使用 kubernetes 设置 cinder.找一个合适的来记录和分享.
I did some experiment and worked out how to setup cinder with kubernetes. Just find a suitable to document and share.
准备
- Kubernetes 集群
- openstack 环境并确保 cinder 服务可用
背景
根据我的调查,组件 kube-controller-manager
负责加载 Kubernetes 中的卷插件和相关插件.所以我们可以通过调整 kube-controller-manager
配置来使 cinder 可用.
From my investigation, component kube-controller-manager
is responsible for loading volume plugins and related in Kubernetes. So we could make cinder available by adjusting kube-controller-manager
configuration.
步骤
- 准备
cloud.conf
文件以包含您的 openstack 凭证
- Prepare
cloud.conf
file to contain your openstack creds
准备您的 openstack 凭证并保存为文件,例如 /etc/kubernetes/cloud.conf
位于 kube-controller-manager
所在的 kubernetes 控制面板中.以下是 cloud.conf
Prepare your openstack creds and saved as a file , for example /etc/kubernetes/cloud.conf
in kubernetes control panel which kube-controller-manager
locates. The following is example for cloud.conf
[Global]
auth-url=$your_openstack_auth_url
username=$your_openstack_user
password=$your_user_pw
region=$your_openstack_reigon
tenant-name=$your_project_name
domain-name=$your_domain_name
ca-file=$your_openstack_ca
大多数可以从您的 stackrc
文件中找到.并且 ca-file
项是可选的,具体取决于您的 openstack auth url 是 http
还是 https
Most could be found from your stackrc
file. And ca-file
item is optional, depending on if your openstack auth url is http
or https
- 调整
kube-controller-manager
启动配置
此链接是 kube-controller-manager
(https://kubernetes.io/docs/admin/kube-controller-manager/)
实际上我们应该根据您当前的参数添加两个额外的参数
Actually we should add two extra parameters based on your current one
--cloud-provider=openstack
--cloud-config=/etc/kubernetes/cloud.conf
启动kube-controller-manager
主要有两种方式:1)使用systemd 2)使用静态pod.
There are mainly two ways to start kube-controller-manager
: 1) using systemd 2) using static pod .
一个提示,如果您使用 kube-controller-manager
的静态 pod,请确保您已将所有文件(例如 cloud.conf 或 openstack ca 文件)安装到您的容器中.
Just one tips, if you are using static pod for kube-controller-manager
, make sure you have mount all files such as cloud.conf or openstack ca file into your container.
验证
我们将创建一个存储类,并使用该存储类动态创建持久卷.
We will create a storageclass, and use this storageclass to create persistent volume dynamically.
- 创建一个名为
standard
的存储类:
demo-sc.yml:
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: standard
annotations:
storageclass.beta.kubernetes.io/is-default-class: "true"
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: EnsureExists
provisioner: kubernetes.io/cinder
使用命令kubectl create -f demo-sc.yml
创建并使用命令kubectl get sc
验证是否创建正确
Using command kubectl create -f demo-sc.yml
to create and using command kubectl get sc
to verify if it created correctly
NAME TYPE
standard (default) kubernetes.io/cinder
- 创建一个 PersistentVolumeClaim 以在 Cinder 中使用 StorageClass 提供 Persistent Volume:
demo-pvc.yml:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: cinder-claim
annotations:
volume.beta.kubernetes.io/storage-class: "standard"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
通过kubectl create -f demo-pvc.yml
现在通过命令kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
cinder-claim Bound pvc-5dd3d62e-9204-11e7-bc43-fa163e0e0379 1Gi RWO standard 23h
在openstack环境下,通过命令cinder list | 检查grep pvc-5dd3d62e-9204-11e7-bc43-fa163e0e0379
And in openstack environment, checking by command cinder list | grep pvc-5dd3d62e-9204-11e7-bc43-fa163e0e0379
root@ds0114:~# cinder list | grep pvc-5dd3d62e-9204-11e7-bc43- fa163e0e0379
| ddd8066d-2e16-4cb2-a89e-cd9d5b99ef1b | available | kubernetes-dynamic- pvc-5dd3d62e-9204-11e7-bc43-fa163e0e0379 | 1 | CEPH_SSD | false | |
所以现在 StorageClass 在 Kubernetes 中使用 Cinder 运行良好.
So now StorageClass is working well using Cinder in Kubernetes.
这篇关于如何在Kubernetes集群中使用OpenStack Cinder创建存储类并动态提供持久卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!