Job Components
A job component runs a provided container image as a Kubernetes Job workload. You can use this to execute one-off tasks as part of app deployments and updates.
Configuring a Job component
You can configure a job component to execute commands in a container image. Using variables you can reference other component images, and configure environment variables for the job.
Using a Published Image
You can run any published Docker image.
[[components]]name = "list_pods"type = "job"image_url = "bitnami/kubectl"tag = "latest"cmd = ["kubectl"]args = ["get", "pods", "-n", "$NAMESPACE"][components.env_vars]NAMESPACE = "{{.nuon.install.id}}"
resource "nuon_job_component" "list_pods" { name = "list_pods" app_id = nuon_app.<your-app>.id
image_url = "bitnami/kubectl" tag = "latest" cmd = ["kubectl"] args = ["get", "pods", "-n", "$NAMESPACE]
env_var { name = "NAMESPACE" value = "{{.nuon.install.id}}" }}
Using a Custom Image
You can use a custom image by referencing either a docker build or container image using variables.
[[components]]name = "my_job_image"type = "docker_build"dockerfile = "Dockerfile"[components.connected_repo]directory = "components/my-job-image"repo = "<your-org>/<your-repo>"branch = "master"
[[components]]name = "my_job"type = "job"image_url = "{{.nuon.components.my_job_image.image.repository.uri}}"tag = "{{.nuon.components.my_job_image.image.tag}}"cmd = ["my-command"]args = ["arguments", "to", "pass", "to", "my-command"][[components.env_vars]]name = "MY_ENV_VAR"value = "value-for-my-command"
resource "nuon_docker_build_component" "my_job_image" { app_id = nuon_app.<your-app>.id name = "my_job_image"
public_repo = { repo = "<your-org>/<your-repo>" directory = "components/my-job-image" branch = "main" }}
resource "nuon_job_component" "job" { name = "my_job" app_id = nuon_app.<your-app>.id
image_url = "{{.nuon.components.my_job_image.image.repository.uri}}" tag = "{{.nuon.components.my_job_image.image.tag}}" cmd = ["my-command"] args = ["arguments", "to", "pass", "to", "my-command"]
env_var { name = "MY_ENV_VAR" value = "value-for-my-command" }}
Use cases
Job components are designed to be an escape hatch to allow you to run any operational commands needed.
Common use cases include:
- running database imports to import data for a customer install.
- running database migrations.
- running operational debugging commands to inspect an install.
- deploying or provisioning custom resources not supported by other components.
- modifying
kubernetes
resources, such as adding secrets.