前面连说了几篇与kubernetes相关的内容,这篇我们来说说docker registry。docker的registry与kubernetes本身并没有太直接的关系。但是任何使用到docker的地方,总少不了这玩艺儿。所以这篇博文我们专门来说一说如何使用开源的harbor来配置管理我们的私有registry。
harbor官方是这么描述harbor的:Harbor是可靠的企业级Registry服务器。企业用户可使用Harbor搭建私有容器Registry服务,提高生产效率和安全度,既可应用于生产环境,也可以在开发环境中使用。github地址:https://github.com/vmware/harbor
需要说明的是,由于harbor只支持registry v2的api,所以对docker的版本也是有要求的,至少得>=1.6.0。同时harbor的安装还依赖于docker-compose,当然官方也提供直接使用kubernetes部署的yml文件。所以其实我们可以想见,harbor的部署一定是以容器的形式来完成的
harbor共有六个容器组成:
harbor_ui:harbor的核心服务。
harbor_log:运行着rsyslog的容器,进行日志收集。
harbor_mysql:由官方mysql镜像构成的数据库容器
nginx:使用Nginx做反向代理
registry:官方的Docker registry
harbor_jobservice:Harbor的任务管理服务。
我这里的安装环境依然是基于centos 7.2。
首先安装docker-compose:
pip install docker-compose
下载docker的安装包:
git clone https://github.com/vmware/harbor
cd harbor/make/
修改配置文件harbor.cfg如下:
复制代码
hostname = myhub.xxx.com
ui_url_protocol = https
email_server = smtp.163.com
email_server_port = 25
email_username = xxx@163.com
email_password = xxxxx
email_from = admin <xxx@163.com>
email_ssl = false
harbor_admin_password = xxx
ssl_cert = /data/server/harbor/make/cert/xxx.com.crt
ssl_cert_key = /data/server/harbor/make/cert/xxx.com.key
复制代码
其中两个ssl证书文件需要自行申请或者直接使用自签名证书。生成自签名证书的方法,在这里不做相关说明。
修改docker-compose.yml文件
复制代码
cp docker-compose.tpl docker-compose.yml
vim docker-compose.yml
version: '2'
services:
log:
p_w_picpath: myhub.fdccloud.com/library/harbor-log
container_name: harbor-log
restart: always
volumes:
- /data/harbor/log/:/var/log/docker/
ports:
- 1514:514
registry:
p_w_picpath: myhub.fdccloud.com/library/registry:2.5.0
container_name: registry
restart: always
volumes:
- /data/registry:/storage
- ./common/config/registry/:/etc/registry/
environment:
- GODEBUG=netdns=cgo
command:
["serve", "/etc/registry/config.yml"]
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
mysql:
p_w_picpath: myhub.fdccloud.com/library/harbor-db
container_name: harbor-db
restart: always
volumes:
- /data/harbor/harbordb:/var/lib/mysql
env_file:
- ./common/config/db/env
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "mysql"
ui:
p_w_picpath: myhub.fdccloud.com/library/harbor-ui
container_name: harbor-ui
env_file:
- ./common/config/ui/env
restart: always
volumes:
- ./common/config/ui/app.conf:/etc/ui/app.conf
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem
- /data/harbor/harbor_storage:/harbor_storage
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "ui"
jobservice:
p_w_picpath: myhub.fdccloud.com/library/harbor-jobservice
container_name: harbor-jobservice
env_file:
- ./common/config/jobservice/env
restart: always
volumes:
- /data/harbor/job_logs:/var/log/jobs
- ./common/config/jobservice/app.conf:/etc/jobservice/app.conf
depends_on:
- ui
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
proxy:
p_w_picpath: myhub.fdccloud.com/library/nginx:1.11.5
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx
ports:
#- 80:80
- 443:443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
复制代码
创建映射的相关目录:
mkdir -p /data/harbor/{harbordb,harbor_storage,job_logs,log}
mkdir /data/registry
执行harbor安装并启动:
./install.sh
也可以通过如下方式启动:
./prepare
docker-compose -f docker-compose.yml up -d
harbor访问界面如下:
转载于:https://blog.51cto.com/sky66/1934001