Skip to content
All writing

Port Contract and the Helm default() Trap

Five layers of config must agree on port numbers. Helm's default() silently fills in a wrong value. required() catches the mistake at deploy time.

The Five-Layer Config Chain

A containerized service with a port relay has five layers of config. Each layer must match its neighbors. A mismatch at any layer is silent: the pod starts, no error appears, but connections fail.

Two Helm values feed five config layers The Helm values port and debugPort flow into the Deployment template (socat port, Chrome debug port, containerPort, the remote debugging flag) and then into the Service targetPort. Helm values (single source of truth) port: 9222 debugPort: 9223 Deployment template CHROME_FORWARD_PORT = port (socat listens) CHROME_DEBUG_PORT = debugPort (Chrome listens) containerPort = port --remote-debugging-port Service targetPort = port other pods dial this Two Helm values control all five layers

Two Helm values control everything. socat, Chrome, containerPort, and Service.targetPort all trace back to these two numbers.

The default() Trap

Helm default returns a fallback when a value is not set. If the fallback is valid but wrong, the template renders without error. The bug appears only at runtime.

How default() hides a missing port When .somePort is set to 9222, the template renders 9222. When it is not set, default renders 8080, which is wrong but raises no error. {{ .somePort | default 8080 }} .somePort = 9222 result: 9222 correct .somePort = (not set) result: 8080 WRONG, but no error

default() vs required()

When to use default() and when to use required() If any reasonable fallback works, such as replica count, log level, or timeout, default() is safe. If not, such as port numbers, image tags, or secrets, use required() so a missing value fails at deploy time. Can any reasonable fallback work? default() is safe replica count, log level, timeout use required() port numbers, image tags, secrets default(): missing value uses fallback silently required(): missing value fails the template with a clear message A deploy-time error is always better than a silent runtime failure. YES NO

“In review, watch for default followed by a different port number, a different image tag, or an empty string for a secret name. That is a landmine.”


References:

Related: see how the entrypoint starts socat that these values feed into, or go back to the series overview.

↑↓ navigate ↵ open esc close