Reputation: 89
error: Couldn't get available api versions from server: couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
Upvotes: 7
Views: 12197
Reputation: 143
Ok, adding an answer for those who are using Terraform and didn't see a solution with upgrading awscli and such. I had to update the command in one of my Terraform providers to include a --output json on the aws eks get-config command:
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = [
"eks",
"get-token",
"--output",
"json",
"--cluster-name",
data.aws_eks_cluster.cluster.name
]
}
}
Note this command is getting a token from the aws cli, but if you your output format is 'text' or not set for some reason, you can get this error because the provider is expecting JSON and getting a text string. Adding the "--output", "json" fixed it in my case.
Upvotes: 0
Reputation: 1749
AWS cli version:
aws-cli/2.11.0 Python/3.11.2 Darwin/22.2.0 source/arm64 prompt/off
Broke my setup and caused the above error
Kubectl version:
GitVersion:"v1.25.4"
Gives this error:
error: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
Using aws-cli:
aws-cli/2.4.18 Python/3.8.8 Darwin/22.2.0 exe/x86_64 prompt/off
Kubectl version:
GitVersion:"v1.22.5"
Fixed the issues for me.
Upvotes: 0
Reputation: 4461
I had to set output format to json
.
>kubectl get nodes
Unable to connect to the server: getting credentials: decoding stdout: couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
>aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [eu-north-1]:
Default output format [text]: json
>kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-192-168-20-202.eu-north-1.compute.internal Ready <none> 370d v1.21.5-eks-9017834
Upvotes: 8
Reputation: 8411
This error can happen in case you have no ~/.kube/config
in place.
Generating proper config and putting it in its place will resolve the problem.
Please refer to the same topic: Kubectl on host returns error: couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:"apiVersion,omitempty""; Kind string "json:"kind,omitempty"" #9114
Upvotes: 2
Reputation: 541
I spent some time this morning troubleshooting this exact error and it looks like this error is thrown when kubeconfig file is not a valid yaml file.
In my particular case the problems with the file were:
Config file was auto-generated and fixing both issues allowed kubectl to use it
Upvotes: 0