{"record":{"id":"578c670166a2b3ad","repo":"zhisheng17/flink-learning","slug":"load-kubernetes-config-failed","errorCode":null,"errorMessage":"Load kubernetes config failed.","messagePattern":"Load kubernetes config failed\\.","errorType":"exception","errorClass":"KubernetesClientException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/FlinkKubeClientFactory.java","lineNumber":82,"sourceCode":"\n\t\tfinal String kubeConfigFile =\n\t\t\tflinkConfig.getString(KubernetesConfigOptions.KUBE_CONFIG_FILE);\n\t\tif (kubeConfigFile != null) {\n\t\t\tLOG.debug(\"Trying to load kubernetes config from file: {}.\", kubeConfigFile);\n\t\t\ttry {\n\t\t\t\t// If kubeContext is null, the default context in the kubeConfigFile will be used.\n\t\t\t\t// Note: the third parameter kubeconfigPath is optional and is set to null. It is\n\t\t\t\t// only used to rewrite\n\t\t\t\t// relative tls asset paths inside kubeconfig when a file is passed, and in the case\n\t\t\t\t// that the kubeconfig\n\t\t\t\t// references some assets via relative paths.\n\t\t\t\tconfig =\n\t\t\t\t\tConfig.fromKubeconfig(\n\t\t\t\t\t\tkubeContext,\n\t\t\t\t\t\tFileUtils.readFileUtf8(new File(kubeConfigFile)),\n\t\t\t\t\t\tnull);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new KubernetesClientException(\"Load kubernetes config failed.\", e);\n\t\t\t}\n\t\t} else {\n\t\t\tLOG.debug(\"Trying to load default kubernetes config.\");\n\n\t\t\tconfig = Config.autoConfigure(kubeContext);\n\t\t}\n\n\t\tfinal String namespace = flinkConfig.getString(KubernetesConfigOptions.NAMESPACE);\n\t\tLOG.debug(\"Setting namespace of Kubernetes client to {}\", namespace);\n\t\tconfig.setNamespace(namespace);\n\n\t\tfinal NamespacedKubernetesClient client = new DefaultKubernetesClient(config);\n\t\tfinal int poolSize =\n\t\t\tflinkConfig.get(KubernetesConfigOptions.KUBERNETES_CLIENT_IO_EXECUTOR_POOL_SIZE);\n\t\treturn new Fabric8FlinkKubeClient(\n\t\t\tflinkConfig, client, createThreadPoolForAsyncIO(poolSize, useCase));\n\t}\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/FlinkKubeClientFactory.java#L64-L100","documentation":"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.","triggerScenarios":"kubernetes.config-file points to a file that does not exist, is unreadable (permissions), or readFileUtf8 fails while reading it during client construction.","commonSituations":"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.","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."],"exampleFix":"// before\nkubernetes.config-file: /home/user/.kube/config\n// after\nkubernetes.config-file: /home/user/.kube/config_actual_name.yaml  # file that exists and is readable","handlingStrategy":"validation","validationCode":"File kubeconfig = new File(kubernetesConfigFile);\nif (!kubeconfig.isFile() || !kubeconfig.canRead()) {\n    throw new IllegalStateException(\"kubeconfig missing or unreadable: \" + kubeconfig.getAbsolutePath());\n}","typeGuard":null,"tryCatchPattern":"try {\n    FlinkKubeClient client = FlinkKubeClientFactory.fromConfiguration(flinkConfig);\n} catch (KubernetesClientException e) {\n    LOG.error(\"Could not load kubeconfig: {}\", e.getCause() != null ? e.getCause().toString() : e.getMessage());\n    throw e;\n}","preventionTips":["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."],"tags":["kubernetes","kubeconfig","io"],"backgroundTag":"file-read-failed","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}