启用 harbor 的 chart repository 服务
我们需要在安装时添加额外的参数,例如:
## 启动 chart repository service 服务
➜ cd /srv/harbor
➜ ./install.sh --with-chartmuseum
等待安装完成即可,安装完成后会有如下类似提示:
...
✔ ----Harbor has been installed and started successfully.----
...
通过 Harbor 界面管理 Helm 图表
您可以单击右上角的图标按钮在卡片视图和列表视图之间切换视图。
上传新图表
点击UPLOAD左上角的按钮打开图表上传对话框。从您的文件系统中选择上传图表。单击UPLOAD按钮将其上传到图表存储库服务器。
列出图表版本
单击图表列表中的图表名称将显示该图表的所有可用版本以及以下信息:
- 图表版本号
- 图表版本的维护者
- 使用的模板引擎(默认为 gotpl)
-
图表版本的创建时间戳
用 Helm CLI 管理 Harbor Charts
作为一个 helm 图表存储库,Harbor 可以与 Helm CLI 顺利工作。关于如何安装 Helm CLI,请参考 install helm。
helm version
version.BuildInfo{Version:"v3.9.0", GitCommit:"7ceeda6c585217a19a1131663d8cd1f7d641b2a7", GitTreeState:"clean", GoVersion:"go1.18.2"}
添加 harbor helm 仓库
在使用之前,应该使用 helm repo add 命令将 Harbor 添加到存储库列表中。它支持两种不同的模式:
- 添加 Harbor 作为统一的单一索引入口点
该模式可以使 Helm 访问到不同项目中的所有图表,以及当前经过身份验证的用户可以访问的图表。
helm repo add \
--username=admin \
--password=Passw0rd \
myrepo https://xx.xx.xx.xx/chartrepo
- 将 Harbor 项目添加为单独的索引入口点
helm repo add \
--username=admin \
--password=Passw0rd
myrepo https://xx.xx.xx.xx/chartrepo/myproject
建议使用是第二种模式,添加完成后,如下所示:
helm repo list
NAME URL
hashcorp https://helm.releases.hashicorp.com
minio https://charts.min.io/
bitpoke https://helm-charts.bitpoke.io
myproject https://hub.xxxxxcom/chartrepo/myproject
上传 Helm Charts
使用 CLI 将图表推送到存储库服务器
安装helm-push方法
作为替代方案,您也可以通过 CLI 上传图表。本机 helm CLI 不支持它。推送前应安装社区插件。首先运行helm plugin install安装push插件。
helm plugin install https://github.com/chartmuseum/helm-push
因个人网络原因使用到proxy。
helm plugin install https://github.com/chartmuseum/helm-push
Downloading and installing helm-push v0.10.3 ...
https://github.com/chartmuseum/helm-push/releases/download/v0.10.3/helm-push_0.10.3_darwin_amd64.tar.gz
Installed plugin: cm-push
# 查看plugin版本
helm plugin list
NAME VERSION DESCRIPTION
diff 3.5.0 Preview helm upgrade changes as a diff
cm-push 0.10.3 Push chart package to ChartMuseum
当我们打包好 Helm Charts后就可以通过命令上传至我们创建的仓库:
$ helm cm-push myproject-22.8.10.tgz myproject
Pushing myproject-22.8.10.tgz to myproject...
Done.
mac m1 cm-push 无法运行
在执行helm cm-push提示报错# [Error: fork/exec /root/.local/share/helm/plugins/helm-push/bin/helm-cm-push: no such file or directory]
修复方法
$ cd /root/.local/share/helm/plugins/helm-push/
$ make build
....
helm.sh/helm/v3/internal/resolver
github.com/chartmuseum/helm-push/pkg/helm
helm.sh/helm/v3/pkg/downloader
command-line-arguments
$ ll
total 448
drwxr-xr-x 20 Sam staff 640 9 1 15:52 ./
drwxr-xr-x 4 Sam staff 128 9 1 15:52 ../
drwxr-xr-x 12 Sam staff 384 9 2 10:11 .git/
drwxr-xr-x 4 Sam staff 128 9 1 15:52 .github/
-rw-r--r-- 1 Sam staff 149 9 1 15:52 .gitignore
-rw-r--r-- 1 Sam staff 397 9 1 15:52 .goreleaser.yml
-rw-r--r-- 1 Sam staff 2254 9 1 15:52 BUILDING.md
-rw-r--r-- 1 Sam staff 11357 9 1 15:52 LICENSE
-rw-r--r-- 1 Sam staff 2030 9 1 15:52 Makefile
-rw-r--r-- 1 Sam staff 6863 9 1 15:52 README.md
drwxr-xr-x 5 Sam staff 160 9 1 15:52 acceptance_tests/
drwxr-xr-x 6 Sam staff 192 9 2 10:15 bin/
drwxr-xr-x 3 Sam staff 96 9 1 15:52 cmd/
-rw-r--r-- 1 Sam staff 5641 9 1 15:52 go.mod
-rw-r--r-- 1 Sam staff 176534 9 1 15:52 go.sum
drwxr-xr-x 4 Sam staff 128 9 1 15:52 pkg/
-rw-r--r-- 1 Sam staff 407 9 1 15:52 plugin.yaml
drwxr-xr-x 4 Sam staff 128 9 1 15:52 releases/
drwxr-xr-x 6 Sam staff 192 9 1 15:52 scripts/
drwxr-xr-x 5 Sam staff 160 9 1 15:52 testdata/
$ ll bin/helm-cm-push/
-rwxr-xr-x 1 Sam staff 38624288 9 2 10:15 bin/helm-cm-push*
# 测试命令正常
$ helm cm-push --help
Helm plugin to push chart package to ChartMuseum
Examples:
$ helm cm-push mychart-0.1.0.tgz chartmuseum # push .tgz from "helm package"
$ helm cm-push . chartmuseum # package and push chart directory
$ helm cm-push . --version="1.2.3" chartmuseum # override version in Chart.yaml
$ helm cm-push . https://my.chart.repo.com # push directly to chart repo URL
Usage:
helm cm-push [flags]
Flags:
--access-token string Send token in Authorization header [$HELM_REPO_ACCESS_TOKEN]
-a, --app-version string Override app version pre-push
--auth-header string Alternative header to use for token auth [$HELM_REPO_AUTH_HEADER]
--ca-file string Verify certificates of HTTPS-enabled servers using this CA bundle [$HELM_REPO_CA_FILE]
--cert-file string Identify HTTPS client using this SSL certificate file [$HELM_REPO_CERT_FILE]
--check-helm-version outputs either "2" or "3" indicating the current Helm major version
--context-path string ChartMuseum context path [$HELM_REPO_CONTEXT_PATH]
--debug Enable verbose output
-d, --dependency-update update dependencies from "requirements.yaml" to dir "charts/" before packaging
-f, --force Force upload even if chart version exists
-h, --help help for helm
--home string Location of your Helm config. Overrides $HELM_HOME (default "/Users/Sam/.helm")
--host string Address of Tiller. Overrides $HELM_HOST
--insecure Connect to server with an insecure way by skipping certificate verification [$HELM_REPO_INSECURE]
--key-file string Identify HTTPS client using this SSL key file [$HELM_REPO_KEY_FILE]
--keyring string location of a public keyring (default "/Users/Sam/.gnupg/pubring.gpg")
--kube-context string Name of the kubeconfig context to use
--kubeconfig string Absolute path of the kubeconfig file to be used
-p, --password string Override HTTP basic auth password [$HELM_REPO_PASSWORD]
--tiller-connection-timeout int The duration (in seconds) Helm will wait to establish a connection to Tiller (default 300)
--tiller-namespace string Namespace of Tiller (default "kube-system")
-t, --timeout int The duration (in seconds) Helm will wait to get response from chartmuseum (default 30)
-u, --username string Override HTTP basic auth username [$HELM_REPO_USERNAME]
-v, --version string Override chart version pre-push
安装 Helm Charts
在安装之前,请确保使用命令 helm init 正确初始化helm,并且图表索引与命令 helm repo update同步。
$ helm repo update myproject
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "myproject" chart repository
Update Complete. ⎈Happy Helming!⎈
搜索上传的 helm chart
$ helm search repo myproject
NAME CHART VERSION APP VERSION DESCRIPTION
myproject/myproject 22.8.10 v20220713 Helm chart for Kubernetes
安装chart
$ helm install --version 22.8.10 myproject/myproject --generate-name
NAME: myproject-1662089567
LAST DEPLOYED: Fri Sep 2 11:32:53 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None