
3.2 通过Helm Chart安装Harbor
3.1节介绍了如何在单机环境下安装Harbor。当用户希望在多节点环境或者生产环境下运行Harbor时,可能需要在Kubernetes集群上部署Harbor。为此,Harbor提供了Helm Chart来帮助用户在Kubernetes上部署Harbor。
本节为读者介绍如何使用Helm将Harbor部署到Kubernetes集群。
在基于Helm安装Harbor Chart到Kubernetes之前,需要安装机器满足如表3-6所示的需求。
表3-6

3.2.1 获取Helm Chart
在安装前需要执行如下命令添加Helm Chart仓库:

我们可以从Harbor的Helm Chart项目的官方发布网站GitHub上查看Release,目录为“github.com/goharbor/harbor-helm/releases”,如图3-4所示。注意:这里不推荐用户从GitHub上直接下载Release,推荐执行命令通过Helm下载。

图3-4
3.2.2 配置Helm Chart
本节详细讲解如何配置Helm Chart。以下介绍的各项配置可在安装过程中通过“--set”命令指定,也可通过编辑values.yaml文件指定。
若希望少量修改Helm Chart的配置完成安装,则可重点关注以下3项配置。
1.配置服务的暴露方式
Harbor Helm-Chart支持Ingress、ClusterIP、NodePort及LoadBalancer等几种访问暴露(expose)方式。在Kubernetes集群中使用Harbor时可选择ClusterIP。如果需要在Kubernetes集群外提供Harbor服务,则可选择使用Ingress、NodePort或LoadBalancer。
访问方式可通过设置expose.type的值来实现。
◎ Ingress:Kubernetes集群需要安装Ingress controller。注意:如果没有开启TLS,则在推送或者拉取镜像时,在命令中需要添加端口号。具体原因可参考“github.com/goharbor/harbor/issues/5291”页面。
◎ ClusterIP:通过集群的内部IP暴露Harbor。该值可支持在Kubernetes集群内部使用Harbor的场景。
◎ NodePort:通过集群中每个Node的IP 和静态端口暴露Harbor。当从集群外部访问时,通过请求NodeIP:NodePort可以访问一个NodePort服务。
◎ LoadBalancer:使用云提供商的负载均衡器,可以对外暴露Harbor。
2.配置外部地址
外部地址是客户端访问Harbor的地址,也是Harbor的管理页面显示完整的“docker”“helm”命令用到的地址;在Docker、Helm客户端交互中暴露完整的Token服务地址。
外部地址可通过设置externalURL的值来实现,格式为“protocol://domain[:port]”。在不同的访问方式下,对domain有不同的要求。
◎ Ingress:当访问方式为Ingress时,应将domain设置为expose.ingress.hosts.core的值。
◎ ClusterIP:当访问方式为ClusterIP时,应将domain设置为expose.clusterIP.name的值。
◎ NodePort:当访问方式为NodePort时,应将domain设置为Kubernetes node的IP地址:Port端口号。
◎ LoadBalancer:当访问方式为LoadBalancer时,应将domain设置为用户自定义的域名。并添加DNS的CNAME记录映射该域名为用户从云提供商处得到的域名。
此外,如果 Harbor 被部署在负载均衡器或反向代理后面,则需要将外部地址设置为负载均衡器或反向代理的访问地址。
3.配置数据持久化
Harbor Helm Chart支持以下几种存储方式。
◎ Disable:关闭持久化数据。在使用过程中产生的数据会随着Pod的消亡而消亡。在生产环境下不建议用户关闭持久化数据。
◎ Persistent Volume Claim:在部署Kubernetes集群时需要一个默认的StorageClass,该StorageClass将被用于动态地为没有设定storage class的PersistentVolumeClaims配置存储。如果需要使用非默认的StorageClass,则要在相应的组件配置下指定storageClass。如果需要使用已有的持久卷,则要在相应的组件配置下指定existingClaim。
◎ External Storage:外部存储仅支持存储镜像和Chart文件。外部存储支持的类型包括azure、gsc、s3、swift及oss。
下面分别介绍其中各项的详细配置。
服务暴露方式的配置如表3-7所示。
表3-7

续表

TLS的配置如表3-8所示。
表3-8

续表

续表

◎ 存储的配置如表3-9所示。
表3-9

续表

续表

◎ 一般配置如表3-10所示。
表3-10

续表

◎ Nginx的配置如表3-11所示。注意:如果访问方式是Ingress,则无须配置Nginx。
表3-11

◎ Portal的配置如表3-12所示。
表3-12

◎ Core的配置如表3-13所示。
表3-13

◎ JobService的配置如表3-14所示。
表3-14

续表

◎ Registry的配置如表3-15所示。
表3-15

续表

◎ ChartMuseum的配置如表3-16所示。
表3-16

◎ Clair的配置如表3-17所示。
表3-17

续表

◎ Trivy的配置如表3-18所示。
表3-18

续表

◎ Notary组件的配置如表3-19所示。
表3-19

◎ Database的配置如表3-20所示。
表3-20

续表

◎ Redis的配置如表3-21所示。
表3-21

续表

3.2.3 安装Helm Chart
在完成Chart的配置后,使用Helm安装Harbor Helm Chart,命令如下,其中my-release为部署名。
◎ Helm 2:

◎ Helm 3:

使用Helm卸载Harbor Helm Chart,命令如下,其中my-release为部署名。
◎ Helm 2:

◎ Helm 3:
