zhisheng17/flink-learning · error · RuntimeException
Could not create the RestClusterClient.
Error message
Could not create the RestClusterClient.
What it means
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.
Source
Thrown at flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java:112
if (restEndpoint.isPresent()) {
configuration.setString(RestOptions.ADDRESS, restEndpoint.get().getAddress());
configuration.setInteger(RestOptions.PORT, restEndpoint.get().getPort());
} else {
throw new RuntimeException(
new ClusterRetrieveException(
"Could not get the rest endpoint of " + clusterId));
}
try {
// Flink client will always use Kubernetes service to contact with jobmanager. So we have a pre-configured web
// monitor address. Using StandaloneClientHAServices to create RestClusterClient is reasonable.
return new RestClusterClient<>(
configuration,
clusterId,
new StandaloneClientHAServices(getWebMonitorAddress(configuration)));
} catch (Exception e) {
client.handleException(e);
throw new RuntimeException(new ClusterRetrieveException("Could not create the RestClusterClient.", e));
}
};
}
private String getWebMonitorAddress(Configuration configuration) throws Exception {
HighAvailabilityServicesUtils.AddressResolution resolution =
HighAvailabilityServicesUtils.AddressResolution.TRY_ADDRESS_RESOLUTION;
if (configuration.get(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE)
== KubernetesConfigOptions.ServiceExposedType.ClusterIP) {
resolution = HighAvailabilityServicesUtils.AddressResolution.NO_ADDRESS_RESOLUTION;
LOG.warn(
"Please note that Flink client operations(e.g. cancel, list, stop,"
+ " savepoint, etc.) won't work from outside the Kubernetes cluster"
+ " since '{}' has been set to {}.",
KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE.key(),
KubernetesConfigOptions.ServiceExposedType.ClusterIP);
}
return HighAvailabilityServicesUtils.getWebMonitorAddress(configuration, resolution);View on GitHub (pinned to d731cee761)
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.
Example fix
// before: swallowing the cause
} catch (Exception e) {
throw new RuntimeException(new ClusterRetrieveException("Could not create the RestClusterClient.", e));
}
// after: log the cause to diagnose DNS/config issues
} catch (Exception e) {
LOG.error("RestClusterClient creation failed for cluster {}", clusterId, e);
client.handleException(e);
throw new RuntimeException(new ClusterRetrieveException("Could not create the RestClusterClient.", e));
} Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the REST service is reachable before creating the client InetAddress addr = InetAddress.getByName(getWebMonitorAddress(config));
Try / catch
try {
RestClusterClient<String> client = new RestClusterClient<>(config, clusterId, haServices);
} catch (Exception e) {
LOG.error("RestClusterClient failed for {}", clusterId, e); // inspect the real cause
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Could not get the rest endpoint of ${clusterId}
- The Flink cluster ${clusterId} already exists.
- Couldn't deploy Kubernetes Application Cluster. Expected dep
- Per-Job Mode not supported by Active Kubernetes deployments.
- Could not create Kubernetes cluster "${clusterId}".
AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06).
Data as JSON: /api/errors/81d4fb40d91b280c.
Report an issue: GitHub.