{"record":{"id":"468206d0dcd5bf09","repo":"zhisheng17/flink-learning","slug":"could-not-create-kubernetes-cluster-clusterid","errorCode":null,"errorMessage":"Could not create Kubernetes cluster \"${clusterId}\".","messagePattern":"Could not create Kubernetes cluster \"(.+?)\"\\.","errorType":"exception","errorClass":"ClusterDeploymentException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java","lineNumber":258,"sourceCode":"\t\t\tfinal KubernetesJobManagerParameters kubernetesJobManagerParameters =\n\t\t\t\tnew KubernetesJobManagerParameters(flinkConfig, clusterSpecification);\n\n\t\t\t//todo：构建 jm spec\n\t\t\tfinal KubernetesJobManagerSpecification kubernetesJobManagerSpec =\n\t\t\t\tKubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(kubernetesJobManagerParameters);\n\n\t\t\t//todo：create jm deployment\n\t\t\tclient.createJobManagerComponent(kubernetesJobManagerSpec);\n\n\t\t\treturn createClusterClientProvider(clusterId);\n\t\t} catch (Exception e) {\n\t\t\ttry {\n\t\t\t\tLOG.warn(\"Failed to create the Kubernetes cluster \\\"{}\\\", try to clean up the residual resources.\", clusterId);\n\t\t\t\tclient.stopAndCleanupCluster(clusterId);\n\t\t\t} catch (Exception e1) {\n\t\t\t\tLOG.info(\"Failed to stop and clean up the Kubernetes cluster \\\"{}\\\".\", clusterId, e1);\n\t\t\t}\n\t\t\tthrow new ClusterDeploymentException(\"Could not create Kubernetes cluster \\\"\" + clusterId + \"\\\".\", e);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void killCluster(String clusterId) throws FlinkException {\n\t\ttry {\n\t\t\tclient.stopAndCleanupCluster(clusterId);\n\t\t} catch (Exception e) {\n\t\t\tclient.handleException(e);\n\t\t\tthrow new FlinkException(\"Could not kill Kubernetes cluster \" + clusterId);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void close() {\n\t\ttry {\n\t\t\tclient.close();\n\t\t} catch (Exception e) {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java#L240-L276","documentation":"Thrown by deployClusterInternal when creating the Kubernetes cluster (deploying JobManager/TaskManager resources) fails. The handler first attempts client.stopAndCleanupCluster(clusterId) to remove residual resources, then wraps the original exception in a ClusterDeploymentException.","triggerScenarios":"deployClusterInternal (reached from deploySessionCluster/deployApplicationCluster) when creating Kubernetes resources throws — e.g. fabric8/kube client API errors, quota exceeded, image pull failures, invalid pod templates.","commonSituations":"Insufficient namespace RBAC to create deployments/services; resource quota limits exceeded; invalid or non-pullable JobManager image (kubernetes.container-image); malformed pod template configuration; Kubernetes API server unreachable.","solutions":["Inspect the cause attached to the ClusterDeploymentException and cluster events: kubectl describe deploy/svc, kubectl get events in the namespace.","Verify RBAC: the service account needs permissions to create deployments, services, configmaps.","Check the container image name/tag is correct and pullable from the cluster (kubernetes.container-image.pull-policy).","Check namespace ResourceQuotas and LimitRanges against requested CPU/memory.","If cleanup also failed (log line 'Failed to stop and clean up'), manually delete residual resources: kubectl delete deploy,svc,cm -l app=<clusterId>."],"exampleFix":"// before\ncfg.setString(KubernetesConfigOptions.CONTAINER_IMAGE, \"flink:latest\");\n// after: pin a pullable image and namespace with proper RBAC\ncfg.setString(KubernetesConfigOptions.CONTAINER_IMAGE, \"apache/flink:1.17.1\");\ncfg.setString(KubernetesConfigOptions.NAMESPACE, \"flink-prod\");\ndescriptor.deployApplicationCluster(spec, appConfig);","handlingStrategy":"try-catch","validationCode":"// preflight: RBAC + quota sanity\nkubeClient.getService(KubernetesService.ServiceType.REST_SERVICE, clusterId); // proves service creation permissions","typeGuard":null,"tryCatchPattern":"try {\n    descriptor.deployApplicationCluster(spec, appConfig);\n} catch (ClusterDeploymentException e) {\n    LOG.error(\"Deploy failed for {}\", clusterId, e.getCause());\n    // cleanup residual resources, fix RBAC/quota/image, retry\n}","preventionTips":["Grant deploy/service/configmap RBAC to the Flink service account","Pin valid, pullable container images","Check namespace ResourceQuotas before large deployments","kubectl get events to catch scheduling/image errors early"],"tags":["kubernetes","flink","cluster-deployment","resource-creation"],"backgroundTag":"api-request-failed","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}