common
by alekc
Function library for TrueCharts, forked and maintained by alekc
About this chart
common
A Helm library chart that provides ready-made templates for the most common Kubernetes
objects: Deployments, StatefulSets, Services, Ingress, PVCs, RBAC, cert-manager
Certificates, CloudNativePG clusters, and more. Charts declare it as a dependency and
configure everything through values.yaml -- no repetitive YAML boilerplate.
Using this library in your chart
1. Add the dependency
# Chart.yaml
dependencies:
- name: common
version: "29.4.0"
repository: https://charts.alekc.dev
helm dependency update
2. Wire the loader
Create templates/common.yaml (the only template file most charts need):
{{- include "tc.v1.common.loader.init" . }}
{{- define "app.hardcodedValues" -}}
{{- end -}}
{{- $_ := mergeOverwrite .Values (include "app.hardcodedValues" . | fromYaml) -}}
{{ include "tc.v1.common.loader.apply" . }}
3. Set values
Everything is driven by values.yaml. The library renders all Kubernetes objects
declared there automatically.
4. Validate against this chart's values.schema.json
Helm has no mechanism to reference or inherit a library dependency's values.schema.json
(a library chart's schema is never validated against the parent's values, and a schema's
$ref resolves against the filesystem root rather than the chart's own directory, so it
can't even reach a sibling file in the same chart, let alone a vendored dependency). To get
schema coverage for the keys this library defines, generate a merged copy, don't vendor the
script that produces it, that's one more file to keep in sync per consumer for no reason,
fetch and run it fresh each time instead:
echo '{}' > values.schema.custom.json # your chart's own additions, on top of common's
helm dependency build
curl -fsSL https://gitlab.com/alexander-chernov/helm/common/-/raw/master/hack/sync-consumer-schema.sh \
| bash -s -- .
That writes values.schema.json as common's schema merged with your
values.schema.custom.json overlay: your overlay wins on any keyword collision (an
additionalProperties, type, enum, etc. at the same path), except required, which
unions instead of replacing, so your overlay can add a required key without silently
dropping common's. Add the CI check so a common version bump or a hand
edit that isn't regenerated fails the pipeline instead of silently drifting:
# .gitlab-ci.yml
include:
- project: alexander-chernov/helm/common
ref: master
file: /.gitlab/schema-sync-check.yml
That include adds two jobs: generate-consumer-schema regenerates the merged
schema once and keeps it as an artifact (it carries its own copy of the merge
logic, so it needs no fetch at all), then check-common-schema-sync just diffs
that artifact against the values.schema.json you committed. Nothing in this
chart's repo needs vendoring either way, CI carries its own copy of the merge
logic and local development fetches it fresh each time (see the command
above).
Quick examples
Basic web application (Deployment + Service + Ingress)
image:
repository: nginx
tag: "1.27"
pullPolicy: IfNotPresent
workload:
main:
replicas: 2
podSpec:
containers:
main:
probes:
liveness:
path: /healthz
readiness:
path: /ready
service:
main:
ports:
main:
port: 80
ingress:
main:
enabled: true
hosts:
- host: myapp.example.com
paths:
- path: /
pathType: Prefix
integrations:
traefik:
enabled: true
entrypoints:
- websecure
certManager:
enabled: true
certificateIssuer: letsencrypt-prod
StatefulSet with persistent storage
workload:
main:
type: StatefulSet
podSpec:
containers:
main:
image:
repository: postgres
tag: "16"
service:
main:
ports:
main:
port: 5432
persistence:
data:
enabled: true
type: pvc
size: 10Gi
mountPath: /var/lib/postgresql/data
accessMode: ReadWriteOnce
Managed Postgres cluster via CloudNativePG
Provision a full HA Postgres cluster with scheduled backups -- no separate operator chart needed beyond the CNPG operator itself.
cnpg:
main:
enabled: true
instances: 2
type: postgres
pgVersion: 16
cluster:
storage:
size: 20Gi
backups:
enabled: true
serverName: myapp-db
credentials: my-s3-creds
scheduledBackups:
daily:
schedule: "0 2 * * *"
backupOwnerReference: self
RBAC for a controller workload
serviceAccount:
main:
enabled: true
primary: true
rbac:
main:
enabled: true
primary: true
clusterWide: false
rules:
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get", "list", "watch"]
subjects:
- kind: ServiceAccount
name: "{{ include \"tc.v1.common.lib.chart.names.fullname\" . }}"
Network isolation with NetworkPolicy
networkPolicy:
restrict-ingress:
enabled: true
policyType: ingress-egress
targetSelector: main
ingress:
- ports:
- protocol: TCP
port: 8080
from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
egress:
- ports:
- protocol: TCP
port: 5432
to:
- podSelector:
matchLabels:
app.kubernetes.io/component: database
Additional raw manifests
Render any Kubernetes object alongside the chart without a separate template file.
Values support tpl so you can reference chart helpers.
additionalManifests:
external-secret:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: "{{ .Release.Name }}-db-creds"
spec:
refreshInterval: 1m
secretStoreRef:
name: vault
kind: ClusterSecretStore
target:
name: "{{ .Release.Name }}-db-creds"
data:
- secretKey: password
remoteRef:
key: secret/myapp/db
property: password
Wait for an external dependency before starting
No dedicated values surface for this (a prior, narrower version only covered five
hardcoded datastores; see the Guide's "Waiting for an external dependency" section
for why it was removed). A plain initContainer covers any dependency, not just
those five, and only runs on the workload(s) you actually add it to:
# imageSelector accepts any top-level key that has repository/tag, not just
# the chart's own predefined ones, define whatever tool image you need here.
waitImage:
repository: busybox
tag: "1.38"
workload:
main:
podSpec:
initContainers:
wait-for-postgres:
enabled: true
type: init
imageSelector: waitImage
command:
- /bin/sh
- -c
args:
- |
until nc -z -w2 my-postgres-host 5432; do
echo "Waiting for postgres..."
sleep 2
done
Key features
| Feature | Values key |
|---|---|
| Deployment / StatefulSet / DaemonSet / Job / CronJob | workload |
| ClusterIP / LoadBalancer / NodePort / ExternalName services | service |
| Ingress with Traefik and cert-manager integration | ingress |
| Persistent volumes and volume claim templates | persistence |
| ConfigMaps and Secrets | configmap, secret |
| RBAC (Role + RoleBinding or cluster-wide) | rbac, serviceAccount |
| cert-manager Certificate resources | certificate |
| CloudNativePG clusters with backups and poolers | cnpg |
| NetworkPolicy (ingress, egress, or both) | networkPolicy |
| HorizontalPodAutoscaler / VerticalPodAutoscaler | hpa, vpa |
| PodDisruptionBudget | podDisruptionBudget |
| Traefik Middleware CRDs | ingressMiddlewares |
| Any raw Kubernetes manifest | additionalManifests |
Chart author's guide: contract and gotchas
The docs/ tree was an unmodified snapshot from the TrueCharts
upstream at fork time (commit b0181cd); auditing it in full is out of scope here, but
it had drifted from this fork's actual values.yaml on the resources and
securityContext.container.UMASK defaults, both corrected alongside this section (see
the callout under Resources below for what changed and why). Everything
in this section was confirmed against the current templates/ source directly, not
copied from docs/; treat it as authoritative over docs/ for the behavior described
here.
image / imageSelector
image.repositoryandimage.tagare required.imageSelector.tplcallsfailif either is empty, at render time, not at schema-validation time.- There is no fallback to
.Chart.AppVersion. Unlike many hand-rolled charts, an unsetimage.tagis a hard error, never a silent AppVersion substitution. - The library ships its own default under
image:(currentlyghcr.io/traefik/whoami). If your chart'svalues.yamlnever setsimage:at all,failnever fires, because the key exists and has a non-empty tag; you silently deploywhoamiinstead of your app rather than getting an error. Always overrideimage.repository/image.tagin your chart's ownvalues.yaml, even for a chart with exactly one image. image.pullPolicydefaults toIfNotPresentif unset, and must be one ofIfNotPresent,Always,Never, anything else fails.- Multiple images per chart (sidecars, a separate backend image, etc.): each
non-primary container needs
imageSelector: <rootKey>, where<rootKey>is another root-levelvalues.yamlkey shaped exactly likeimage:(repository/tag/pullPolicy). The selector defaults to the literal keyimage, so a container with noimageSelectoralways resolves against the rootimage:block, whichever image key the chart author intended.
# root-level
image:
repository: vendor/frontend
tag: "1.0.0"
backendImage: # <-- any name; must live at root, sibling to `image`
repository: vendor/backend
tag: "1.0.0"
workload:
main:
podSpec:
containers:
backend:
imageSelector: backendImage # <-- required, or this container silently uses `image`
workload
workload.<name>.type must be one of Deployment, StatefulSet, DaemonSet, Job,
CronJob (_workloadValidation.tpl). Exactly one enabled workload must have
primary: true, and inside each workload's podSpec.containers, exactly one enabled
container must have primary: true, both fail render on zero or on more than one.
The library ships a working default skeleton, which is why most charts never set
type/enabled/primary at all: values.yaml already defines workload.main
(type: Deployment, enabled: true, primary: true) with one container main
(enabled: true, primary: true, imageSelector: image, liveness/readiness/startup
probes pre-wired to service.main.ports.main). A chart's own values.yaml is
deep-merged (mergeOverwrite) on top of this default, not the reverse, so setting only
workload.main.replicas or workload.main.podSpec.containers.main.probes works
without repeating type/primary/enabled. Adding a second workload or container
from scratch does need all three set explicitly, there is no second default to merge
onto.
securityContext
Defaults (from values.yaml, not docs/security/securityContext.md, see the callout above):
securityContext:
container:
runAsUser: 568
runAsGroup: 0
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
privileged: false
seccompProfile:
type: RuntimeDefault
capabilities:
add: []
drop: [ALL]
disableS6Caps: false
PUID: 568
UMASK: "0022"
pod:
fsGroup: 568
fsGroupChangePolicy: OnRootMismatch
Override per-container via
workload.<name>.podSpec.containers.<container>.securityContext, merged on top of the
global default (mustMergeOverwrite), same shape as securityContext.container above.
The alekc-charts skill's "read-only root filesystem" recipe is the common override.
runAsNonRoot is computed, not a value you set. _securityContext.tpl derives it
after the merge from runAsUser alone (0 forces runAsNonRoot: false; anything else
forces true), matching Kubernetes' own definition rather than also considering
runAsGroup. Setting runAsNonRoot: false directly in values has no effect except
through runAsUser. This is what lets the default runAsGroup: 0 (root group, chosen
for compatibility with the common "arbitrary UID" image convention, see
docs/security/securityContext.md) coexist with runAsNonRoot: true. It does still
count toward hostUsers's own, separate
"needs the host user namespace" calculation, which checks runAsGroup too, so every
pod gets hostUsers: true by default now.
Running as root (runAsUser: 0) auto-adds Linux capabilities CHOWN, SETUID,
SETGID, FOWNER, DAC_OVERRIDE on top of whatever capabilities.add you set,
because the library assumes a root container is chowning files before dropping
privileges (s6-style init). Set securityContext.container.capabilities.disableS6Caps: true to opt out if your root container doesn't need them.
A container that binds a port ≤ 1024 auto-gains NET_BIND_SERVICE. No values
change needed; the library detects the low port from the container/service wiring.
A persistence entry with type: device forces the whole container privileged:
privileged: true, `allowPr
Deploy common with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has common on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcommon is pinned at v39.0.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply