3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kubernetes の finalizers について確認したメモ

Posted at

メモです。
以下を読んで試した時のメモです。

Using Finalizers to Control Deletion

また、そもそも finalizers とは、という点は以下などを拝見しました。

Kubernetes の Garbage Collection

環境

$alias |grep kubectl
k=kubectl

$k version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.5-eks-bc4871b", GitCommit:"5236faf39f1b7a7dabea8df12726f25608131aa9", GitTreeState:"clean", BuildDate:"2021-10-29T23:32:16Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

やってみた時のメモ

例えば以下のように finalizers が指定された ConfigMap を作る。

# ConfigMap 作成
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: mymap
  finalizers:
  - kubernetes
EOF

# yaml を確認
$k get configmaps mymap -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: "2022-01-28T22:33:44Z"
  finalizers:
  - kubernetes
  name: mymap
  namespace: default
  resourceVersion: "1123879"
  uid: 18dcafff-ca4a-4ebc-88a8-e11b637610f3

finalizers がある状態で削除を試みる。

$kubectl delete configmap/mymap

これは処理が完了しない。
yaml として見ると deletionGracePeriodSeconds 及び deletionTimestamp が増えているが、実際にオブジェクトもまだ存在するままとなっている。

$k get configmaps mymap
NAME    DATA   AGE
mymap   0      2m11s

$ k get configmap/mymap -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: "2022-01-28T22:33:44Z"
  deletionGracePeriodSeconds: 0
  deletionTimestamp: "2022-01-28T22:36:42Z"
  finalizers:
  - kubernetes
  name: mymap
  namespace: default
  resourceVersion: "1124503"
  uid: 18dcafff-ca4a-4ebc-88a8-e11b637610f3

ブログに記述があるが、finalizers があるために削除が完了していない。
ブログでは kubectl patch によって finalizers を削除することで削除が完了している。
同様のことを kubectl edit でやってみる。

# finalizers のキーを削除
$k edit configmap/mymap

具体的には以下のようにする。

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: "2022-01-28T22:33:44Z"
  finalizers:
  name: mymap
  namespace: default
  resourceVersion: "1123879"
  uid: 18dcafff-ca4a-4ebc-88a8-e11b637610f3
~

この後オブジェクトが削除されていることを確認。

# オブジェクトも削除される
$k get configmap/mymap -o yaml
Error from server (NotFound): configmaps "mymap" not found
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?