K8s configmap Secrets 更新滾動更新pod
-
Reloader
-
patch
一、k8s使用Reloader實現更新configmap後自動重啓pod
在日常使用kubernetes過程中,需要經常使用到configMap
或Secret
時,但存在的問題:在更新完configMap
或secret
後,已經啓動的pod
無法感知到其變化,不會滾動更新pod
。給人感覺是新配置未生效。
如果業務自身支持 reload
操作,比如 nginx
,那麼我們可以使用 inotify
感知到文件更新或者直接定期 reload
(可以配合 readinessProbe
一起使用)。但是如果業務不支持熱加載配置,就需要使用到 Kubernetes
自身提供的滾動更新功能了。
由於更新 configmap
或 secret 不會觸發 Pod 的滾動更新,所以需要引入一個開源工具 Reloader
,它通過監控 Pod 引用的 configmap
或 secret
資源,如果發現變更,就會自動觸發對 Deployment configs、Deployment、Statefulset、Daemonsets 和 Rollouts 等資源的滾動更新。
二、patch
kubectl patch ds filebeat -n pub-system --patch '{"spec": {"template": {"metadata": {"annotations": {"version/config": "20221113" }}}}}'