
Let's say something like this is being returned by the kubectl CLI.
~]$ kubectl version
error: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
Or by Terraform.
~]$ terraform apply -auto-approve
Error: Kubernetes cluster unreachable: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
The apiVersion should be listed in your kube config file.
- name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args:
- --region
- us-east-1
- eks
- get-token
- --cluster-name
- my-cluster
command: aws
env:
- name: AWS_PROFILE
value: default
Some versions of the AWS CLI should set the apiVersion to be v1alpha1 and some versions of the AWS CLI should set the apiVersion to be v1beta1.
For example, if you download and install version 2.1.1 of the AWS CLI and then use the aws eks update-kubeconfig command to create or update your kube config file, apiVersion in your kube config file should be v1alpha1.
~]$ /path/to/aws-cli-version-2.1.1 eks update-kubeconfig --name my-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config
~]$ grep apiVersion /home/john.doe/.kube/config
apiVersion: client.authentication.k8s.io/v1alpha1
On the other hand, if you download and install version 2.13.30 of the AWS CLI and then use the aws eks update-kubeconfig command to create or update your kube config file, apiVersion in your kube config file should be v1beta1.
~]$ /path/to/aws-cli-version-2.13.30 eks update-kubeconfig --name my-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config
~]$ grep apiVersion /home/john.doe/.kube/config
apiVersion: client.authentication.k8s.io/v1beta1
If you are getting this error with the kubectl CLI, you can also try downloading a different version of the kubectl CLI.
curl --location --remote-name https://storage.googleapis.com/kubernetes-release/release/v1.23.6/bin/linux/amd64/kubectl
If you have two or more different kube config files, you can try pointing to a specific kube config file.
~]$ kubectl version --kubeconfig /path/to/.kube/config
And then you might want to see if the kubectl api-versions command returns output.
~]$ kubectl api-versions | grep -i authentication
authentication.k8s.io/v1
And if the kubectl api-resources command returns output.
~]$ kubectl api-resources | grep -i authentication
NAME SHORTNAMES APIVERSION NAMESPACED KIND
tokenreviews authentication.k8s.io/v1 false TokenReview
If you are getting this error with Terraform, you can try a specific version of the hashicorp/aws and hashicorp/kubernetes and gavinbunney/kubectl providers.
~]$ cat required_providers.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.67.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.0.0"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "1.9.4"
}
}
}
Did you find this article helpful?
If so, consider buying me a coffee over at