zhisheng17/flink-learning · error · KubernetesClientException
Load kubernetes config failed.
Error message
Load kubernetes config failed.
What it means
FlinkKubeClientFactory.fromConfiguration wraps IOException thrown while reading the kubeconfig file (Config.fromKubeconfig -> FileUtils.readFileUtf8) in this KubernetesClientException. It means the library could not read or parse the kubeconfig file supplied via kubernetes.config-file, so no Kubernetes client can be created.
Source
Thrown at flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/FlinkKubeClientFactory.java:82
final String kubeConfigFile =
flinkConfig.getString(KubernetesConfigOptions.KUBE_CONFIG_FILE);
if (kubeConfigFile != null) {
LOG.debug("Trying to load kubernetes config from file: {}.", kubeConfigFile);
try {
// If kubeContext is null, the default context in the kubeConfigFile will be used.
// Note: the third parameter kubeconfigPath is optional and is set to null. It is
// only used to rewrite
// relative tls asset paths inside kubeconfig when a file is passed, and in the case
// that the kubeconfig
// references some assets via relative paths.
config =
Config.fromKubeconfig(
kubeContext,
FileUtils.readFileUtf8(new File(kubeConfigFile)),
null);
} catch (IOException e) {
throw new KubernetesClientException("Load kubernetes config failed.", e);
}
} else {
LOG.debug("Trying to load default kubernetes config.");
config = Config.autoConfigure(kubeContext);
}
final String namespace = flinkConfig.getString(KubernetesConfigOptions.NAMESPACE);
LOG.debug("Setting namespace of Kubernetes client to {}", namespace);
config.setNamespace(namespace);
final NamespacedKubernetesClient client = new DefaultKubernetesClient(config);
final int poolSize =
flinkConfig.get(KubernetesConfigOptions.KUBERNETES_CLIENT_IO_EXECUTOR_POOL_SIZE);
return new Fabric8FlinkKubeClient(
flinkConfig, client, createThreadPoolForAsyncIO(poolSize, useCase));
}
View on GitHub (pinned to d731cee761)
Solutions
- Verify kubernetes.config-file points to an existing, readable kubeconfig file (ls -l / cat it).
- Mount the kubeconfig into the pod/container and update the config path.
- Remove kubernetes.config-file to fall back to default config discovery (KUBECONFIG env var / ~/.kube/config) if that is intended.
- If you meant in-cluster access, remove the config-file option so the client uses the service account.
Example fix
// before kubernetes.config-file: /home/user/.kube/config // after kubernetes.config-file: /home/user/.kube/config_actual_name.yaml # file that exists and is readable
Defensive patterns
Strategy: validation
Validate before calling
File kubeconfig = new File(kubernetesConfigFile);
if (!kubeconfig.isFile() || !kubeconfig.canRead()) {
throw new IllegalStateException("kubeconfig missing or unreadable: " + kubeconfig.getAbsolutePath());
} Try / catch
try {
FlinkKubeClient client = FlinkKubeClientFactory.fromConfiguration(flinkConfig);
} catch (KubernetesClientException e) {
LOG.error("Could not load kubeconfig: {}", e.getCause() != null ? e.getCause().toString() : e.getMessage());
throw e;
} Prevention
- Always verify the kubeconfig path exists and is readable before launching.
- Mount kubeconfig into containers explicitly and set kubernetes.config-file accordingly.
- Rely on KUBECONFIG env var or in-cluster service accounts when appropriate instead of absolute paths.
When it happens
Trigger: kubernetes.config-file points to a file that does not exist, is unreadable (permissions), or readFileUtf8 fails while reading it during client construction.
Common situations: Wrong path in kubernetes.config-file, running the client in a container without the kubeconfig mounted, HOME not set so the default ~/.kube/config is misresolved, or restrictive file permissions.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Failed to clear job state in ConfigMap {} for job {}
- Could not get the rest endpoint of ${clusterId}
- Could not create the RestClusterClient.
- The Flink cluster ${clusterId} already exists.
- Couldn't deploy Kubernetes Application Cluster. Expected dep
AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06).
Data as JSON: /api/errors/578c670166a2b3ad.
Report an issue: GitHub.