1.Harbor仓库
Harbor简史
Harbor是由VMware公司开源的容器镜像仓库, 事实上, Harbor是在Docker Registry上进行了相应的企业级拓展, 从而获得了更加广泛的应用, 这些企业级拓展包括: 管理用户界面、基于角色访问控制、AD/LDAP集成以及审计日志, 足以满足基本企业需求.
基于角色访问控制
- Guest: 对指定项目只读权限
- Developer: 开发人员, 读写项目权限
- Admin: 项目管理, 所有权限
- Anonymous: 当用户未登陆时,该用户视为匿名, 不能访问私有项目, 只能访问公开项目
2.Harbor部署
1.环境准备
在k8s集群搭建完成的情况下再准备一台虚拟机作为harbor仓库
192.168.13.139 harbor #harbor仓库的服务端
192.168.13.141 master #作为客户端
下载:https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.5.3.tgz
下载此软件包需要翻墙, 请自行安装Google浏览器插件
2.安装docker和compose
#安装必要的一些系统工具
[root@harbor ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
#添加软件源信息
[root@harbor ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新并安装Docker-CE
[root@harbor ~]# yum makecache fast
[root@harbor ~]# yum -y install docker-ce
#开启Docker服务
[root@harbor ~]# systemctl enable docker && systemctl start docker
GitHub:docker-compose1.22 :
[root@harbor ~]# curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
[root@harbor ~]# chmod a+x /usr/local/bin/docker-compose
3.无证书部署
将harbor-offline-installer-v1.5.3.tgz 包 上传并解压
[root@harbor ~]# tar xf harbor-offline-installer-v1.5.3.tgz
[root@harbor ~]# cd harbor
[root@harbor harbor]# vim harbor.cfg #修改两个地方
hostname = 192.168.13.139 #改为仓库服务端地址
customize_crt = false #不用证书的方式
[root@harbor harbor]# ./prepare #修改配置文件后一定要执行这一步
[root@harbor harbor]# ./install.sh
#首次安转用这个命令,以后都用docker-compose up -d 命令启动
[root@harbor harbor]# docker-compose ps #全部为up就是启动成功
Name Command State Ports
-----------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/start.sh Up (healthy)
harbor-db /usr/local/bin/docker-entr ... Up (healthy) 3306/tcp
harbor-jobservice /harbor/start.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
harbor-ui /harbor/start.sh Up (healthy)
nginx nginx -g daemon off; Up (healthy) 0.0.0.0:443->443/tcp,
0.0.0.0:4443->4443/tcp,
0.0.0.0:80->80/tcp
redis docker-entrypoint.sh redis ... Up 6379/tcp
registry /entrypoint.sh serve /etc/ ... Up (healthy) 5000/tcp
如果出错 用docker-compose down 停掉服务(^+s)
docker-compose up -d 启动服务
1.客户端配置
[root@master ~]# vim /etc/docker/daemon.conf
{
"insecure-registries": ["http://192.168.13.139"]
}
[root@master ~]# cat /usr/lib/systemd/system/docker.service |grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.13.139 --containerd=/run/containerd/containerd.sock
#找到 ExecStart开头的 添加--insecure-registry 192.168.13.139
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl restart docker
2.服务端配置
[root@harbor harbor]# vim /etc/docker/daemon.conf
{
"insecure-registries": ["http://192.168.13.139"]
}
[root@harbor harbor]# cat /usr/lib/systemd/system/docker.service |grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.13.139:5000 --containerd=/run/containerd/containerd.sock
#找到 ExecStart开头的 添加--insecure-registry 192.168.13.139:5000
[root@harbor harbor]# systemctl daemon-reload
[root@harbor harbor]# systemctl restart docker
3.客户端测试
[root@master ~]# docker login -u admin -p Harbor12345 http://192.168.13.139
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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
4.Harbor使用
打开网页访问服务端IP http://192.168.13.139/
[root@harbor harbor]# vim harbor.cfg
查看配置文件,默认的用户名为admin,密码为Harbor12345
登录上之后里面只有一个公开的library,我们可以新建一个
然后我们去客户端上面上传一个镜像到该仓库
[root@master ~]# docker images #查看镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
daocloud.io/library/nginx latest e791337790a6 2 weeks ago 127MB
[root@master ~]# docker tag daocloud.io/library/nginx:latest 192.168.13.139/yjssjm/nginx
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.13.139/yjssjm/nginx latest e791337790a6 2 weeks ago 127MB
daocloud.io/library/nginx latest e791337790a6 2 weeks ago 127MB
harbor.io/library/nginx latest e791337790a6 2 weeks ago 127MB
[root@master ~]# docker push 192.168.13.139/yjssjm/nginx #推送
The push refers to repository [192.168.13.139/yjssjm/nginx]
be91fceb796e: Pushed
919b6770519b: Pushed
b60e5c3bcef2: Pushed
latest: digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee size: 948
我们在页面上查看
这里面可以创建新的用户,然后给他们设置每个项目的权限就能实现角色访问控制。