Container
Read the containers of a workload (a Deployment, StatefulSet, Job, Pod, …, through its pod template): images, environment variables, ports and counts, by container index or name.
Reference
| Function | Description |
|---|---|
containerCount | Returns the number of containers in the pod spec. |
containerEnv | Returns the value of a named environment variable from the container at the given index. |
containerImage | Returns the container image at the given index. |
containerPort | Returns a containerPort number: by default the first port of the first container; an optional container index and port index choose another. |
containerPortByName | Returns the port number for a named container port. |
containerPorts | Returns the containerPort numbers the container at index exposes. |
hasContainerPort | Reports whether the container exposes a specific port number. |
Functions
containerCount
containerCount returns the number of containers in the pod spec.
{{ containerCount .deployment }} → 2
containerEnv
containerEnv returns the value of a named environment variable from the container at the given index.
{{ containerEnv .deployment "APP_ENV" }} → "production"
containerImage
containerImage returns the container image at the given index.
{{ containerImage .deployment }} → "nginx:1.25"
{{ containerImage .deployment 1 }} → "envoyproxy/envoy:v1.30"
containerPort
containerPort returns a containerPort number: by default the first port of the first container; an optional container index and port index choose another. 0 when there is no such port.
{{ containerPort .deployment }} → 8080
containerPortByName
containerPortByName returns the port number for a named container port. Returns 0 when not found.
{{ containerPortByName .deployment 0 "metrics" }} → 9090
containerPorts
containerPorts returns the containerPort numbers the container at index exposes.
{{ containerPorts .deployment 0 }} → [8080 9090]
hasContainerPort
hasContainerPort reports whether the container exposes a specific port number.
{{ hasContainerPort .deployment 0 9090 }} → true