Run a one-off Kubernetes Job
Run a command in a container as a Job in the cluster, show its log, and fail the step if the Job fails or does not finish in time. The Job does not retry on its own.
Install v1.0.0
Installs the template into your Argo namespace. The URL is pinned to this version.
kubectl apply -n argo -f https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml
Or with the Argo CLI:
argo template create -n argo https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml
Facts
- Category
- Kubernetes
- Tags
- kubectl kubernetes
- Entrypoint
run- Template SHA-256
41d4568114e12631cdaf3c4311564fda800edf6435791728b4b158b6962f8271- Source
- kubectl-run-job at catalog commit 67458f7
- API
- item document, latest template.yaml
Images and provenance
Every image is pinned by digest, so a rebuilt tag can never change what this version runs.
| Repository | Tag | Digest |
|---|---|---|
cgr.dev/chainguard/kubectl | latest-dev | sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba |
Parameters
| Name | Description | Default |
|---|---|---|
image required |
Container image the Job runs. Example postgres:18-alpine |
none |
name required |
Name for the Job. It must not already exist in the namespace. Example reindex-2026-10 |
none |
cleanup |
Set to "true" to delete the Job once its log has been shown. One of true, false |
true |
command |
Shell command to run in the image, which needs sh. Leave blank to run the image's own entrypoint. Example pg_isready -h db.default.svc |
empty |
namespace |
Namespace the resource lives in. Example default |
default |
service-account |
Service account the Job runs as. Leave blank for the namespace default. | empty |
timeout-seconds |
Seconds to wait for the Job to finish before failing the step. | 600 |
WorkflowTemplate
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: kubectl-run-job
labels:
dagweave.io/catalog-item: kubectl-run-job
annotations:
dagweave.io/catalog-version: "1.0.0"
dagweave.io/catalog-category: "Kubernetes"
spec:
entrypoint: run
templates:
- name: run
metadata:
annotations:
dagweave.io/local-support: unsupported
dagweave.io/local-support-reason: >-
This step runs kubectl with whatever identity the pod is given. On Dagweave
Local that is the default service account of the hidden cluster's argo
namespace, which Argo's quick-start install grants create, get and patch on pods
and create and get on workflows, and nothing anywhere else. Creating a Job is
outside what that account may do, so the step fails on a 403 rather than
touching anything. The cluster you meant is one this run cannot reach.
inputs:
parameters:
- name: name
- name: image
- name: command
default: ""
- name: namespace
default: "default"
- name: service-account
default: ""
- name: timeout-seconds
default: "600"
- name: cleanup
default: "true"
container:
# cgr.dev/chainguard/kubectl:latest-dev
image: cgr.dev/chainguard/kubectl@sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba
command: [sh, -c]
args:
- |
set -eu
set -- "${NAME}" -n "${NAMESPACE}" --image="${IMAGE}" --dry-run=client -o json
if [ -n "${COMMAND}" ]; then set -- "$@" -- sh -c "${COMMAND}"; fi
kubectl create job "$@" \
| kubectl patch --local -f - --type=merge -p '{"spec":{"backoffLimit":0}}' -o json > /tmp/job.json
if [ -n "${SERVICE_ACCOUNT}" ]; then
kubectl set serviceaccount --local -f /tmp/job.json "${SERVICE_ACCOUNT}" -o json > /tmp/job-sa.json
cp /tmp/job-sa.json /tmp/job.json
fi
kubectl create -f /tmp/job.json
status=timeout
end=$(( $(date +%s) + TIMEOUT_SECONDS ))
while [ "$(date +%s)" -lt "${end}" ]; do
if [ "$(kubectl get job "${NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}')" = "True" ]; then status=complete; break; fi
if [ "$(kubectl get job "${NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.conditions[?(@.type=="Failed")].status}')" = "True" ]; then status=failed; break; fi
sleep 5
done
kubectl logs "job/${NAME}" -n "${NAMESPACE}" --all-containers || true
if [ "${CLEANUP}" = "true" ]; then kubectl delete job "${NAME}" -n "${NAMESPACE}" --wait=false; fi
echo "job ${NAME}: ${status}"
[ "${status}" = "complete" ]
env:
- name: NAME
value: "{{inputs.parameters.name}}"
- name: IMAGE
value: "{{inputs.parameters.image}}"
- name: COMMAND
value: "{{inputs.parameters.command}}"
- name: NAMESPACE
value: "{{inputs.parameters.namespace}}"
- name: SERVICE_ACCOUNT
value: "{{inputs.parameters.service-account}}"
- name: TIMEOUT_SECONDS
value: "{{inputs.parameters.timeout-seconds}}"
- name: CLEANUP
value: "{{inputs.parameters.cleanup}}"
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
memory: 256Mi
Version history
Read from the item's changelog. Each version has its own JSON document; the pinned catalogue vendors the manifest of the latest one, so that is the version that installs.
-
1.0.0 latest 2026-10-18
Initial release.
kubectl apply -n argo -f https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yamlargo template create -n argo https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml
Run it once
After installing, from the command line.
argo submit -n argo --from workflowtemplate/kubectl-run-job \
-p image=postgres:18-alpine \
-p name=reindex-2026-10
Workflow that references it
A Workflow with the required parameters filled from the examples.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: kubectl-run-job-
spec:
workflowTemplateRef:
name: kubectl-run-job
arguments:
parameters:
- name: image
value: "postgres:18-alpine"
- name: name
value: "reindex-2026-10"
As a step of a larger workflow
steps:
- - name: kubectl-run-job
templateRef:
name: kubectl-run-job
template: run