I am trying to deploy our created docker image using terrafrom on local kubernetes (k3s). Also creating a service using nginx_ingress. While doing terraform apply getting error. Whatever information I have searched on net it looks like versioning issue but my kuberenetes version is up to date. Terrafrom version is also fine. Please help me to resolve this issue.
Error details are as below -
$ terraform apply --auto-approve
kubernetes_deployment.eve-statedb-deploy: Creating...
kubernetes_horizontal_pod_autoscaler.eve-statedb-hpa: Creating...
kubernetes_secret.eve-statedb-config: Creating...
kubernetes_secret.ghcr-cred: Creating...
Error: the server could not find the requested resource (post secrets)
Error: Failed to create deployment: the server could not find the requested resource (post deployments.apps)
Error: the server could not find the requested resource (post secrets)
Error: the server could not find the requested resource (post horizontalpodautoscalers.autoscaling)
Cluster information:
Kubernetes(using k3s for k8s set up) and terraform version:
$ sudo kubectl version --short
Client Version: v1.20.0+k3s2
Server Version: v1.20.0+k3s2
$ terraform --version
Terraform v0.13.6
+ provider registry.terraform.io/hashicorp/kubernetes v2.0.1
One reason this type of error happens is if the API group of the Kubernetes objects is that is not recognizable in your cluster. For instance, if your Deployment YAML is using extensions/v1beta1 and if the cluster does not recognize Deployment to be part of extensions API group then this issue will happen.
Run âkubectl api-resourcesâ to find out what API groups exist for various resources in your cluster. Then update your YAML manifests to use those api groups (e.g.: use apps/v1 for Deployment instead of extensions/v1beta1, etc.)
Thanks for the swift reply. In my deployment yaml, already included right api version âapiVersion: apps/v1â. I am new to terraform but as per my knowledge terraform will not use the existing deployment yaml. We need to configure it in â.tfâ file like below
I donât know what api version is Terraform generating for the resources. I hear that there is a âdry runâ option for Terraform. Try that to see if it gives a clue.
If not, I would suggest checking on Terraform forums as this issue is most likely because the apiVersion of the k8s objects that Terraform is generating is not present on your cluster.
Just to verify that is the case try these two things:
try doing a deployment directly with extensions/v1beta1 as apiVersion.
try using a different cluster in which extensions/v1beta is present (older k8s version) and use that with your terraform template above.
Could you please check if kubernetes provider is given, mentioned Like below:
provider âkubernetesâ {
host = hostsinfo
client_certificate = base64decode(hostcertificate)
client_key = base64decode(hostskey)
cluster_ca_certificate = base64decode(hostclientcertificate)
}
you will get all info from ~/.kube/config
I had similar problem and it took me a bit of time to realize what was missing. I had the
provider âkubernetesâ {
host = hostsinfo
client_certificate = base64decode(hostcertificate)
client_key = base64decode(hostskey)
cluster_ca_certificate = base64decode(hostclientcertificate)
}
but it was in a separate submodule. In my case I had to add the provider in the submodule causing me the original problem and all started to work fine.