用 Harbor 管理 Helm Charts

原文连接:https://aeric.io/post/harbor-manage-helm-charts/git

在 v1.6 版本的 harbor 中新增长了 helm charts 的管理功能,这样就能够利用 harbor 同时管理镜像和 helm charts 了,在部署 kubernetes 相关应用时就比较方便,本次尝试用 harbor 来管理 helm charts。github

以前我是将公司内的 harbor 仓库作了一次升级,将 harbor 升级到了 v1.7.1版本,具体升级过程能够参考以前博文内容:记一次harbor的升级之旅。固然你也能够从新安装新版本的 harbor。由于本人公司 harbor 仓库用的是 https 协议来访问的,因此咱们还须要相关证书,证书须要是受信的才行,这个须要根据具体状况来作取舍,这里再也不赘述,具体怎么使用 harbor 来管理 helm charts 能够参考下面的内容。api

启用 harbor 的 chart repository 服务

默认新版 harbor 不会启用 chart repository service,若是须要管理 helm,咱们须要在安装时添加额外的参数,例如:bash

## 默认安装
$ cd /srv/harbor
$ ./install.sh

## 启动 chart repository service 服务
$ cd /srv/harbor
$ ./install.sh --with-chartmuseum
复制代码

等待安装完成便可,安装完成后会有以下相似提示:ide

...
✔ ----Harbor has been installed and started successfully.----
...
复制代码

以后,咱们就能够用上述 harbor 来管理 helm charts 了。工具

图形界面操做

建立相关项目:post

首先,咱们须要在 harbor 上建立一个名为 helm-repo的项目,以下图所示:ui

建立 helm-repo 项目

上传 Helm Charts 包:google

单击 “上传” 按钮以打开图表上载对话框。 从文件系统中选择上传 Helm Charts。 单击 UPLOAD 按钮将其上载到 helm-repo存储库。spa

上传 Helm Charts

If the chart is signed, you can choose the corresponding provenance file from your filesystem and Click the UPLOADbutton to upload them together at once.

Helm Charts 上传成功后,就能够显示在相关界面上,具体内容包括: chart 版本号、状态、做者、Egine、建立时间等信息,以下图所示:

charts_version

固然,harbor 也支持根据每一个 cahrt 的用途,为上传的 chart 包打上对应的标签,点击相关按钮便可,在打标签以前须要在 harbor 的系统设置里添加好对应标签便可,当为相应的 chart 添加好对应标签后 harbor 支持根据标签过滤 chart ,这个挺简单的,这里再也不赘述。

charts 成功上传后,咱们能够查看其具体信息,主要包括 SummaryDependenciesValues等相关信息。也能够经过图形界面来管理上传的 charts ,包括 删除、更新等等具体操做。

用 Helm CLI 管理 Helm Charts

上述用 harbor 的图形界面操做 helm charts 当然简单快捷,这个在咱们查看 helm 时确实简单高效,可是当咱们想利用 CI 实现 helm charts 自动部署应用到 Kubernetes 集群的时候,该方法就显得比较鸡肋了,能够说图形界面根本没法实现,因此咱们须要用 Helm CLI工具来实现。

首先,须要安装 helm 客户端工具,具体安装 helm cli 能够参考:Install Helm,安装完成后能够经过以下命令验证安装是否完成:

helm version

#Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
#Server: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
复制代码

添加 harbor helm 仓库

在使用以前,应该使用 helm repo add 命令将 Harbor 添加到存储库列表中。它支持两种不一样的模式:

1.Add Harbor as a unified single index entry point
2.Add Harbor project as separate index entry point
复制代码

这两种模式的具体区别以下所述:

Add Harbor as a unified single index entry point

  • 该模式可使 Helm 访问到不一样项目中的全部图表,以及当前通过身份验证的用户能够访问的图表。

  • helm repo add --ca-file ca.crt --cert-file server.crt --key-file server.key --username=admin --password=Passw0rd myrepo https://xx.xx.xx.xx/chartrepo
    复制代码

Add Harbor project as separate index entry point

  • 该模式 helm 只能在指定项目中提取图表。

  • helm repo add --ca-file ca.crt --cert-file server.crt --key-file server.key --username=admin --password=Passw0rd myrepo https://xx.xx.xx.xx/chartrepo/myproject
    复制代码

须要注意的是,若是用 https协议,这两种模式均需提供受信的证书和密钥,ca 证书能够不须要,省略

本次,我用的是第二种模式,添加完成后,以下所示:

[root@k8s-m1 ~]# helm repo list
NAME     	URL
stable   	https://kubernetes-charts.storage.googleapis.com
local    	http://127.0.0.1:8879/charts
myrepo	    https://harbor.xxx.cn/chartrepo/helm-repo
复制代码

上传 Helm Charts

由于咱们须要用 helm push命令上传,该命令是经过 helm plugin实现的,可是默认 helm 没有安装此插件,须要安装:

helm plugin install https://github.com/chartmuseum/helm-push
复制代码

当咱们打包好 Helm Charts后就能够经过命令上传至咱们建立的仓库:

helm push --ca-file=ca.crt --key-file=server.key --cert-file=server.crt --username=admin --password=passw0rd chart_repo/hello-helm-0.1.0.tgz myrepo
复制代码

push command does not support pushing a prov file of a signed chart yet.

安装 Helm Charts

在安装以前,请确保使用命令 helm init 正确初始化helm,而且图表索引与命令 helm repo update同步。

helm repo update
复制代码

搜索须要安装的 helm chart

helm search hello
复制代码

安装 helm charts

helm install --ca-file=ca.crt --key-file=server.key --cert-file=server.crt --username=admin --password=Passw0rd --version 0.1.10 repo248/chart_repo/hello-helm
复制代码

至此, 用 harbor 管理 helm charts 就完成了。helm 链接的 kubernetes 集群默认是和 kubectl 链接的 kubernetes 集群一致的,以后咱们能够到 kubernetes 集群中查看咱们新部署的 helm 相关应用

helm list
复制代码
相关文章
相关标签/搜索