vashon's docs
  • Kubernetes
  • Kubernetes之etcd数据库
  • Kubernetes中pod的创建流程
  • k8s一键部署脚本
  • TKE操作笔记01
  • TKE操作笔记02
  • TKE操作笔记03
  • TKE操作笔记04
  • TKE学习笔记
  • TKE上搭建EFK日志采集系统
  • TKE上搭建prometheus
  • TKE升级node节点版本
  • TKE上部署treafik2
  • k8s之dns解析
  • TKE网络模式之vpc-cni
  • harbor搭建企业docker私有镜像仓库
  • Traefik1.7.17的部署使用
  • TKE中configMap的使用
  • TKE集群中deployment使用vpc-cni模式
  • TKE中使用lb直连获取客户端真实IP
  • TKE上搭建集群Dashboard
  • TKE中在节点上获取容器资源配置
  • TKE挂载COS桶容器目录权限如何设置
  • TKE中挂载文件到CFS子目录
  • TKE上部署metrics-server
  • TKE之初识容器探测器
  • 自制CA证书设置ssl证书
  • TKE上动态部署jenkins-slaves
  • Kubernetes之RBAC权限管理
  • Kubernetes之调度篇
  • Kubectl命令行jsonpath的使用
  • Kubernetes插件之ip-masq-agent
  • linux定位问题常用命令
  • 关于kubernetes垃圾回收那点事
  • Kubernetes在pod中配置hosts解析域名
  • Kubernetes之helm部署使用
  • kubeadm部署k8s
  • TKE使用自建NFS持久化存储
  • 二进制部署k8s
  • TKE上关于postStart和preStop使用
  • DockerFile学习
  • linux常用命令
  • k8s中通过ExternalName访问外部服务副本
  • docker常用命令
  • 搭建Docker私有仓库
  • crictl调试Kubernetes节点
  • 强制删除Terminating的ns
  • kubernetes之StatefulSet控制器
  • kubewatch监控k8s集群资源变更
  • 日志聚合工具Loki
  • 关于kubernetes证书的那点事
  • 如何阅读k8s源码
  • k8s之securityContext
  • Kubernetes之多集群的访问
  • k8s之externaltrafficpolicy保留客户端源ip
  • fluent-bit收集不同业务日志
由 GitBook 提供支持
在本页
  • 搭建harbor仓库
  • 安装docker和docker-compose
  • 下载harbor安装包
  • 配置https方式访问证书
  • 修改harbor配置项
  • 启动harbor
  • haobor仓库的使用
  • harbor的登录和创建项目
  • 客户端推送镜像
  • harbor中角色权限说明

这有帮助吗?

harbor搭建企业docker私有镜像仓库

本篇文章介绍了如何搭建企业级私有镜像仓库harbor及harbor仓库的使用。

搭建harbor仓库

安装docker和docker-compose

# curl -fsSL https://get.docker.com/ | sh
# systemctl start docker
# systemctl enable docker
# curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose

下载harbor安装包

# wget https://github.com/goharbor/harbor/releases/download/v2.0.0/harbor-offline-installer-v2.0.0.tgz
# tar -zxvf harbor-offline-installer-v2.0.0.tgz
# mv harbor /opt/
# cd /opt/harbor
# cp harbor.yml.tmpl harbor.yml

配置https方式访问证书

  1. 生成根证书(存放到目录/etc/docker/certs.d/reg.niewx.club)

    $ mkdir -p /etc/docker/certs.d/reg.niewx.club && cd /etc/docker/certs.d/reg.niewx.club
  2. 创建自己的CA证书(不使用第三方权威机构的CA来认证,自己充当CA的角色

    $ openssl genrsa -out ca.key 2048
  3. 生成自签名证书(使用已有私钥ca.key自行签发根证书)

    $ openssl req -x509 -new -nodes -key ca.key -days 10000 -out ca.crt -subj "/CN=Harbor-ca"
  4. 生成服务器端私钥和CSR签名请求

    $ openssl req -newkey rsa:4096 -nodes -sha256 -keyout server.key -out server.csr
  5. 签发服务器证书

    echo subjectAltName = IP:49.235.179.157 > extfile.cnf
    openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 -extfile extfile.cnf -out server.crt
  6. 最终生成的证书如下

    [root@VM_0_13_centos reg.niewx.club]# ls
    ca.crt ca.key ca.srl extfile.cnf server.crt server.csr server.key

修改harbor配置项

[root@VM_0_13_centos harbor]# cat harbor.yml
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 1.1.1.1
# http related config
#http:
 # port for http, default is 80. If https enabled, this port will redirect to https port
# port: 80
# https related config
https:
 # https port for harbor, default is 443
 port: 443
 # The path of cert and key files for nginx
 certificate: /etc/docker/certs.d/reg.niewx.club/server.crt
 private_key: /etc/docker/certs.d/reg.niewx.club/server.key
# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal
# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433
# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: 123456

主要需要修改上面标记的选项。

启动harbor

# cd /opt/harbor
# ./ prepare
# ./install.sh --with-clair (启动扫描器)

启动日志显示上面则启动成功

如果修改了配置项需要重新启动harbor则重新执行以下命令即可

# cd /opt/harbor
# ./ prepare
# ./install.sh --with-clair (启动扫描器)

haobor仓库的使用

harbor的登录和创建项目

默认账号为admin,密码为你之前修改配置密码

项目管理,里面会有一个默认的公开项目library,所有人可以上传下载镜像

点击新建项目,输入项目名称,设置存储容量和是否公开

查看项目的镜像仓库,也可以查看推送命令推送镜像

客户端推送镜像

首先需要配置docker认真地址

[root@node1 ~]# cat /etc/docker/daemon.json
{
 "insecure-registries": ["https://1.1.1.1"],
 "registry-mirrors": ["https://yywkvob3.mirror.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"]
}
# systemctl daemon-reload && systemctl restart docker
# docker login 1.1.1.1 -u admin -p *****
# docker tag busybox:latest 1.1.1.1/library/busybox:latest
# docker push 1.1.1.1/library/busybox:latest

harbor中角色权限说明

角色

权限说明

访客

对于指定项目拥有只读权限

开发人员

对于指定项目拥有读写权限

维护人员

对于指定项目拥有读写权限,创建 Webhooks

项目管理员

除了读写权限,同时拥有用户管理/镜像扫描等管理权限

上一页TKE网络模式之vpc-cni下一页Traefik1.7.17的部署使用

最后更新于4年前

这有帮助吗?

upload-image
upload-image
upload-image
upload-image
upload-image