天行健,君子以自强不息;地势坤,君子以厚德载物。
每个人都有惰性,但不断学习是好好生活的根本,共勉!
文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。
K8S部署Harbor三部曲:
K8S部署Harbor(三部曲之一:配置)
K8S部署Harbor(三部曲之二:部署)本篇
K8S部署Harbor(三部曲之三:使用)
本篇是在k8s集群的master节点中部署harbor
首先在服务器当前根目录下创建harbor文件夹用于存储压缩文件
mkdir -p /harbor
将下载的安装包上传到服务器的/harbor文件夹中(可用ftp工具或者oss工具下载文件)
我这里是先将压缩包上传到oss然后再使用oss工具下载到服务器中的harbor文件夹中
可参考上方oss工具链接,操作如下
ossutil cp oss://com-hs-dev/hslb/34_Harbor_installer_tgz/harbor-offline-installer-v2.10.0.tgz /harbor/
ls /harbor
解压文件,解压到指定目录/opt目录下
tar -zxvf /harbor/harbor-offline-installer-v2.10.0.tgz -C /opt
解压后/opt目录下会多出一个harbor文件夹,harbor相关文件都在该文件夹中,共六个文件
ls /opt/harbor/
配置harbor.yml文件中的参数,主要是端口号、IP地址、证书秘钥、数据存储位置的配置
文件夹中有harbor.yml.tmpl模板文件,将其复制为harbor.yml,后续我们使用的就是这个文件
cp /opt/harbor/harbor.yml.tmpl /opt/harbor/harbor.yml
修改IP地址、http和https对应的端口号、证书位置路径、数据目录
vim /opt/harbor/harbor.yml
修改如下:
hostname
域名修改为自己要安装harbor的服务器的ip
http
端口修改为8800
https
端口修改为8443
证书位置修改
certificate:
证书路径修改为/harbor/certs/ca.crt
private_key:
秘钥路径修改为/harbor/certs/ca.key
harbor_admin_password:
默认Harbor密码,不修改,就用默认的Harbor12345
data_value:
修改为/data/harbor
,这里默认为/data
,建议修改一下,我这里没改,是因为我忘了,当然后续也可以改了之后重启harbor
注
:如果只用http访问的施主可将https对应部分注释掉,因为配置https后,即使你以http请求访问也会跳转到https
修改后截图
修改后Esc
退出编辑,shift+zz
快捷保存退出
通过prepare文件来执行命令生成Harbor所需配置文件
进入/opt/harbor目录
cd /opt/harbor
./prepare
执行命令后输出的代码如下
[root@k8s-master ~]# cd /opt/harbor
[root@k8s-master harbor]# ./prepare
prepare base dir is set to /opt/harbor
Unable to find image 'goharbor/prepare:v2.10.0' locally
v2.10.0: Pulling from goharbor/prepare
577f92c8b679: Pull complete
a0d0953b0d98: Pull complete
ee7af4211aa2: Pull complete
4da360042325: Pull complete
43e5fe5edbe4: Pull complete
cd55cc46f080: Pull complete
baeb9599408e: Pull complete
a0d5489f51f3: Pull complete
997317a00013: Pull complete
bb6dae348e49: Pull complete
Digest: sha256:d5f6c4a87e97323214aef195507737ba9c9b3651aece517015b83012667f6e95
Status: Downloaded newer image for goharbor/prepare:v2.10.0
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[root@k8s-master harbor]#
同样在/opt/harbor目录下执行安装命令
./install.sh
出现最后一行成功安装的输出即表示安装成功,如下
完整输出内容:
执行命令后输出的代码如下
[root@k8s-master harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 24.0.7
[Step 1]: checking docker-compose is installed ...
Note: Docker Compose version v2.21.0
[Step 2]: loading Harbor images ...
7570a78aea36: Loading layer [==================================================>] 9.08MB/9.08MB
04774e0e84f2: Loading layer [==================================================>] 4.096kB/4.096kB
8a42710a9f5a: Loading layer [==================================================>] 3.072kB/3.072kB
f1990e77f8e5: Loading layer [==================================================>] 197MB/197MB
172f5af926be: Loading layer [==================================================>] 17.6MB/17.6MB
2bef5dd17a10: Loading layer [==================================================>] 215.4MB/215.4MB
Loaded image: goharbor/trivy-adapter-photon:v2.10.0
Loaded image: goharbor/prepare:v2.10.0
a36cb8a4e510: Loading layer [==================================================>] 126.1MB/126.1MB
fd72ef63aacc: Loading layer [==================================================>] 3.584kB/3.584kB
162d9960a2b9: Loading layer [==================================================>] 3.072kB/3.072kB
b71508b0d586: Loading layer [==================================================>] 2.56kB/2.56kB
18c685e189cb: Loading layer [==================================================>] 3.072kB/3.072kB
84690af2e82b: Loading layer [==================================================>] 3.584kB/3.584kB
8d7eb73e8207: Loading layer [==================================================>] 20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.10.0
001da4979db8: Loading layer [==================================================>] 8.562MB/8.562MB
275281f671bf: Loading layer [==================================================>] 4.096kB/4.096kB
f6856e2d539f: Loading layer [==================================================>] 17.4MB/17.4MB
557317f3c1c5: Loading layer [==================================================>] 3.072kB/3.072kB
942b8c3060c6: Loading layer [==================================================>] 32.81MB/32.81MB
b2bc30e737e7: Loading layer [==================================================>] 51MB/51MB
Loaded image: goharbor/harbor-registryctl:v2.10.0
d5e5478da184: Loading layer [==================================================>] 116.8MB/116.8MB
Loaded image: goharbor/nginx-photon:v2.10.0
74a7f6a8de8c: Loading layer [==================================================>] 11.58MB/11.58MB
46523ccaf371: Loading layer [==================================================>] 27.6MB/27.6MB
3cea6b428022: Loading layer [==================================================>] 4.608kB/4.608kB
9815d4ae0f06: Loading layer [==================================================>] 28.39MB/28.39MB
Loaded image: goharbor/harbor-exporter:v2.10.0
7d7e15ae8ca1: Loading layer [==================================================>] 15.93MB/15.93MB
e13b0ff80947: Loading layer [==================================================>] 111.8MB/111.8MB
da74a4230588: Loading layer [==================================================>] 3.072kB/3.072kB
89240f6f343b: Loading layer [==================================================>] 59.9kB/59.9kB
7b00214da46a: Loading layer [==================================================>] 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.10.0
345fdbd05997: Loading layer [==================================================>] 8.562MB/8.562MB
5c4443929555: Loading layer [==================================================>] 4.096kB/4.096kB
605c9788ef17: Loading layer [==================================================>] 3.072kB/3.072kB
b2ab56de0e45: Loading layer [==================================================>] 17.4MB/17.4MB
950eb2734789: Loading layer [==================================================>] 18.19MB/18.19MB
Loaded image: goharbor/registry-photon:v2.10.0
7693164e30e0: Loading layer [==================================================>] 116.8MB/116.8MB
6b50b5d516aa: Loading layer [==================================================>] 6.531MB/6.531MB
5aea217650ad: Loading layer [==================================================>] 246.8kB/246.8kB
0b3de92ff70b: Loading layer [==================================================>] 1.477MB/1.477MB
Loaded image: goharbor/harbor-portal:v2.10.0
b79ac58f353c: Loading layer [==================================================>] 11.58MB/11.58MB
18c4c015e339: Loading layer [==================================================>] 3.584kB/3.584kB
c6eef6a39935: Loading layer [==================================================>] 2.56kB/2.56kB
03db56130352: Loading layer [==================================================>] 58.57MB/58.57MB
78c9748f2d29: Loading layer [==================================================>] 5.632kB/5.632kB
e1732f90232a: Loading layer [==================================================>] 123.4kB/123.4kB
6b733e4833c8: Loading layer [==================================================>] 80.38kB/80.38kB
fe6828cc147a: Loading layer [==================================================>] 59.56MB/59.56MB
8e1349c44768: Loading layer [==================================================>] 2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.10.0
02b0385778eb: Loading layer [==================================================>] 15.93MB/15.93MB
ac2be26232ee: Loading layer [==================================================>] 175MB/175MB
1e3e9dba5eaa: Loading layer [==================================================>] 25.47MB/25.47MB
c7fa85d79c1c: Loading layer [==================================================>] 18.14MB/18.14MB
f9ef6596c7ce: Loading layer [==================================================>] 5.12kB/5.12kB
e35036cc139f: Loading layer [==================================================>] 6.144kB/6.144kB
0cb7ded8041a: Loading layer [==================================================>] 3.072kB/3.072kB
5d178abacde0: Loading layer [==================================================>] 2.048kB/2.048kB
67fe09fd709b: Loading layer [==================================================>] 2.56kB/2.56kB
d0b4aac335c4: Loading layer [==================================================>] 7.68kB/7.68kB
Loaded image: goharbor/harbor-db:v2.10.0
fced8697b2c7: Loading layer [==================================================>] 11.58MB/11.58MB
af968b902c26: Loading layer [==================================================>] 3.584kB/3.584kB
7caaebde63bc: Loading layer [==================================================>] 2.56kB/2.56kB
d6e3c7a6ef36: Loading layer [==================================================>] 44.96MB/44.96MB
bc8a8ef654ea: Loading layer [==================================================>] 45.75MB/45.75MB
Loaded image: goharbor/harbor-jobservice:v2.10.0
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /opt/harbor
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/config.yml
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/registryctl/env
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Note: stopping existing Harbor instance ...
[Step 5]: starting Harbor ...
[+] Running 10/10
✔ Network harbor_harbor Created 0.0s
✔ Container harbor-log Started 0.0s
✔ Container registryctl Started 0.0s
✔ Container redis Started 0.0s
✔ Container registry Started 0.0s
✔ Container harbor-portal Started 0.0s
✔ Container harbor-db Started 0.0s
✔ Container harbor-core Started 0.0s
✔ Container harbor-jobservice Started 0.0s
✔ Container nginx Started 0.0s
✔ ----Harbor has been installed and started successfully.----
[root@k8s-master harbor]#
这个查看可以用docker也可以用docker-compose,后者可进行多数量容器管理
我们用docker命令查看我们运行的harbor相关容器
docker ps
docker-compose命令只显示其管理的harbor容器
docker-compose -f /opt/harbor/docker-compose.yml ps
如果docker-compose
命令报错no configuration file provided: not found
表示无法找到配置文件
可到docker-compose.yml
所在目录下执行命令,该文件本篇位于/opt/harbor/
目录下
docker-compose命令可参考下方链接文章中第5步:
Linux系统安装docker-compose
如果harbor服务出问题,可使用docker-compose一键重启所有服务,如命令无法使用可加-f参数
docker-compose restart
当然了,也可以先停再启,这种是比较保险的,毕竟重启有时候会有问题
docker-compose stop
docker-compose start