Problem:
Kubernetes cluster unreachable: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
Cause:
When using the Kubernetes provider version 1.24 or higher and specifying the API version as v1alpha1, you’ll encounter the invalid API version error.
Here’s the relevant Terraform configuration snippet:
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 1.24.0"
}
}
}
provider "kubernetes" {
host = "cluster_endpoint"
cluster_ca_certificate = base64decode("eks_cluster_certificate_authority")
token = "aws_eks_cluster_auth"
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", module.eks_cluster.eks_cluster_name]
command = "aws"
}
}
Solutions:
-
It appears that
v1alpha1
is deprecated in Kubernetesv1.14
and higher, then completely removed inv.1.24
and higher. -
Upgrade your api_version from
client.authentication.k8s.io/v1alpha1
to client.authentication.k8s.io/v1beta1 orclient.authentication.k8s.io/v1
Additional Information