使用docker部署standalone cinder


版權:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接。如有問題,可以郵件:wangxu198709@gmail.com

 

背景

OpenStack社區一直在嘗試用Container技術來部署其各個組件,由此還發展出了kolla這個big tent項目,以及衍生項目kolla-ansible。

最近項目上有些調整,有了些自由時間,於是開始嘗試使用container方式部署OpenStack的組件,自然是從最熟悉的Cinder開始。

驚喜的發現Cinder項目自身就有一個簡單易上手的腳步,可以幫助理解以container部署Cinder的基本步驟和方式。

 [請在ROOT用戶下執行下面所有的命令,主要是docker和后面的local-attach都需要root或者sudo,直接使用root會少掉很多坑]

配置環境

首先clone下來cinder的源代碼:

git clone https://github.com/openstack/cinder

cd contrib/block-box/

然后就是安裝相關的依賴了,如make, docker,docker-compose

安裝make及相關包

sudo apt-get install build-essential

安裝docker

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

安裝docker-compose

https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-ubuntu-16-04

接下來就是build需要的docker image了

make base

這個過程中,會clone loci-cinder項目,如果遇到不能clone這個項目,你可以把loci-cinder項目clone到本地,然后修改目錄下的Makefile, 指向本地的loci-cinder就行。我就遇到這種問題,於是我做了如下修改

# git diff Makefile
diff --git a/contrib/block-box/Makefile b/contrib/block-box/Makefile
index ca173cc..ff60a56 100644
--- a/contrib/block-box/Makefile
+++ b/contrib/block-box/Makefile
@@ -1,12 +1,12 @@
 CINDER_BRANCH ?= master # master, stable/ocata, refs/changes/67/418167/1
 NAME_PREFIX ?= ""
-PLATFORM ?= debian # ubuntu, centos
+PLATFORM ?= ubuntu # debian, centos  TAG ?= latest
 
 all: base lvm devbox
 
 base:
-       docker build https://git.openstack.org/openstack/loci-cinder.git\#:$(PLATFORM) --tag cinder:$(TAG) --build-arg PROJECT_REF=$(CINDER_BRANCH)
+       docker build /root/containerized/loci-cinder/$(PLATFORM) --tag cinder:$(TAG) --build-arg PROJECT_REF=$(CINDER_BRANCH)  
 lvm:
        docker build -t cinder-lvm -f ./docker_files/Dockerfile.cinder-lvm .

Docker 的image build好過后,馬上就可以使用docker-compose命令啟動cinder的相關service了。

啟動docker的相關service

啟動之前你要按照自己的需求,修改目錄下的etc-cinder/cinder.confdocker-compose.yml文件,你可以參考我的gist文件 cinder.conf 和 docker-compose.yml

docker-compose -f docker-compose.yml up -d

docker-compose up -d
Creating network "blockbox_cindernet" with driver "bridge"
Creating blockbox_mariadb_1 ...
Creating blockbox_rabbitmq_1 ...
Creating blockbox_mariadb_1
Creating blockbox_mariadb_1 ... done
Creating blockbox_rabbitmq_1 ... done
Creating blockbox_cinder-api_1 ... done
Creating blockbox_cinder-scheduler_1 ...
Creating blockbox_cinder-scheduler_1 ... done
Creating blockbox_cinder-volume_1 ...
Creating blockbox_cinder-volume_1 ... done

啟動后,查看啟動的container,發現cinder-api服務啟動后又退出了。

docker ps

最后發現,cinder api的相關code有變動,需要在 當前目錄(contrib/block-box)的 etc-cinder/cinder.conf,加入下面綠色內容,cinder-api才能啟動成功,不讓會因為找不到key manager而退出:

[database]
connection = mysql+pymysql://cinder:password@mariadb/cinder?charset=utf8
[key_manager]
backend = cinder.keymgr.conf_key_mgr.ConfKeyManager

更改后,重新啟動所有docker containers

docker-compose -f docker-compose.yml down
docker-compose -f docker-compose.yml up -d

等一段時間,重新檢查所有的docker containers

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
67180a6e8056        cinder              "bash -c 'pip inst..."   38 seconds ago      Up 37 seconds                                                               blockbox_cinder-volume_1
d963f200be2a        cinder              "cinder-scheduler"       39 seconds ago      Up 38 seconds                                                               blockbox_cinder-scheduler_1
5166d688bbbd        cinder              "sh /init-scripts/..."   39 seconds ago      Up 38 seconds                                                               blockbox_cinder-api_1
a14757b40830        mariadb             "docker-entrypoint..."   40 seconds ago      Up 38 seconds       0.0.0.0:3306->3306/tcp                                  blockbox_mariadb_1
b23d77e10bad        rabbitmq            "docker-entrypoint..."   40 seconds ago      Up 38 seconds       4369/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:5672->5672/tcp   blockbox_rabbitmq_1

所有服務都啟動成功,后面使用cinder client請求cinder volume

TIPS: 可以使用下面命令查看docker里面的log。

docker logs <container id> -f 

 

使用cinder volume

安裝cinder client

接下來,在host上新建virtual environment並在venv中安裝最新的cinder client(只有最新的cinder client才有對noauth這種認證方式的支持)

# 創建venv
virtualenv pyenv

. pyenv/bin/activate
git clone https://github.com/openstack/python-cinderclient
pip install -e python-cinderclient

直接請求請求cinder api

(pyenv) peter@ubuntu16:~/pyenv$ cinder --os-auth-type=noauth --os-endpoint="http://127.0.0.1:8776/v3" --os-user-id=admin --os-tenant-id=admin list
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| ID                                   | Status    | Name   | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+
| 0fefa93d-475e-4cde-9246-cc5666fde991 | available | peter1 | 10   | -           | false    |             |
+--------------------------------------+-----------+--------+------+-------------+----------+-------------+

注意上面使用了--os-auth-type-noauth,這就是讓它直接請求cinder api,而不是先到keystone去認證。使用--os-endpoint=127.0.0.1:8776/v3是因為cinder-api同時暴露在了host上的這個端口上。

這樣,就可以使用很多cinder的命令,比如cinder create,list,snapshot-create等等,相關的storage就可以被這個standalone的cinder來管理了。

 

使用local-attach

volume創建好后,這里不能給到VM直接使用,因為沒有nova:)。尷尬,難道volume就不能給host用了嗎?當然可以。opestack社區提供了一個cinder client的plugin,讓volume可以直接attach給一個host

 

安裝python-brick-cinderclient-ext

 

git clone https://github.com/openstack/python-brick-cinderclient-ext
pip install -e python-brick-cinderclient-ext/

現在我把剛才創建的volume暴露給host使用(記得在host上安裝open-iscsi包)

cinder --os-auth-type=noauth --os-endpoint="http://127.0.0.1:8776/v3" --os-user-id=admin --os-tenant-id=admin local-attach 0fefa93d-475e-4cde-9246-cc5666fde991

注意,要保證--os-user-id和--os-tenant-id使用與create volume一樣的參數,否則會出現NotVolumeFound類似的error

 

參考文獻:

https://thenewstack.io/deploying-cinder-stand-alone-storage-service/

https://gorka.eguileor.com/standalone-cinder/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM