zhisheng17/flink-learning · error · RuntimeException

Failed to find Deployment named {} in namespace {}

Error message

Failed to find Deployment named {} in namespace {}

What it means

createTaskManagerPod() looks up the JobManager Deployment named after the clusterId to copy its pod template, and throws this RuntimeException if the fabric8 client returns null (no such Deployment in the namespace). A TaskManager pod cannot be created without the master Deployment's spec.

Source

Thrown at flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java:129

		this.internalClient
			.resourceList(accompanyingResources)
			.inNamespace(this.namespace)
			.createOrReplace();
	}

	@Override
	public CompletableFuture<Void> createTaskManagerPod(KubernetesPod kubernetesPod) {
		return CompletableFuture.runAsync(
			() -> {
				if (masterDeploymentRef.get() == null) {
					final Deployment masterDeployment =
						this.internalClient
							.apps()
							.deployments()
							.withName(KubernetesUtils.getDeploymentName(clusterId))
							.get();
					if (masterDeployment == null) {
						throw new RuntimeException(
							"Failed to find Deployment named "
								+ clusterId
								+ " in namespace "
								+ this.namespace);
					}
					masterDeploymentRef.compareAndSet(null, masterDeployment);
				}

				// Note that we should use the uid of the master Deployment for the OwnerReference.
				setOwnerReference(masterDeploymentRef.get(), Collections.singletonList(kubernetesPod.getInternalResource()));

				LOG.debug(
					"Start to create pod with spec {}{}",
					System.lineSeparator(),
					KubernetesUtils.tryToGetPrettyPrintYaml(
						kubernetesPod.getInternalResource()));

				this.internalClient

View on GitHub (pinned to d731cee761)

Solutions

  1. Verify the Deployment exists: kubectl get deployment <deployment-name-of-clusterId> -n <namespace>.
  2. Ensure the KubeClient's namespace and clusterId match how the JobManager was deployed.
  3. Create the JobManager Deployment (createJobManagerComponent) before requesting TaskManager pods.
  4. If this happens during shutdown, guard pod creation against activeResourceManager teardown — do not create TMs after the deployment was removed.

Example fix

// before: TM pod requested for nonexistent cluster
client.createTaskManagerPod(tmPodTemplate).get();
// after: verify deployment first
if (client.getServiceNames() != null && kubectlHasDeployment(clusterId)) {
    client.createTaskManagerPod(tmPodTemplate).get();
}
Defensive patterns

Strategy: validation

Validate before calling

// confirm the JobManager Deployment exists before creating TM pods
boolean exists = kubeClient
    .listPods(Collections.emptyMap()) != null; // plus: kubectl get deployment <deployment-name(clusterId)> -n <ns>

Try / catch

try {
    client.createTaskManagerPod(template).get();
} catch (Exception e) {
    if (e.getMessage() != null && e.getMessage().contains("Failed to find Deployment")) {
        // cluster is gone: stop requesting workers
    }
}

Prevention

When it happens

Trigger: createTaskManagerPod called before the JobManager Deployment exists, after it was deleted (e.g. by killing a session-mode job), or with a clusterId that doesn't match the deployed Deployment name (getDeploymentName(clusterId) mismatch).

Common situations: Submitting TaskManager pods to a session cluster that was already torn down; using the wrong clusterId/namespace combination (deployed in 'flink' but client configured with 'default'); native-K8s lifecycle races during teardown.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06). Data as JSON: /api/errors/312a3cbd40296c1d. Report an issue: GitHub.