环境准备
操作系统:centos7.9
ip : 192.168.205.128
①关闭防火墙,selinux (略)
②时间同步(略)
③开启包转发功能和修改内核参数
##内核参数修改:br_netfilter模块用于将桥接流量转发至iptables链,br_netfilter内核参数需要开启转发
modprobe br_netfilter
cat > /etc/sysctl.d/docker.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
使参数生效
sysctl -p /etc/sysctl.d/docker.conf
image.png
一,安装docker&docker-compose (略)
二,生成证书(自选)
1,生成一个3072位的key(私钥)
openssl genrsa -out ca.key 3072
image.png
2,生成一个数字证书ca.pem
-new 表示生成一个新的证书请求
-x509 表示输出一个X.509证书,而不是一个证书签名请求
-days 3650 表示证书的有效期为10年
openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
填写城市信息,没有标注的回车:(我这里是BJ)
image.png
3,生成harbor域名的证书
生成一个3072位的key(私钥)
openssl genrsa -out harbor.key 3072
image.png
生成一个证书请求,一会签发证书时需要的
openssl req -new -key harbor.key -out harbor.csr
image.png
4,签发证书
openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650
image.png
三:安装harbor
1,创建安装目录
mkdir /data/install -p
cd /data/install/
离线包下载地址:
https://pan.baidu.com/s/13ayH_6RVqBZVIUj7GMVp-A?pwd=s6gt
(参考转自https://blog.csdn.net/weixin_40364776/article/details/136969578)
image.png
2,解压
tar zxvf harbor-offline-installer-v2.3.0-rc3.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml
##修改配置文件
vim harbor.yml
···
hostname: harbor
#修改hostname,跟上面签发的证书域名保持一致
#协议用https
certificate: /data/ssl/harbor.pem
private_key: /data/ssl/harbor.key
···
-----------------------------------------------------------------------------------------------------------------------------------------------------------
#邮件和ldap不需要配置,在harbor的web界面可以配置
#其他配置采用默认即可,修改之后保存退出
image.png
3,安装harbor
需要的离线镜像包 docker-harbor-2-3-0.tar.gz
#导入镜像
docker load -i docker-harbor-2-3-0.tar.gz
image.png
4,导入完成后进入对应目录执行install.sh
./install.sh
image.png
安装完成:
image.png
浏览器访问:ip
image.png
默认账密:
admin/Harbor12345
image.png
至此安装完成
harbor使用
1,客户端配置
#修改hosts文件
[root@master yaml]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.205.136 master
192.168.205.137 node1
192.168.205.138 node2
192.168.205.128 harbor ##新增
#修改docker配置文件
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://mirror.gcr.io",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn"],
#添加下面一行harbor信息
"insecure-registries": ["192.168.205.128","harbor" ]
}
image.png
#修改配置之后使配置生效
systemctl daemon-reload && systemctl restart docker
systemctl status docker
#登录harbor
[root@master yaml]# docker login 192.168.205.128
Username: admin
Password:
Login Succeeded
2,上传本地镜像
创建一个项目(kubernetes)
image.png
##测试
#把本地calico/node镜像重打标签上传至harbor
#把本地像重打标签(标签名称要与harbor仓库路径对应)
docker tag calico/node:v3.8.9 192.168.205.128/kubernetes/node:v3.8.9
#上传到kubernetes项目下
[root@master yaml]# docker push 192.168.205.128/kubernetes/node:v3.8.9
The push refers to a repository [192.168.205.128/kubernetes/node]
20bc0635222d: Pushed
e9d282384a53: Pushed
d7cf51fcf129: Pushed
b02331222ba0: Pushed
eece49d70012: Pushed
001c9a0b70e1: Pushed
319a4e14c63b: Pushed
9ff11352d3d3: Pushed
9fc41040de1a: Pushed
ded268590614: Pushed
a972d1df58c7: Pushed
ffc9b21953f4: Pushed
v3.8.9: digest: sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd size: 2832
查看仓库刚上传的镜像
image.png
下载测试
[root@node1 ~]# docker pull 192.168.205.128/kubernetes/node@sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd
Trying to pull repository 192.168.205.128/kubernetes/node ...
sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd: Pulling from 192.168.205.128/kubernetes/node
afb6ec6fdc1c: Pull complete
8f0aa642cdc0: Pull complete
ec1829ab02bf: Pull complete
e95c599dc006: Pull complete
1e3198f9b4d1: Pull complete
e8cba1315c9f: Pull complete
5ddf8cb8a0ff: Pull complete
57def24135ce: Pull complete
94ddcf5c4711: Pull complete
f8f102bf867d: Pull complete
0d22e8bceb1c: Pull complete
bd3891bad789: Pull complete
Digest: sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd
Status: Downloaded newer image for 192.168.205.128/kubernetes/node@sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd