{"record":{"id":"81d4fb40d91b280c","repo":"zhisheng17/flink-learning","slug":"could-not-create-the-restclusterclient","errorCode":null,"errorMessage":"Could not create the RestClusterClient.","messagePattern":"Could not create the RestClusterClient\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java","lineNumber":112,"sourceCode":"\t\t\tif (restEndpoint.isPresent()) {\n\t\t\t\tconfiguration.setString(RestOptions.ADDRESS, restEndpoint.get().getAddress());\n\t\t\t\tconfiguration.setInteger(RestOptions.PORT, restEndpoint.get().getPort());\n\t\t\t} else {\n\t\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\tnew ClusterRetrieveException(\n\t\t\t\t\t\t\t\t\"Could not get the rest endpoint of \" + clusterId));\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\t// Flink client will always use Kubernetes service to contact with jobmanager. So we have a pre-configured web\n\t\t\t\t// monitor address. Using StandaloneClientHAServices to create RestClusterClient is reasonable.\n\t\t\t\treturn new RestClusterClient<>(\n\t\t\t\t\tconfiguration,\n\t\t\t\t\tclusterId,\n\t\t\t\t\tnew StandaloneClientHAServices(getWebMonitorAddress(configuration)));\n\t\t\t} catch (Exception e) {\n\t\t\t\tclient.handleException(e);\n\t\t\t\tthrow new RuntimeException(new ClusterRetrieveException(\"Could not create the RestClusterClient.\", e));\n\t\t\t}\n\t\t};\n\t}\n\n\tprivate String getWebMonitorAddress(Configuration configuration) throws Exception {\n\t\tHighAvailabilityServicesUtils.AddressResolution resolution =\n\t\t\tHighAvailabilityServicesUtils.AddressResolution.TRY_ADDRESS_RESOLUTION;\n\t\tif (configuration.get(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE)\n\t\t\t== KubernetesConfigOptions.ServiceExposedType.ClusterIP) {\n\t\t\tresolution = HighAvailabilityServicesUtils.AddressResolution.NO_ADDRESS_RESOLUTION;\n\t\t\tLOG.warn(\n\t\t\t\t\"Please note that Flink client operations(e.g. cancel, list, stop,\"\n\t\t\t\t\t+ \" savepoint, etc.) won't work from outside the Kubernetes cluster\"\n\t\t\t\t\t+ \" since '{}' has been set to {}.\",\n\t\t\t\tKubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE.key(),\n\t\t\t\tKubernetesConfigOptions.ServiceExposedType.ClusterIP);\n\t\t}\n\t\treturn HighAvailabilityServicesUtils.getWebMonitorAddress(configuration, resolution);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java#L94-L130","documentation":"Thrown when constructing a RestClusterClient for the Kubernetes cluster fails. Before rethrowing, client.handleException(e) inspects the underlying exception and may surface a more specific problem; the original cause is attached to the ClusterRetrieveException.","triggerScenarios":"Calling clusterClientProvider (via deployClusterInternal or direct retrieve) when RestClusterClient construction throws — typically getWebMonitorAddress fails to resolve the cluster IP, HA services cannot be created, or the REST configuration (address/port) is invalid.","commonSituations":"DNS unable to resolve the JobManager service name; misconfigured rest.address/rest.port; Kubernetes API connectivity problems when fetching web monitor address; HA storage misconfiguration in StandaloneClientHAServices setup.","solutions":["Read the cause attached to the ClusterRetrieveException (and any message from handleException) — it names the real failure (DNS, timeout, config).","Verify rest.address/rest.port in the Flink configuration match the exposed JobManager service.","Test DNS resolution of the JobManager service from the launching pod (kubectl exec ... getent hosts <clusterId>).","Confirm Kubernetes API access credentials/permissions (kubeconfig, RBAC) are valid.","If using HA, check the HA storage (ConfigMap) is reachable and configured consistently."],"exampleFix":"// before: swallowing the cause\n} catch (Exception e) {\n    throw new RuntimeException(new ClusterRetrieveException(\"Could not create the RestClusterClient.\", e));\n}\n// after: log the cause to diagnose DNS/config issues\n} catch (Exception e) {\n    LOG.error(\"RestClusterClient creation failed for cluster {}\", clusterId, e);\n    client.handleException(e);\n    throw new RuntimeException(new ClusterRetrieveException(\"Could not create the RestClusterClient.\", e));\n}","handlingStrategy":"try-catch","validationCode":"// ensure the REST service is reachable before creating the client\nInetAddress addr = InetAddress.getByName(getWebMonitorAddress(config));","typeGuard":null,"tryCatchPattern":"try {\n    RestClusterClient<String> client = new RestClusterClient<>(config, clusterId, haServices);\n} catch (Exception e) {\n    LOG.error(\"RestClusterClient failed for {}\", clusterId, e); // inspect the real cause\n}","preventionTips":["Check rest.address/rest.port config values","Verify DNS resolution of the JobManager service","Keep the cause chain intact for diagnosis","Validate kube API connectivity before deployment"],"tags":["kubernetes","flink","rest-client","cluster-retrieval"],"backgroundTag":"http-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"}