base

by Das Meta

Helm chartv0.7.0App 0.4.0

A Base Helm chart for Kubernetes

About this chart

Introduction

This chart provides a base template helpers which can be used to develop new charts using Helm package manager.

Prerequisites

  • Kubernetes 1.18+
  • Helm 3.7.1

commands

# minimal setup
helm repo add dasmeta https://dasmeta.github.io/helm # adds dasmeta helm chart into helm repos list
helm upgrade --install -n default my-test-app dasmeta/base --version 0.3.11 -f ./my-test-app.values.yaml # create/change helm release, you have to have ./my-test-app.values.yaml created, check examples to know how to create/configure it

# to get diff and debug check what will be created/changed on apply
helm plugin install https://github.com/databus23/helm-diff # to install helm diff plugin
helm diff upgrade --install -n default my-test-app dasmeta/base --version 0.3.11 -f ./my-test-app.values.yaml # shows diff of what will be create/changed

# for case you have the chart as dependency
helm dependency update # in case you added `dasmeta/base` in helm chart Chart.yaml as dependency this command will pull/update dependency
helm upgrade --install my-app . # allows to run current directory helm chart

The default values and related description/examples can be found in ./values.yaml file

Key values

KeyDescriptionDefault / Example
image.repositoryMain container image repositoryset per app
image.tagImage tag. Ignored when image.digest is set. Falls back to Chart.appVersion when emptyset per app
image.digestOptional image digest. When non-empty, the main container is repository@digest and this takes precedence over image.tag""
initContainers[].image.digestOptional digest for one init container. When non-empty, that init container is repository@digest and this takes precedence over its image.tag. An empty or omitted digest keeps repository:tagunset
initContainers[].securityContextOptional Kubernetes container security context, rendered as supplied for each init container. Also supported in single-object format. Omitted, empty or null values omit the field; the main container's context is not copiedunset
containerPortMain container portset per app
service.enabledCreate Servicetrue
service.typeService typeClusterIP
service.sessionAffinityService session affinity (None or ClientIP)unset / no affinity
service.sessionAffinityConfigOptional sessionAffinityConfig (e.g. ClientIP timeout){}
ingress.enabledEnable Ingressfalse
configEnv vars for main container (map)example in values.yaml
externalSecretsApiVersionAPI version of the generated ExternalSecret. Set to external-secrets.io/v1beta1 if the cluster's external secret operator does not serve v1external-secrets.io/v1
gatewayApi.enabledEnable Gateway API (subchart)false
pdb.enabledCreate a PodDisruptionBudget. Leave unset for the safe default: created automatically when the effective replica floor is 2 or more, omitted below that. true at a floor below 2 is refusedunset (derived)
pdb.maxUnavailableCeiling on simultaneously-unavailable replicas. Absolute number or percentage string. Recommended form; can never become a zero-eviction budget"25%" (applied by the template)
pdb.minAvailableFloor on available replicas. Mutually exclusive with maxUnavailable. Must stay below the effective replica floor. Never set to autoscaling.minReplicasunset
pdb.allowZeroEvictionsAllow a budget that permits zero voluntary evictions, for a workload rolled by hand that automation must never evict. Renders with a warning and an annotation rather than being refusedfalse
pdb.selectorOverrideLabels the budget selects on. Only needed where the chart cannot derive them — see Flagger belowunset (derived)
pdb.pdbNameOverride the generated PodDisruptionBudget namechart fullname
terminationGracePeriodSecondsTime Kubernetes waits for the pod to shut down before killing it. Must exceed the defaultLifecycle.preStop sleepunset (Kubernetes default 30)

0.5.0

The main container can be pinned by digest. Set image.digest to a full digest such as sha256:<64 hex chars>. The rendered image is <repository>@<digest>. When image.digest is empty, rendering is unchanged: image.tag is used, and an empty tag still falls back to Chart.appVersion. If both image.digest and image.tag are set, the digest wins.

image:
  repository: my-registry/my-app
  digest: "sha256:<full-image-digest>"

See examples/base/with-image-digest.yaml. This applies to the main application container. Extra containers still use their own image tag.

0.6.0

Each init container can be pinned by digest the same way. Set initContainers[].image.digest. That init container renders as <repository>@<digest>. When the digest is missing or empty, the init container still renders repository:tag. If both image.digest and image.tag are set on an init container, the digest wins. Other init container fields are unchanged.

initContainers:
  - name: migrate
    image:
      repository: my-registry/migrate
      digest: "sha256:<full-image-digest>"
    command: ["/bin/sh", "-c"]
    args: ["echo migrated"]

See examples/base/with-init-container-digest.yaml.

0.7.0

Init containers now support an optional securityContext. Each non-empty context is rendered as supplied, including nested fields and explicit false values. This works with both the list format and the legacy single-object initContainers format.

initContainers:
  - name: migrator-service
    image:
      repository: example/migrator
      tag: example
      pullPolicy: IfNotPresent
    securityContext:
      runAsNonRoot: true
      runAsUser: 1002
      runAsGroup: 1001
      privileged: false
      allowPrivilegeEscalation: false
      capabilities:
        drop:
          - ALL

Omit securityContext, or set it to {} or null, to preserve the existing output without a container-level context. The chart does not copy the main container's securityContext to init containers. Pod-level settings remain controlled by podSecurityContext; Kubernetes applies overlapping settings according to its security context rules.

See examples/base/with-init-container-security-context.yaml. Run the regression cases with ./tests/run.sh base init-security-context.

Upgrading to 0.4.0

This release changes rendered output. Read this before bumping.

PodDisruptionBudgets are now created by default

