如何使用OpenStack Cinder创建存储类并在Kubernetes Cluster中动态设置持久卷 [英] How to use OpenStack Cinder to create storage class and dynamically provision persistent volume in Kubernetes Cluster

查看:378
本文介绍了如何使用OpenStack Cinder创建存储类并在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中使用的煤渣呢?

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环境,并确保可以使用煤渣服务

背景

根据我的调查,组件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.

步骤

  1. 准备cloud.conf文件以包含您的openstack凭据
  1. Prepare cloud.conf file to contain your openstack creds

准备您的openstack凭据并保存为文件,例如,在kube-controller-manager所在的kubernetes控制面板中的/etc/kubernetes/cloud.conf.以下是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身份验证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

  1. 调整kube-controller-manager开始配置

此链接是kube-controller-manager的完整详细信息选项( https://kubernetes.io/docs/admin/kube-controller-manager/)

This link is a full detail options for 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 .

只有一个提示,如果您将静态Pod用于kube-controller-manager,请确保已将所有文件(例如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.

  1. 创建一个名为standard的存储类:
  1. Create a storageclass named 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 

  1. 创建一个PersistentVolumeClaim以使用StorageClass在Cinder中提供持久卷:

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.

这篇关于如何使用OpenStack Cinder创建存储类并在Kubernetes Cluster中动态设置持久卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