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

  1. Verify kubernetes.config-file points to an existing, readable kubeconfig file (ls -l / cat it).
  2. Mount the kubeconfig into the pod/container and update the config path.
  3. Remove kubernetes.config-file to fall back to default config discovery (KUBECONFIG env var / ~/.kube/config) if that is intended.
  4. 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

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


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