본문 바로가기
공부/IaC

[Terraform/k8s] gp2 Storage Class patch

by haejang 2023. 6. 5.
728x90
728x90

 

 

eks를 만들면, gp2 storage class가 자동으로 같이 생성되어 있다.

https://docs.aws.amazon.com/eks/latest/userguide/storage-classes.html

 

Storage classes - Amazon EKS

Storage classes Amazon EKS clusters that were created prior to Kubernetes version 1.11 weren't created with any storage classes. You must define storage classes for your cluster to use and you should define a default storage class for your persistent volum

docs.aws.amazon.com

 

얘는 default class설정이 되어있다.

따라서 gp3만을 default class로 사용하려면 이미 존재하는 gp2 sc에 대해 storageclass.kubernetes.io/is-default-class: "false" 로 annotation을 수정해주어야 한다.

 

cli 명령으로는 아래와 같다.

kubectl patch sc gp2 -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'

 

🧐 Terraform에서는?

terraform에는 kubernetes patch api가 아직 제공되지 않는다.

-> annotation을 강제로 덮어쓰는 방식으로 적용이 가능하다.

 

################################################################################
# 자동으로 생성되는 gp2 storage class : default class에서 제거
# kubernetes patch api 가 현재 terraform으로 제공되고 있지 않기 때문에, annotation을 엎어치는 방식으로 사용
################################################################################
resource "kubernetes_annotations" "sc_gp2" {
  api_version = "storage.k8s.io/v1"
  kind        = "StorageClass"
  force       = "true"

  metadata {
    name = "gp2"
  }
  annotations = {
    "storageclass.kubernetes.io/is-default-class" = "false"
  }
}

################################################################################
# Create GP3 Storage Class - Default Class 적용
################################################################################
resource "kubernetes_storage_class_v1" "gp3" {
  metadata {
    name   = "gp3"
    annotations = {
      "storageclass.kubernetes.io/is-default-class" = "true"
    }
  }
  storage_provisioner = "ebs.csi.aws.com"
  volume_binding_mode = "WaitForFirstConsumer"
  parameters = {
    "type"                      = "gp3"
    "csi.storage.k8s.io/fstype" = "ext4"
  }
  allow_volume_expansion = true
}

 

참조

https://github.com/hashicorp/terraform-provider-kubernetes/issues/723#issuecomment-1141833527

 

Feature Request: equivalent of `kubectl patch` · Issue #723 · hashicorp/terraform-provider-kubernetes

Terraform Version Terraform v0.12.18 Affected Resource(s) n/a (request for new resource) In AWS EKS, clusters come "pre-configured" with several things running in the kube-system namespace. We need...

github.com

 

 

 

 

728x90
728x90

댓글