apache/dolphinscheduler · critical · TaskException

Execute k8s task error

Error message

Execute k8s task error

What it means

AbstractK8sTask.handle() wraps any exception raised while submitting or tracking a Kubernetes task (submitApplication/run/waitTimeout/cancel or output-param processing) into a TaskException("Execute k8s task error", e), after setting exitStatusCode = -1 so the task instance is marked failed. The message is generic; the root cause is in the wrapped cause.

Source

Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/AbstractK8sTask.java:60

     */
    protected AbstractK8sTask(TaskExecutionContext taskRequest) {
        super(taskRequest);
        this.abstractK8sTaskExecutor = new K8sTaskExecutor(taskRequest);
    }

    // todo split handle to submit and track
    @Override
    public void handle(TaskCallBack taskCallBack) throws TaskException {
        try {
            TaskResponse response = abstractK8sTaskExecutor.run(buildCommand());
            setExitStatusCode(response.getExitStatusCode());
            setAppIds(response.getAppIds());
            dealOutParam(abstractK8sTaskExecutor.getTaskOutputParams());
            taskRequest.setVarPool(getParameters().getVarPool());
        } catch (Exception e) {
            log.error("k8s task submit failed with error");
            exitStatusCode = -1;
            throw new TaskException("Execute k8s task error", e);
        }
    }

    // todo
    @Override
    public void submitApplication() throws TaskException {

    }

    // todo
    @Override
    public void trackApplicationStatus() throws TaskException {

    }

    /**
     * cancel application
     *

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Inspect the caused-by chain in the logs (k8s task submit failed with error) to find the root exception.
  2. Verify cluster connectivity and credentials (kubeconfig, API server reachable from the worker).
  3. Validate the task's commands/args YAML and container image settings in the task definition.
  4. Check task timeout configuration and increase it if waitTimeout caused the failure.
  5. Fix the underlying cause, then rerun the task; exitStatusCode -1 marks the instance failed and it can be re-run.

Example fix

// before (opaque)
throw new TaskException("Execute k8s task error", e);
// after (actionable)
log.error("k8s task submit failed", e);
throw new TaskException("Execute k8s task error: " + e.getMessage(), e);
Defensive patterns

Strategy: try-catch

Validate before calling

if (StringUtils.isBlank(k8sTaskParams.getCommand()) || clusterUnreachable()) {
    throw new TaskException("Pre-flight check failed before k8s submit");
}

Try / catch

try {
    taskExecutionContext = abstractK8sTaskExecutor.run(parameter);
} catch (TaskException e) {
    log.error("K8s task failed: {}", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e);
    exitStatusCode = -1;
    throw e;
}

Prevention

When it happens

Trigger: Any exception in the submit flow: K8sTaskExecutor.run() failing (YAML parse error, job submission failure, timeout from waitTimeout), getTaskOutputParams() failing, or dealOutParam/setVarPool throwing.

Common situations: Unreachable or misconfigured Kubernetes cluster (bad kubeconfig/context); invalid command/args YAML in task params; job image missing or pull errors; task timeout exceeded; RBAC denying job creation in the namespace.

Related errors


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