クブ管理者とリソースをクリーンアップ
3366 ワード
アバウト
設定済みのTTL (生存する時間)後にKubernetesリソースをクリーンアップする
実装
アプリケーションは、エスカレーションされた権限を持つ展開として展開されます.APIサーバにAPIリクエストを聞き、内部のスケジュールキューを持っていて、規則マッチでリソースを削除します.
参考資料
https://codeberg.org/hjacobs/kube-janitor.git
インストール
# pick files from https://codeberg.org/hjacobs/kube-janitor/src/branch/main/deploy/
# update rules.yaml as necessary
> cat rules.yaml
rules:
# remove deployments and statefulsets with a "demo" label set after 3 days
- id: cleanup-demo-objects
resources:
- deployments
- statefulsets
jmespath: "(spec.template.metadata.labels.demo)"
ttl: 3d
# remove all deployments and jobs named "pr-*" after 6 hours
- id: cleanup-pr-deployments
resources:
- deployments
- jobs
jmespath: "starts_with(metadata.name, 'pr-')"
ttl: 6h
# delete all resources within the "temp-*" namespace after 3 days
- id: cleanup-temp-namespaces
resources:
- namespaces
jmespath: "starts_with(metadata.name, 'temp-')"
ttl: 3d
# delete all PVCs which are not mounted and not referenced by StatefulSets after 4 days
- id: remove-unused-pvcs
resources:
- persistentvolumeclaims
jmespath: "_context.pvc_is_not_mounted && _context.pvc_is_not_referenced"
ttl: 4d
> kubectl apply -k .
構成
このツールを使用する3つの方法があります
janitor/ttl
注釈.CI/CDシナリオに便利です> kubectl annotate deploy test-app-dep janitor/ttl=24h
janitor/expires
注釈.ジョブの問題解決に便利> kubectl annotate deploy nginx janitor/expires=2022-03-31
> kubectl edit configmap kube-janitor
). これは、政策執行のために適用可能なサーバー側の自動化ですrules.yaml
例えば詳しい情報
Reference
この問題について(クブ管理者とリソースをクリーンアップ), 我々は、より多くの情報をここで見つけました https://dev.to/ashokan/clean-up-resources-with-kube-janitor-4ecテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol