apache/dolphinscheduler · error · TaskException
fail to create job
Error message
fail to create job
What it means
K8sUtils.createJob() submits a Batch/V1 Job to Kubernetes via the Fabric8 client and wraps any exception in a TaskException with message 'fail to create job'. It is a generic wrapper: the root cause (network, RBAC, validation) is attached as the cause and must be inspected.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java:48
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
@Slf4j
public class K8sUtils {
private KubernetesClient client;
public void createJob(String namespace, Job job) {
try {
client.batch()
.v1()
.jobs()
.inNamespace(namespace)
.create(job);
} catch (Exception e) {
throw new TaskException("fail to create job", e);
}
}
public void deleteJob(String jobName, String namespace) {
try {
client.batch()
.v1()
.jobs()
.inNamespace(namespace)
.withName(jobName)
.delete();
} catch (Exception e) {
throw new TaskException("fail to delete job", e);
}
}
public Boolean jobExist(String jobName, String namespace) {
try {View on GitHub (pinned to 02eac45a1b)
Solutions
- Inspect the chained cause (e.getCause()) in worker logs to see the real Kubernetes client error.
- Verify cluster connectivity from the worker: kubectl version / get ns using the same kubeconfig.
- Confirm the namespace exists: kubectl get ns <namespace>, and create it if missing.
- Check RBAC: bind the service account to a role allowing create on batch/jobs.
- Validate the Job spec fields (image, resources) rendered by the task.
Example fix
// before
// assuming namespace exists
k8sUtils.createJob(jobName, namespace, jobSpec);
// after
if (k8sUtils.namespaceExists(namespace)) {
k8sUtils.createJob(jobName, namespace, jobSpec);
} else {
throw new IllegalStateException("namespace missing: " + namespace);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!k8sClientReachable() || !namespaceExists(namespace)) {
throw new IllegalStateException("K8s precheck failed before creating job " + jobName);
} Type guard
boolean canCreateJobs(KubernetesClient client, String ns) {
return client.namespaces().withName(ns).get() != null;
} Try / catch
try {
k8sUtils.createJob(jobName, namespace, job);
} catch (TaskException e) {
log.error("create job failed: {}", e.getCause() == null ? e : e.getCause().getMessage(), e);
throw e;
} Prevention
- Pre-check namespace existence and RBAC (can-i create jobs) with the same kubeconfig.
- Validate rendered Job specs against the cluster version before submission.
- Always log the chained cause of TaskException from K8sUtils for triage.
When it happens
Trigger: Calling createJob(jobName, namespace, ...) when the Kubernetes API server is unreachable, the kubeconfig is invalid, the namespace does not exist, RBAC denies Job creation, or the Job spec fails server-side validation.
Common situations: Worker cannot reach the K8s API server (network/DNS); kubeconfig YAML pasted incorrectly; target namespace deleted or misspelled; service account lacks the 'jobs create' permission; invalid job spec (bad image name, resource limits).
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- fail to delete job
- fail to check job:
- fail to register batch job watcher
- namespace %s does not exist in k8s cluster, please create na
- fail to get k8s ApiClient:%s
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/2ed6d6314632c2cf.
Report an issue: GitHub.