hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.6k stars 979 forks source link

Can GKE POD Horizontal Autoscaling be available with Memory Utilization Metrics through Terraform IAC? #2544

Closed savitapal8 closed 4 months ago

savitapal8 commented 4 months ago

Terraform version, Kubernetes provider version and Kubernetes version

Terraform version:
Kubernetes Provider version:
Kubernetes version:

Terraform configuration

+ resource "kubernetes_horizontal_pod_autoscaler" "hpa" {
[2024-07-09 10:49:37]       + id = (known after apply)
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]       + metadata {
[2024-07-09 10:49:37]           + generation       = (known after apply)
[2024-07-09 10:49:37]           + labels           = {
[2024-07-09 10:49:37]               + "app"     = "query-service"
[2024-07-09 10:49:37]               + "dept"    = "Sentinels"
[2024-07-09 10:49:37]               + "name"    = "query-service"
[2024-07-09 10:49:37]               + "part-of" = "Foundry"
[2024-07-09 10:49:37]             }
[2024-07-09 10:49:37]           + name             = "query-service"
[2024-07-09 10:49:37]           + namespace        = "dev1-e2-dev1-ssrs-query"
[2024-07-09 10:49:37]           + resource_version = (known after apply)
[2024-07-09 10:49:37]           + uid              = (known after apply)
[2024-07-09 10:49:37]         }
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]       + spec {
[2024-07-09 10:49:37]           + max_replicas                      = 3
[2024-07-09 10:49:37]           + min_replicas                      = 1
[2024-07-09 10:49:37]           + target_cpu_utilization_percentage = (known after apply)
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]           + metric {
[2024-07-09 10:49:37]               + type = "Resource"
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]               + resource {
[2024-07-09 10:49:37]                   + name = "cpu"
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]                   + target {
[2024-07-09 10:49:37]                       + average_utilization = 80
[2024-07-09 10:49:37]                       + type                = "Utilization"
[2024-07-09 10:49:37]                     }
[2024-07-09 10:49:37]                 }
[2024-07-09 10:49:37]             }
[2024-07-09 10:49:37]           + metric {
[2024-07-09 10:49:37]               + type = "Resource"
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]               + resource {
[2024-07-09 10:49:37]                   + name = "memory"
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]                   + target {
[2024-07-09 10:49:37]                       + average_utilization = 80
[2024-07-09 10:49:37]                       + type                = "Utilization"
[2024-07-09 10:49:37]                     }
[2024-07-09 10:49:37]                 }
[2024-07-09 10:49:37]             }
[2024-07-09 10:49:37] 
[2024-07-09 10:49:37]           + scale_target_ref {
[2024-07-09 10:49:37]               + api_version = "apps/v1"
[2024-07-09 10:49:37]               + kind        = "Deployment"
[2024-07-09 10:49:37]               + name        = "query-service"
[2024-07-09 10:49:37]             }
[2024-07-09 10:49:37]         }
[2024-07-09 10:49:37]     }

Question

I need to make enable GKE POD Horizontal Autoscaling with Memory Utilization Metrics through terraform IAC. 
I found code with CPU Utilization, but not for Memory Utilization Metrics.

I also tried with above code but getting below error after applying terraform pipeline-------

**ERROR Message:**

[2024-07-09 10:50:07] Error: the server could not find the requested resource
[2024-07-09 10:50:07] 
[2024-07-09 10:50:07] releases, based on feedback.
[2024-07-09 10:50:07] 
[2024-07-09 10:50:07] If you have feedback on the design of this feature, please open a GitHub issue
[2024-07-09 10:50:07] to discuss it.
[2024-07-09 10:50:07] 
[2024-07-09 10:50:07] (and 7 more similar warnings elsewhere)
[2024-07-09 10:50:07] 
[2024-07-09 10:50:07]   on .terraform/modules/query_service_dev1.query_service/k8s_hpa.tf line 32, in resource "kubernetes_horizontal_pod_autoscaler" "hpa":
[2024-07-09 10:50:07]   32: resource "kubernetes_horizontal_pod_autoscaler" "hpa"
appilon commented 4 months ago

The provider is merely a passthrough for the k8s API. It's very unlikely TF works for CPU but not Memory, it should support all the metric Kubernetes supports. I'm going to close this issue/question as I don't think there's anything actionable we can provide at this time.