💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
**阿里云上提供镜像仓库服务,目前可以免费使用,如果需要自己搭建私有仓库,请看本章。** **关于Harbor** docker官方提供了registry镜像仓库,在registry基础上vmware公司做了进一步完善,开发了harbor仓库,其底层仍使用resgistry作为镜像存储,增加了UI界面,权限控制,审计等功能,harbor 官方只提供了 docker-compose 部署方式。 **安装docker-compose** git地址: https://github.com/docker/compose/releases 当前最新版本为1.21.2(2018.6.12): ~~~ curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose --version #查看安装是否程成功 ~~~ **安装Harbor** git地址:https://github.com/vmware/harbor/releases 官网地址:http://harbor.orientsoft.cn/ 当前版本为1.5.0(2018.06.12) 从官网地址下载offline离线安装包 ~~~ mkdir /usr/local/bin/harbor && cd /usr/local/bin/harbor wget http://harbor.orientsoft.cn/harbor-v1.5.0/harbor-offline-installer-v1.5.0.tgz tar -zxvf harbor-offline-installer-v1.5.0.tgz cd harbor docker load -i harbor.v1.5.0.tar.gz #将镜像导入docker images ~~~ 创建TLS证书 创建TLS证书 默认使用https方式访问需要证书支持,如果使用http访问可以忽略此步骤,但docker配置文件中需要设置仓库信任。 cd /usr/local/bin/harbor ~~~ cat > harbor-csr.json <<EOF { "CN": "harbor", "hosts": [ "127.0.0.1", "image.xx.cn" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "BeiJing", "L": "BeiJing", "O": "k8s", "OU": "System" } ] } EOF ~~~ hosts :填写你的仓库域名 **生成 harbor 证书和私钥** 注: 登录到**第二章**中创建证书的服务器,ca.pem,ca-key.pem,ca-config.json 已经创建过,这里还是使用此ca来签名harbor证书; ~~~ cd /etc/kubernetes/ssl/ cfssl gencert -ca=/etc/kubernetes/ssl/ca.pem -ca-key=/etc/kubernetes/ssl/ca-key.pem -config=/etc/kubernetes/ssl/ca-config.json -profile=kubernetes harbor-csr.json | cfssljson -bare harbor ls harbor* harbor.csr harbor-csr.json harbor-key.pem harbor.pem mkdir -p /etc/harbor/ssl cp harbor*.pem /etc/harbor/ssl #将生成的证书拷贝到harbor服务器的此目录下 ~~~ **修改Harbor配置文件** ~~~ cd harbor vim harbor.cfg #证书中的域名 hostname = image.xx.cn #设置为https方式 ui_url_protocol = https #证书路径 ssl_cert = /etc/harbor/ssl/harbor.pem ssl_cert_key = /etc/harbor/ssl/harbor-key.pem #注意:/data路径不要更改 secretkey_path = /data #启动Harbor后,管理员UI登录的密码 harbor_admin_password = Harbor@2018 #用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员) project_creation_restriction = adminonly ~~~ **启动 Harbor** 启动 Harbor 修改完配置文件后,在的当前目录执行./install.sh,Harbor服务就会根据当期目录下的docker-compose.yml开始下载依赖的镜像,上面以后手动导入到docker images ,检测并按照顺序依次启动各个服务。 `./install.sh` ![](https://box.kancloud.cn/5035b6969a3e3c9f32b37120f147c015_630x504.png) ![](https://box.kancloud.cn/79d6fd63da52f616b5e006d2e4b102ce_631x411.png) ![](https://box.kancloud.cn/0b1d10f4b542377097afb71c555cbc60_923x175.png) Harbor共由七个容器组成: harbor-adminserver:harbor系统管理服务 harbor-db: 由官方mysql镜像构成的数据库容器 harbor-jobservice:harbor的任务管理服务 harbor-log:harbor的日志收集、管理服务 harbor-ui:harbor的web页面服务 nginx:负责流量转发和安全验证 registry:官方的Docker registry,负责保存镜像 **访问Harbor UI** 浏览器访问 https://域名 账号admin 密码 Harbor@2018 ~~~ # 日志目录 ls /var/log/harbor/2018-xx-xx/ adminserver.log jobservice.log mysql.log proxy.log registry.log ui.log # 数据目录,包括数据库、镜像仓库 ls /data/ ca_download config database job_logs registry secretkey ~~~ **使用Harbor仓库** docker login image.xxx.cn Username: admin Password: Harbor@2018 docker tag {image} image.xxx.cn/{library}/{image:} #上传镜像前要先打tag,格式如此 docker push image.xxx.cn/{library}/{image:} #上传到仓库 **在k8s中使用harbor** 将签署 harbor 证书的 ca 证书拷贝到所有k8s节点 /etc/docker/certs.d/你的域名 目录下并改名为ca.crt; ~~~ mkdir -p /etc/docker/certs.d/image.xx.cn cp /etc/kubernetes/ssl/ca.pem /etc/docker/certs.d/image.xx.cn/ca.crt ~~~ **创建包含harbor密码的secret** ~~~ kubectl create secret docker-registry default-registry --docker-server=image.xxx.cn --docker-username=admin --docker-password=Harbor@2018 --docker-email=admin@xx.cn ~~~ default-registry: 指定密钥的键名称, 可自行定义 --docker-server: 指定docker仓库地址 --docker-username: 指定docker仓库账号 --docker-password: 指定docker仓库密码 --docker-email: 邮箱 **注**: 该密钥只能在对应namespace使用, 也就是这里的default, 如果需要用到其他namespace, 比如说kube-system, 就需要在生成的时候指定参数 -n kube-system; **yaml中加入imagePullSecrets参数** ~~~ imagePullSecrets: - name: default-registry #上步创建的secret ~~~ 注:imagePullSecretsfang参数的位置和containers的缩进一致; **harbor启动和关闭** ~~~ docker-compose down -v # 停止 harbor docker-compose up -d # 启动 harbor vim harbor.cfg # 修改harbor配置文件 ./prepare # 修改后需要更新到 docker-compose.yml 文件 Clearing the configuration file: ./common/config/ui/app.conf Clearing the configuration file: ./common/config/ui/env Clearing the configuration file: ./common/config/ui/private_key.pem ..... ~~~ 可以利用harbor的镜像复制功能,将镜像复制到另外一台harbor服务器上,实现harbor的高可用。