{"id":22885041,"url":"https://github.com/mark8s/helm-library","last_synced_at":"2025-10-17T12:29:41.212Z","repository":{"id":112107727,"uuid":"492236329","full_name":"mark8s/helm-library","owner":"mark8s","description":"helm library record","archived":false,"fork":false,"pushed_at":"2022-05-14T15:11:14.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T22:42:24.620Z","etag":null,"topics":["helm-charts"],"latest_commit_sha":null,"homepage":"","language":"Mustache","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mark8s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-14T14:17:36.000Z","updated_at":"2022-05-27T03:27:59.000Z","dependencies_parsed_at":"2023-05-09T14:16:12.221Z","dependency_job_id":null,"html_url":"https://github.com/mark8s/helm-library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fhelm-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fhelm-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fhelm-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fhelm-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mark8s","download_url":"https://codeload.github.com/mark8s/helm-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246514250,"owners_count":20790016,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helm-charts"],"created_at":"2024-12-13T19:31:14.234Z","updated_at":"2025-10-17T12:29:41.135Z","avatar_url":"https://github.com/mark8s.png","language":"Mustache","funding_links":[],"categories":[],"sub_categories":[],"readme":"# helm-library\nHelm 3 中引入了一种新的 Chart 类型，名为 Library Chart 。它不会部署出一些具体的资源，只能被其他的 Chart 所引用，提高代码的可用复用性。当一个 Chart 想要使用该 Library Chart内的一些模板时，可以在 Chart.yaml 的 dependencies 依赖项中指定。\n\n## 使用helm charts\n在helm chart包中，编辑Chart.yaml，然后增加以下代码\n``` yaml\n  dependencies:\n  - name: common\n    version: \"1.0.0\"\n    repository: \"file://../../../common\"\n```\ncommon：模块名\n\nversion: 模块版本\n\nrepository：模块的位置，这里通过file引入\n\n当我们执行完以上的步骤后，我们需要执行以下命令进行common模块的引入\n``` shell\n   helm dependency update XXXXchartName\n```\n当执行完后，理论上在charts中会生成一个common-1.0.0.tgz的包\n\n现在我们已经将common模块引入到我们自己的charts中，那么如何使用呢？\n\n我们可以通过使用 `{{ include 模块func名 作用域 }} `的语法，在我们的yaml或tpl文件去使用它。\n\n关于include的用法，可以查看以下文档\n\u003e https://helm.sh/zh/docs/chart_template_guide/named_templates/\n\n举个栗子\n\n在common中，有一个名为 `_label.tpl` 的文件，它的内容大致如下：\n\n```yaml\n{{- define \"common.labels.standard\" -}}\napp.kubernetes.io/name: {{ include \"common.names.name\" . }}\nhelm.sh/chart: {{ include \"common.names.chart\" . }}\napp.kubernetes.io/instance: {{ .Release.Name }}\napp.kubernetes.io/managed-by: {{ .Release.Service }}\n{{- end -}}\n```\n`{{- define }} {{ end }}` 中间包含的就是一组k8s中的labels，这里可以看作一个function，而 `common.labels.standard` 就相当于这个function的方法名\n\n如何使用这个function呢？\n\n我们回到自己的chart的template中，修改deployment.yaml文件\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: test\n  namespace: {{ .Release.Namespace }}\n  labels:\n    {{- include \"common.labels.standard\" . | nindent 4 }}\n...\n```\n\n`{{- include \"common.labels.standard\" . | nindent 4 }}` ,就这样，就可以将 common.labels.standard 这个function引入进来\n\n然后我们执行helm install 去查看效果\n\n```yaml\n# Source: test/templates/deployment.yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: test\n  namespace: example\n  labels:\n    app.kubernetes.io/name: test\n    helm.sh/chart: test-0.1.0\n    app.kubernetes.io/instance: test\n    app.kubernetes.io/managed-by: Helm\n...\n```\n\n### 如何启动我们的helm chart？\n在安装前我们需要做一些前置的操作。\n\n检查charts中是否引用了common模块。如果，你的charts中使用到了common模块的内容，在install之前你需要执行以下命令\n```shell\nhelm dependency update\n```\n\n### 部署服务\n\n检查是否使用了common模块\n\n```shell\n[root@infra cloudtogo]# cat Chart.yaml \napiVersion: v2\nname: agentorca\ndescription: A Helm chart for Kubernetes\n\n# A chart can be either an 'application' or a 'library' chart.\n#\n# Application charts are a collection of templates that can be packaged into versioned archives\n# to be deployed.\n#\n# Library charts provide useful utilities or functions for the chart developer. They're included as\n# a dependency of application charts to inject those utilities and functions into the rendering\n# pipeline. Library charts do not define any templates and therefore cannot be deployed.\ntype: application\n\n# This is the chart version. This version number should be incremented each time you make changes\n# to the chart and its templates, including the app version.\n# Versions are expected to follow Semantic Versioning (https://semver.org/)\nversion: 0.1.0\n\n# This is the version number of the application being deployed. This version number should be\n# incremented each time you make changes to the application. Versions are not expected to\n# follow Semantic Versioning. They should reflect the version the application is using.\n# It is recommended to use it with quotes.\nappVersion: \"1.16.0\"\n\ndependencies:\n  - name: common\n    version: \"1.0.0\"\n    repository: \"file://../../../common\"\n```\n引用了common模块，在install之前，我们首先执行以下命令，防止出现依赖非最新导致的异常情况\n\n```shell\n[root@infra cloudtogo]# helm dependency update test\nHang tight while we grab the latest from your chart repositories...\nUpdate Complete. ⎈Happy Helming!⎈\nSaving 1 charts\nDeleting outdated charts\n```\n更新完毕，现在可以进行install了","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark8s%2Fhelm-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmark8s%2Fhelm-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark8s%2Fhelm-library/lists"}