zhisheng17/flink-learning · error · KubernetesException

Failed to create ConfigMap {}

Error message

Failed to create ConfigMap {}

What it means

createConfigMap() runs the fabric8 ConfigMap create asynchronously and maps any throwable into this CompletionException(KubernetesException) with the ConfigMap name. The Kubernetes API rejected or failed the create call.

Source

Thrown at flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java:263

	public KubernetesLeaderElector createLeaderElector(
			KubernetesLeaderElectionConfiguration leaderElectionConfiguration,
			KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) {
		return new KubernetesLeaderElector(
			(NamespacedKubernetesClient) this.internalClient,
			namespace,
			leaderElectionConfiguration,
			leaderCallbackHandler);
	}

	@Override
	public CompletableFuture<Void> createConfigMap(KubernetesConfigMap configMap) {
		final String configMapName = configMap.getName();
		return CompletableFuture.runAsync(
			() -> this.internalClient.configMaps().inNamespace(namespace).create(configMap.getInternalResource()),
			kubeClientExecutorService)
			.exceptionally(
				throwable -> {
					throw new CompletionException(
						new KubernetesException("Failed to create ConfigMap " + configMapName, throwable));
				});
	}

	@Override
	public Optional<KubernetesConfigMap> getConfigMap(String name) {
		final ConfigMap configMap = this.internalClient.configMaps().inNamespace(namespace).withName(name).get();
		return configMap == null ? Optional.empty() : Optional.of(new KubernetesConfigMap(configMap));
	}

	@Override
	public CompletableFuture<Boolean> checkAndUpdateConfigMap(
			String configMapName,
			Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> function) {
		return FutureUtils.retry(
			() -> CompletableFuture.supplyAsync(
				() -> getConfigMap(configMapName)
					.map(

View on GitHub (pinned to d731cee761)

Solutions

  1. Check if the ConfigMap already exists (getConfigMap(name)) and reuse/delete it before creating.
  2. Check RBAC: the Flink service account needs create on configmaps in the namespace.
  3. Inspect the wrapped cause for 403/409/timeout and address accordingly.
  4. If etcd/quota limits hit, free resources or raise namespace quotas.

Example fix

// before: fails on re-submission with leftover configmap
client.createConfigMap(configMap).get();
// after: delete stale configmap first
client.getConfigMap(configMap.getName())
    .ifPresent(cm -> client.deleteConfigMap(configMap.getName()).join());
client.createConfigMap(configMap).get();
Defensive patterns

Strategy: try-catch

Validate before calling

// create only if absent
if (kubeClient.getConfigMap(name).isPresent()) {
    return; // or delete first, then create
}

Try / catch

try {
    client.createConfigMap(cm).get();
} catch (CompletionException e) {
    Throwable c = e.getCause();
    if (c instanceof KubernetesException && c.getMessage().contains("AlreadyExists")) {
        // idempotent: configmap already provisioned
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: createConfigMap called with a ConfigMap that already exists in the namespace (409 AlreadyExists), or the API server is unreachable, times out, or RBAC denies create on configmaps.

Common situations: Re-submitting a job/application after a previous run left the HA ConfigMap behind; limited service-account RBAC in restricted namespaces; API server outages or etcd quota exceeded ('resourceQuota exceeded' errors).

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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