K8s環境中有個需求是希望在container啟動前把PV(Persistent Volumn)內的檔案都清空,好讓container啟動時如全新般的狀態。Google後發現busybox這個精巧的image可以達到需求
YAML內
…
..containers:
…
..initContainers:
- name : clean folder
Image:library/busybox
Command:
- /bin/sh
- “-c”
- “rm -rf /data/db/*”
VolumnMounts:
- name : my-data
mountPath : /data/db
以上開頭字母須為小寫(編輯器自動轉換大寫真不方便)