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

  1. Inspect the chained cause (e.getCause()) in worker logs to see the real Kubernetes client error.
  2. Verify cluster connectivity from the worker: kubectl version / get ns using the same kubeconfig.
  3. Confirm the namespace exists: kubectl get ns <namespace>, and create it if missing.
  4. Check RBAC: bind the service account to a role allowing create on batch/jobs.
  5. 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

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


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/2ed6d6314632c2cf. Report an issue: GitHub.