apache/flink · error · FlinkException

No cluster id was specified. Please specify a cluster to whi

Error message

No cluster id was specified. Please specify a cluster to which you would like to connect.

What it means

Thrown by CliFrontend.runClusterAction when the selected ClusterClientFactory returns a null clusterId from the effective configuration. This means Flink resolved a deployment target type (the factory was found) but the configuration did not contain a concrete, already-running cluster identifier to connect to. It occurs for cluster-action commands — cancel, stop, savepoint, list, checkpoint — that operate on an existing cluster rather than deploying a new one.

Source

Thrown at flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java:1199

     * @throws FlinkException if something goes wrong
     */
    private <ClusterID> void runClusterAction(
            CustomCommandLine activeCommandLine,
            CommandLine commandLine,
            ClusterAction<ClusterID> clusterAction)
            throws FlinkException {
        final Configuration effectiveConfiguration =
                getEffectiveConfiguration(activeCommandLine, commandLine);
        LOG.debug(
                "Effective configuration after Flink conf, and custom commandline: {}",
                effectiveConfiguration);

        final ClusterClientFactory<ClusterID> clusterClientFactory =
                clusterClientServiceLoader.getClusterClientFactory(effectiveConfiguration);

        final ClusterID clusterId = clusterClientFactory.getClusterId(effectiveConfiguration);
        if (clusterId == null) {
            throw new FlinkException(
                    "No cluster id was specified. Please specify a cluster to which you would like to connect.");
        }

        try (final ClusterDescriptor<ClusterID> clusterDescriptor =
                clusterClientFactory.createClusterDescriptor(effectiveConfiguration)) {
            try (final ClusterClient<ClusterID> clusterClient =
                    clusterDescriptor.retrieve(clusterId).getClusterClient()) {
                clusterAction.runAction(clusterClient, effectiveConfiguration);
            }
        }
    }

    /**
     * Internal interface to encapsulate cluster actions which are executed via the {@link
     * ClusterClient}.
     *
     * @param <ClusterID> type of the cluster id
     */

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Add the -m/--target flag with the JobManager address, e.g. `flink cancel -m <host>:<port> <jobId>`
  2. For YARN, include -yid <applicationId> so getClusterId can extract the running YARN application
  3. For Kubernetes, set -Dkubernetes.cluster-id=<id> to target the right session cluster
  4. Verify that the active custom command line (checked in validateAndGetActiveCommandLine) actually parses the connection options you provided

Example fix

// before
flink cancel <jobId>

// after
flink cancel -m my-jm-host:8081 <jobId>
// or for YARN
flink cancel -yid application_123456789_0001 <jobId>
Defensive patterns

Strategy: validation

Validate before calling

// Before calling runClusterAction or any cluster-action CLI command,
// verify the cluster ID resolves non-null from the factory:
ClusterClientFactory<?> factory = serviceLoader.getClusterClientFactory(config);
if (factory.getClusterId(config) == null) {
    throw new IllegalArgumentException("No cluster id in configuration. Set -m/--target, -yid, or -Dkubernetes.cluster-id.");
}

Try / catch

try {
    runClusterAction(activeCommandLine, commandLine, action);
} catch (FlinkException e) {
    if (e.getMessage().contains("No cluster id")) {
        System.err.println("Specify the cluster with -m, -yid, or -Dkubernetes.cluster-id");
    }
    throw e;
}

Prevention

When it happens

Trigger: Running `flink cancel <jobId>`, `flink stop`, or `flink savepoint` without specifying the cluster address (-m / --target) or the deployment-specific cluster identifier (e.g., -yid for YARN application id, -Dexecution.target for Kubernetes session id). The active custom command line resolves a factory but getClusterId returns null because no connection target is configured.

Common situations: Using the CLI against a YARN cluster but forgetting -yid <appId>; targeting a Kubernetes cluster without -Dkubernetes.cluster-id; pointing at a remote standalone cluster without -m <host>:<port>; misconfigured flink-conf.yaml where jobmanager.rpc.address is unset and no -m override is given.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/671521676bf0a1f7. Report an issue: GitHub.