硬件 | 最低配置 | 推荐配置 |
---|---|---|
处理器 | 2 CPU | 4 CPU |
内存 | 4GB | 8GB |
硬盘 | 40GB | 160GB |
软件 | 版本 | 说明 |
---|---|---|
Docker | 17.03.0-ce 或更高 | |
Docker Compose | 1.18.0 或更高 | |
Openssl | 首选最新版本 | 为Harbor生成证书和密钥 |
官方安装教程
goharbor 官方下载地址
安装Docker
安装 Docker-Compose
为了简单,我选择了在线安装
[root@k8s-master setup]# pwd
/home/deploy/setup
[root@k8s-master setup]# wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.0.tgz
[root@k8s-master setup]#
[root@k8s-master setup]# tar -zxvf harbor-online-installer-v1.8.0.tgz
[root@k8s-master setup]#
[root@k8s-master setup]# ll harbor
total 32
-rw-r--r-- 1 root root 4531 Jun 6 09:58 harbor.yml
-rwxr-xr-x 1 root root 5088 May 21 15:59 install.sh
-rw-r--r-- 1 root root 11347 May 21 15:59 LICENSE
-rwxr-xr-x 1 root root 1654 May 21 15:59 prepare
[root@k8s-master setup]#
为了简单安装部署,这里只修改必填项
[root@k8s-master harbor]# vim harbor.yml
# 修改域名 或 IP地址
hostname: k8s.dev-share.top
# 数据存储目录
data_volume: /home/harbordata
# 访问接口
http:
port: 80
# 用户密码
harbor_admin_password: Harbor12345
# 数据库密码
database:
password: root123
[root@k8s-master harbor]#
[root@k8s-master harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.0
Note: docker-compose version: 1.18.0
[Step 1]: preparing environment ...
# 省略
......
Creating harbor-log ... done
Status: Downloaded newer image for goharbor/harbor-jobservice:v1.8.0
Pulling proxy (goharbor/nginx-photon:v1.8.0)...
v1.8.0: Pulling from goharbor/nginx-photon
Creating registryctl ... done
Creating harbor-core ... done
Digest: sha256:9c7c9ca3d34e5872743577ce911cabce9965935261f3b53de4196ce394504799
Creating harbor-portal ... done
Creating nginx ... done
Creating registry ...
Creating redis ...
Creating harbor-db ...
Creating registryctl ...
Creating harbor-core ...
Creating harbor-jobservice ...
Creating harbor-portal ...
Creating nginx ...
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://k8s.dev-share.top.
For more details, please visit https://github.com/goharbor/harbor .
[root@k8s-master harbor]#
http://k8s.dev-share.top
用户名:admin
用户密码:Harbor12345
执行 docker push 的时候必需要登录到私有仓库
# 不登录不能 push
[root@k8s-master ~]# docker login k8s.dev-share.top -u admin
Password:Harbor12345
Login Succeeded
[root@k8s-master ~]#
[root@k8s-master harbor]#
[root@k8s-master harbor]# pwd
/home/deploy/setup/harbor
[root@k8s-master harbor]#
# 启动
[root@k8s-master harbor]# docker-compose start
# 停止
[root@k8s-master harbor]# docker-compose stop
# 重新创建并启动Harbor的实例
[root@k8s-master harbor]# docker-compose up -d
# 删除Harbor的容器,同时将图像数据和Harbor的数据库文件保存在文件系统上
[root@k8s-master harbor]# docker-compose down -v
执行 docker pull 的时候需要指定 仓库地址
[root@k8s-master ~]# cat > /etc/docker/daemon.json << EOF
{
# http连接,非加密连接,数据传输不安全,使用相对简单
# 私服地址
"insecure-registries": ["http://k8s.dev-share.top"],
# 远程镜像代理地址,与Harbor无关
"registry-mirrors": ["http://f1361db2.m.daocloud.io"]
}
EOF
[root@k8s-master ~]#
分为两步
docker tag SOURCE_IMAGE[:TAG] k8s.dev-share.top/library/IMAGE[:TAG]
docker push k8s.dev-share.top/library/IMAGE[:TAG]
接下来在如下示例当中实现,将本地的 node.js镜像 推送到远程的 私服仓库
[root@k8s-master ~]# docker images | grep node
node
[root@k8s-master ~]#
[root@k8s-master ~]# docker push k8s.dev-share.top/library/node:slim
The push refers to repository [k8s.dev-share.top/library/node]
daade46d532d: Pushed
46b67135288b: Pushed
715cf255d73f: Pushed
aa5a12ea4279: Pushed
6270adb5794c: Pushed
slim: digest: sha256:1b5871385c87ed5cc64e6a6f2a4b789a03266d29b4a0c72c4a740ed67f29286e size: 1367
[root@k8s-master ~]#
换到节点服务器测试,从远程私有仓库进行拉取
[root@k8s-node1 ~]# docker pull k8s.dev-share.top/library/node:slim
Error response from daemon: Get https://k8s.dev-share.top/v2/: dial tcp 47.92.200.41:443: getsockopt: connection refused
# 子节点也需要配置代理地址,这个操作可以使用 ansible批量执行
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# cat > /etc/docker/daemon.json << EOF
{
"insecure-registries": ["http://k8s.dev-share.top"],
"registry-mirrors": ["https://dhq9bx4f.mirror.aliyuncs.com"]
}
EOF
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# systemctl daemon-reload
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# systemctl reload docker
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# docker pull k8s.dev-share.top/library/node:slim
slim: Pulling from library/node
743f2d6c1f65: Pull complete
89252b028f01: Pull complete
a4c96ce39a15: Pull complete
b3d04fa69e29: Pull complete
6194decb3876: Pull complete
Digest: sha256:1b5871385c87ed5cc64e6a6f2a4b789a03266d29b4a0c72c4a740ed67f29286e
Status: Downloaded newer image for k8s.dev-share.top/library/node:slim
[root@k8s-node1 ~]#
[root@k8s-node1 ~]# docker images | grep node
k8s.dev-share.top/library/node slim d9bfca6c7741 7 days ago 150MB
[root@k8s-node1 ~]#