Ephemeral Agents
The following will explain how to run the executor component in"ephemeral" mode.
These environment variables can be used to customize the API component:
ExecutorEphemeralNamespace (Default value: "terrakube")
ExecutorEphemeralImage (Default value: the executor image of the same version as the API, for example "azbuilder/executor:2.34.0")
ExecutorEphemeralSecret (Default value: "terrakube-executor-secrets" )
The above is basically to control where the job will be created and executed and to mount the secrets required by the executor component
Internally the Executor component will use the following to run in "ephemeral" :
EphemeralFlagBatch (Default value: "false")
EphemeralJobData, this contains all the data that the executor need to run.
Helm Chat Configuration (Automatic)
To enable the ephemeral executor using the helm chart please use the following options:
api:
serviceAccountName: "terrakube-api-service-account"
ephemeralExecution:
enabled: trueManual Configuration
To use Ephemeral executors we need to create the following configuration:
Service Account Creation
Role Creation
Role Binding Creation
Workspace Configuration
Add the environment variable TERRAKUBE_ENABLE_EPHEMERAL_EXECUTOR=1 like the image below

Workspace Execution
Now when the job is running internally Terrakube will create a K8S job and will execute each step of the job in a "ephemeral executor"

Internal Kubernetes Job Example:

Plan Running in a pod:

Apply Running in a different pod:

Executor secrets in ephemeral jobs
By default the API mounts the executor secret (ExecutorEphemeralSecret, default terrakube-executor-secrets) into each ephemeral job as files that the executor loads at startup, instead of injecting them as environment variables. An init container with a restricted security context copies them into a memory-backed volume. The executor image used for ephemeral jobs must be 2.34.0 or later; to keep the old behaviour with an older image set ExecutorEphemeralEmptyDirSecret=false on the API.
Job Controls
The following environment variables on the API component control the Kubernetes Job created for each ephemeral step. They apply to every ephemeral job in the cluster and cannot be overridden per workspace.
Variable
Helm value (api.ephemeralExecution.*)
Default
Description
ExecutorEphemeralActiveDeadlineSeconds
activeDeadlineSeconds
unset (no deadline)
Maximum seconds a job may run before Kubernetes terminates it as failed.
ExecutorEphemeralBackoffLimit
backoffLimit
unset (Kubernetes default, 6)
Number of retries before the job is marked failed. Set to 0 for at-most-once execution.
ExecutorEphemeralTerminationGracePeriodSeconds
terminationGracePeriodSeconds
60
Seconds the pod gets to shut down cleanly after SIGTERM before Kubernetes sends SIGKILL.
ExecutorEphemeralTtlSecondsAfterFinished
ttlSecondsAfterFinished
30
Seconds after completion before the job and its pod are deleted.
Active deadline
The deadline is counted from the Job's
startTime, which is set before the pod is scheduled or its image is pulled. Node autoscaling and large image pulls count against it, so avoid very small values.It is Job-wide: every retry allowed by
backoffLimitshares the one deadline, and the deadline takes precedence over any retries left.A single cluster-wide value has to fit your longest legitimate apply, otherwise long runs are terminated with
DeadlineExceeded.When the deadline fires, the run fails with the message
Executor pod is shutting down.If the pod is killed before the executor has started (still scheduling or pulling its image), nothing reports back to the API. The run is failed by the API's heartbeat sweep after
ReconciliationHeartbeatGracePeriodSeconds(default 300), not immediately.
Backoff limit
Each retry runs in a brand-new pod. A step that died while holding the Terraform state lock will fail immediately on that lock when retried, and a step that had already applied non-idempotent changes may duplicate them. Set backoffLimit to 0 if you want a failed step to fail once and stop.
Termination grace period
On shutdown Terraform receives SIGTERM and 10 seconds (fixed by the Terraform client used by the executor) to exit before it is killed. That wait only starts after Spring's shutdown phase, which by default can take up to 30 seconds (spring.lifecycle.timeout-per-shutdown-phase) while the running job is stopped. The default of 60 seconds covers both, but raising terminationGracePeriodSeconds does not give Terraform more than the 10 seconds, so a long-running apply can still be killed while holding the state lock.
TTL after finished
The default of 30 seconds is a tight window to run kubectl describe pod or kubectl logs on a pod that failed before the executor started (image pull failure, missing secret, out-of-memory). Raise it, for example to 300-600, if you need more time to troubleshoot.
Node Selector.
If required you can specify the node selector configuration where the pod will be created using something like the following:
The above will be the equivalent to use the Kubernetes YAML like:
Using Environment Variables for Configuration
The following environment variables can be used to customize the ephemeral executor adding the following values inside the workspace settings:
EPHEMERAL_CONFIG_NODE_SELECTOR_TAGS
Example: key1=value1;key2=value2
EPHEMERAL_CONFIG_SERVICE_ACCOUNT
Example: myserviceaccount
EPHEMERAL_CONFIG_ANNOTATIONS
Example: key1=value1;key2=value2
EPHEMERAL_CONFIG_TOLERATIONS
Example:
key:operator:effect
EPHEMERAL_CONFIG_MAP_NAME
EPHEMERAL_CONFIG_MAP_MOUNT_PATH
EPHEMERAL_CPU_REQUEST
Example:
100mor1
EPHEMERAL_CPU_LIMIT
Example:
200mor2
EPHEMERAL_MEMORY_REQUEST
Example:
50Mior1Gi
EPHEMERAL_MEMORY_LIMIT
Example:
100Mior2Gi
EPHEMERAL_STORAGE_REQUEST
Example:
2Gi
EPHEMERAL_STORAGE_LIMIT
Example:
4Gi
More information can be found inside this code
Last updated
Was this helpful?