Terraform-provider-kubernetes: kubernetes_horizontal_pod_autoscaler for a deployment

Created on 24 Jul 2019  ·  5Comments  ·  Source: hashicorp/terraform-provider-kubernetes

Terraform Version

0.12.3

Affected Resource(s)

  • kubernetes_horizontal_pod_autoscaler

Terraform Configuration Files

resource "kubernetes_horizontal_pod_autoscaler" "source-file-processing" {
  metadata {
    name = "${terraform.workspace}-drawboard-services-source-file-processing"
  }
  spec {
    max_replicas = 3
    min_replicas = 2
    target_cpu_utilization_percentage = 50
    scale_target_ref {
      kind = "Deployment"
      name = "${terraform.workspace}-drawboard-services-source-file-processing"
    }
  }
}

Expected Behavior

(from kubectl.exe describe hpa)

 AbleToScale    True    SucceededRescale  the HPA controller was able to update the target scale to 2

Actual Behavior

I get an autoscaler that doesn't work
(from kubectl.exe describe hpa)

 AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: no matches for kind "Deployment" in group ""

Steps to Reproduce

Try and setup an autoscaler for a resource of type Deployment. Do not specify api_version

Important Factoids

Kubernetes is in my case running on azure.

When i set up the same using the cli I got something that worked. So I exported the yaml of two the resources created a different way and found the terraform one had in the scale target no apiVersion defined. The resource created by the command line had apiVersion: extensions/v1beta1. So i explicitly set that in my terraform config and i got a working resource.

I don't know if this is a bug per-se, my high degree of ignorance or perhaps this is a quirk of Azure's kubernetes offering but couldn't the provider have set the (optional) api_version field for me? Or maybe a hint in the docs?

Most helpful comment

If you're coming across this in google now, you might also want to try apps/v1 as the api_version depending on your Kubernetes version.

All 5 comments

In scale_target_ref object add api_version = "extensions/v1beta1"

scale_target_ref {
      api_version = "extensions/v1beta1"
      kind = "deployment"
      name = "${terraform.workspace}-drawboard-services-source-file-processing"
    }

Ensure in your deployment you have resources block on container https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#resources-1

EDIT: take care of @lucaskjaero comment

+1

If you're coming across this in google now, you might also want to try apps/v1 as the api_version depending on your Kubernetes version.

Closing since the question appears to have been answered here.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings