9、Harbor部署

Kubernetes学习目录

1、在register主机上安装docker

参考章节:2、Docker安装:https://www.cnblogs.com/ygbh/p/17221286.html

2、安装

2.1、下载harbor

wget https://github.com/goharbor/harbor/releases/download/v2.5.6-rc1/harbor-offline-installer-v2.5.6-rc1.tgz

2.2、解压软件

tar xvf harbor-offline-installer-v2.5.6-rc1.tgz -C /usr/local/

2.3、导入镜像

docker load < /usr/local/harbor/harbor.v2.5.6.tar.gz

3、配置文件

3.1、复制配置文件

cp harbor.yml.tmpl harbor.yml
mkdir /data/harbor -p

3.2、需要配置部分

# 2、需要配置部分
[root@register harbor]# vi /usr/local/harbor/harbor.yml

hostname: 192.168.10.33
http:
  port: 80

# 注释如下部分
#https:
#   port: 443
#    The path of cert and key files for nginx
#   certificate: /your/certificate/path
#   private_key: /your/private/key/path

# 设置管理员密码
harbor_admin_password: 12345

# mkdir /data/harbor -p
data_volume: /data/harbor

3.3、检查配置语法并且创建yaml

./prepare

3.4、安装harbor

./install.sh

4、安装docker-compose

4.1、下载软件且配置

# 下载地址
https://github.com/docker/compose/releases/tag/v2.17.0-rc.1


# 安装如下
mv docker-compose-linux-x86_64 /usr/sbin/docker-compose
chmod +x /usr/sbin/docker-compose

4.2、查询结果

[root@register harbor]# docker-compose ps
NAME                IMAGE                                COMMAND                  SERVICE             CREATED             STATUS                  PORTS
harbor-core         goharbor/harbor-core:v2.5.6          "/harbor/entrypoint.…"   core                20 hours ago        Up 19 hours (healthy)   
harbor-db           goharbor/harbor-db:v2.5.6            "/docker-entrypoint.…"   postgresql          20 hours ago        Up 19 hours (healthy)   
harbor-jobservice   goharbor/harbor-jobservice:v2.5.6    "/harbor/entrypoint.…"   jobservice          20 hours ago        Up 19 hours (healthy)   
harbor-log          goharbor/harbor-log:v2.5.6           "/bin/sh -c /usr/loc…"   log                 20 hours ago        Up 19 hours (healthy)   127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.5.6        "nginx -g 'daemon of…"   portal              20 hours ago        Up 19 hours (healthy)   
nginx               goharbor/nginx-photon:v2.5.6         "nginx -g 'daemon of…"   proxy               20 hours ago        Up 19 hours (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp
redis               goharbor/redis-photon:v2.5.6         "redis-server /etc/r…"   redis               20 hours ago        Up 19 hours (healthy)   
registry            goharbor/registry-photon:v2.5.6      "/home/harbor/entryp…"   registry            20 hours ago        Up 19 hours (healthy)   
registryctl         goharbor/harbor-registryctl:v2.5.6   "/home/harbor/start.…"   registryctl         20 hours ago        Up 19 hours (healthy)  

5、登陆测试

5.1、登陆的帐号密码

用户名: admin, 密码:123456

5.2、创建帐号

5.3、建立项目

5.4、设置开机自启动

5.4.1、harbor.service

cat > /lib/systemd/system/harbor.service << 'EOF'
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
# 需要注意harbor的安装位置
ExecStart=/usr/sbin/docker-compose --file /usr/local/harbor/docker-compose.yml up
ExecStop=/usr/sbin/docker-compose --file /usr/local/harbor/docker-compose.yml stop
[Install]
WantedBy=multi-user.target
EOF

5.4.3、启动服务

# 加载服务配置文件
systemctl daemon-reload
systemctl start harbor
systemctl status harbor
systemctl enable harbor

6、测试仓库

6.1、需要上传或下载镜的主机docker需要设置仓库地址

[root@master1 ~]# cat /etc/docker/daemon.json 
{
"data-root":"/data/docker",
"insecure-registries": ["192.168.10.33:80"],#<==主要配置仓库的地址
"registry-mirrors": ["http://hub-mirror.c.163.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}

6.2、检查是否配置完成

[root@master1 ~]#  docker info | grep -A1 Insecure
 Insecure Registries:
  192.168.10.33:80

6.3、登陆docker仓库

# 记得加端口 
[root@master1 ~]# docker login 192.168.10.33:80
Username: cyc
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

6.4、打标签上传镜像到仓库

# 打标签
docker tag nginx:latest 192.168.10.33:80/k8s/nginx:latest

# 推至私有仓库
docker push 192.168.10.33:80/k8s/nginx:latest

注意:
提交的代码仓库必须在对应的账号里面存在,否则无法提交
因为默认情况下docker仓库是基于https方式来进行登录的,而我们的没有定制https所以,这里的仓
库地址必须是 ip:port 方式

posted @ 2023-03-16 11:17  小粉优化大师  阅读(73)  评论(0编辑  收藏  举报