Creating Library Charts

1. Defining Library Chart Type

Example: Library Chart.yaml

apiVersion: v2
name: common
description: Shared template helpers
type: library
version: 1.0.0
ConstraintReason
No installable resourceshelm install fails on type=library
Only _*.tpl + helpersManifest templates would be ignored

2. Creating Reusable Templates

Example: Common deployment helper

{{- define "common.deployment" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "common.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount | default 1 }}
  selector:
    matchLabels: {{- include "common.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels: {{- include "common.selectorLabels" . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: {{ include "common.image" . }}
{{- end -}}

3. Sharing Common Helpers

HelperPurpose
common.fullnameStandard name truncation
common.labelsStandard label set
common.imageRegistry/repo/tag/digest resolution
common.affinityAnti-affinity boilerplate

4. Using Library as Dependency

Example: Consumer Chart.yaml

dependencies:
  - name: common
    version: "^1.0.0"
    repository: oci://ghcr.io/acme/charts

5. Including Library Templates

Example: Consumer's templates/deployment.yaml

{{- include "common.deployment" . }}

6. Versioning Library Charts

RuleApply
MAJORBreaking template name or scope changes
MINORNew helpers added (backward compatible)
PATCHBug fixes in existing helpers

7. Documenting Library Usage

DocContent
README.mdList of helpers + expected values
Inline tpl commentsDocument required .Values keys
Example chartReference consumer chart in repo

8. Organizing Library Templates

FileHelpers
_names.tplname, fullname
_labels.tpllabels, selectorLabels
_deployment.tplWorkload helpers
_service.tplService helpers

9. Testing Library Templates

ApproachTool
Helper unit testshelm-unittest on a wrapper application chart
Snapshot testsVerify rendered output diff across PRs
IntegrationInstall consumer chart in kind/minikube

10. Publishing Library Charts

TargetCommand
HTTP repohelm package + helm repo index
OCI registryhelm push lib-1.0.0.tgz oci://ghcr.io/acme/charts