A budget is created automatically when the effective replica floor is 2 or more, defaulting to maxUnavailable: "25%". The effective replica floor is autoscaling.minReplicas when autoscaling is enabled, and replicaCount otherwise. Below a floor of 2 no budget is created, because a budget over a single replica either blocks every drain or protects nothing.

Previously pdb.enabled defaulted to false, so most services had no budget at all and a node drain could evict every replica at once, emptying the service's endpoints for one to two minutes.

Budgets that permit zero evictions are now refused

The chart now fails to render any budget that permits no voluntary eviction at the replica floor. This is deliberate and it is the more important half of the change.

Such a budget blocks every drain-based operation: node consolidation stalls, reclaimed-capacity (spot) replacement stalls, and managed node group upgrades fail on pod eviction. The reported symptom is that node scaling or the cluster upgrade is stuck, which sends the investigation somewhere other than the service that caused it.

Refused configurations:

ConfigurationWhy
minAvailable >= effective replica floorpermits nothing
maxUnavailable: 0permits nothing
a percentage resolving to 0 permitted evictionsonly "0%" can, since budget percentages round up
a value outside the IntOrString domainnegative numbers, percentages above 100, and anything that is neither
both minAvailable and maxUnavailable setthe Kubernetes API accepts only one
pdb.enabled: true at a replica floor below 2no budget over a single replica is both safe and useful

Every message above names pdb.allowZeroEvictions as the way through, so the escape hatch is discoverable from the failure rather than from this document.

When a zero-eviction budget is correct

Some workloads are rolled by hand, pod by pod, after cooling an internal process down first, and must never be evicted by automation. For those, a budget permitting nothing is the right answer rather than a mistake:

autoscaling:
  enabled: true
  minReplicas: 3
  maxReplicas: 3
pdb:
  enabled: true
  minAvailable: 3            # equals the floor, permits nothing -- deliberately
  allowZeroEvictions: true   # say so, and the chart renders it
podAnnotations:
  karpenter.sh/do-not-disrupt: "true"   # stop the autoscaler retrying a drain it cannot finish

The chart then renders the budget, annotates it dasmeta.io/zero-evictions, and prints a warning on every install and upgrade. Nothing is silenced: node drains still block, node group upgrades still fail on eviction, and the node stops receiving AMI patches until someone moves the workload. The flag records that those consequences are intended, and the annotation is what tells whoever finds the stuck drain months later that it was a decision.

The default budget tracks the current replica count

maxUnavailable defaults to "25%" at every replica floor.

A percentage rather than a number computed by the chart, because Kubernetes resolves a percentage at runtime against the current expected pod count, while a number is fixed at template time from the floor and never moves. For a service with minReplicas: 10, maxReplicas: 100:

running replicasabsolute 2"25%"
1022
2025
100225

25% is not arbitrary: it is what a Deployment rollout already does by default, so draining paces at a rate the service demonstrably tolerates every time it is deployed.

Rounding. The disruption controller resolves both minAvailable and maxUnavailable percentages rounding up. That is not the same as a Deployment rolling update, where maxUnavailable rounds down — so "25%" is 1 permitted eviction at a floor of 2 under budget rules and 0 under rollout rules. Only "0%" can resolve to zero.

This paces draining, not rollouts. A Deployment rollout deletes pods directly and never uses the Eviction API, so its speed comes from strategy.rollingUpdate (Kubernetes defaults to 25% unavailable / 25% surge) and a PodDisruptionBudget has no say in it. What the budget paces is node drains: consolidation, reclaimed-capacity replacement, and cluster upgrades.

Override in either direction — an absolute number to pin it regardless of scale, or a different percentage.

When the chart does NOT create a budget for you

Automatic creation needs the chart to own both the workload and the selector. It stands down where it does not, because an unrequested budget there is wrong rather than merely useless:

situationwhy
workloadType is not Deploymentthe workload template does not render, so the budget would select nothing
selectorLabelsOverride is setthe release points at another release's pods. Two budgets over one pod makes it un-evictable, because the eviction API refuses a pod covered by more than one

Setting pdb.enabled: true still creates one in both cases — the author has taken ownership, and the guards above only govern what happens unasked.

Flagger

Under a Flagger rolloutStrategy the budget follows the generated primary, not the canary:

  • with autoscaling enabled, the floor is rolloutStrategy.configs.primaryScalerMinReplicas, falling back to autoscaling.minReplicas exactly as Flagger does
  • with autoscaling disabled, Flagger emits no autoscalerRef at all and the primary mirrors the Deployment, so the floor is replicaCount
  • the selector is the Deployment's full selector — selectorLabels plus anything added through matchLabels — with one key suffixed -primary: the first of app, name, app.kubernetes.io/name that is present, which is how Flagger chooses it

Both matter. Flagger scales the canary Deployment to zero between rollouts, so a budget derived from the canary would take its floor from a workload that is not serving and select pods that do not exist — protection that looks present and is not. The bundled canary example has a canary floor of 1 and a primary floor of 5, so reading the canary would have rendered no budget at all.

Flagger walks its -selector-labels list in order and suffixes the first key it finds in the target's selector, leaving the rest untouched. A release whose selector carries app therefore gets app=<value>-primary while app.kubernetes.io/name is unchanged — assuming the last key is the suffixed one produces a selector matching zero pods. Where the selector contains none of those keys the chart refuses rather than guessing, because Flagger itself would refuse the canary.

That order is Flagger's -selector-labels default, and it is a controller-wide flag this chart does not set — so there is deliberately no per-release option to change it here. One would alter only the budget while Flagger kept its own order, which

Deploy base with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has base 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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartbase is pinned at v0.7.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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