🗑

IngressClassParamsでALBの削除保護をすれば、Ingressの削除に手間取らない

に公開

IngressClassParamsで削除保護

https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/ingress_class/#ingressclassparams

spec.loadBalancerAttributesに以下のように書ける

spec:
  loadBalancerAttributes:
    - key: deletion_protection.enabled
      value: 'true'

IngressClassからIngressClassParamsを参照
IngressからIngressClassを参照
して、IngressとIngressClassParamsを結びつける


Ingressのmetadata.annotationsに書く場合

https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/annotations/#custom-attributes

alb.ingress.kubernetes.io/load-balancer-attributes: deletion_protection.enabled=true

Ingress削除の流れ

Ingressをdeleteすると、metadata.deletionTimestampがつく
finalizerを持っているため、すぐには削除されず
いったんIngressの更新があったということで、Reconcileが開始する

group_controllerのreconcile内でLoadされるとき
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/e116495cbef124874575cba9512861e83a3a8d7e/controllers/ingress/group_controller.go#L138

IngressGroupの各Ingressに対してcheckGroupMembershipTypeされる
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/ee3fc7a7f617ffbbe5ad88d85455200df91e523c/pkg/ingress/group_loader.go#L88

metadata.deletionTimestampが存在するため、GroupIDはnilと判定される
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/ee3fc7a7f617ffbbe5ad88d85455200df91e523c/pkg/ingress/group_loader.go#L173-L178

するとinactiveなメンバーだとされる
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/ee3fc7a7f617ffbbe5ad88d85455200df91e523c/pkg/ingress/group_loader.go#L168-L169

inactiveなメンバーは、グループ名の入ったfinalizerを外される
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/e116495cbef124874575cba9512861e83a3a8d7e/controllers/ingress/group_controller.go#L181

→finalizerがなく、deletion timestampが存在するため、Ingressオブジェクトは削除される

IngressClassParamsとannotationsの違い

IngressClassParamsでALBの削除保護をした場合、「Ingress削除の流れ」を阻止する要素はないため、Ingressは削除できる

annotationsに書いた場合
RemoveGroupFinalizerに入る前のbuildAndDeployModelの段階で
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/ee3fc7a7f617ffbbe5ad88d85455200df91e523c/controllers/ingress/group_controller.go#L154

エラーが返る
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/ee3fc7a7f617ffbbe5ad88d85455200df91e523c/pkg/ingress/model_builder.go#L233-L242

するとreconcile関数をそのまま抜けるため、finalizerは削除されず、Ingressも削除されないままになる
(自分でfinalizerを削除すると消える)
https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/e116495cbef124874575cba9512861e83a3a8d7e/controllers/ingress/group_controller.go#L154-L157

Discussion