Fork me on GitHub

K8s configmap Secrets 更新滚动更新pod

K8s configmap Secrets 更新滚动更新pod

  • Reloader

  • patch

一、k8s使用Reloader实现更新configmap后自动重启pod

GitHub - stakater/Reloader

在日常使用kubernetes过程中,需要经常使用到configMapSecret时,但存在的问题:在更新完configMapsecret后,已经启动的pod无法感知到其变化,不会滚动更新pod。给人感觉是新配置未生效。

  如果业务自身支持 reload 操作,比如 nginx,那么我们可以使用 inotify 感知到文件更新或者直接定期 reload(可以配合 readinessProbe 一起使用)。但是如果业务不支持热加载配置,就需要使用到 Kubernetes 自身提供的滚动更新功能了。

由于更新 configmap 或 secret 不会触发 Pod 的滚动更新,所以需要引入一个开源工具 Reloader,它通过监控 Pod 引用的 configmapsecret 资源,如果发现变更,就会自动触发对 Deployment configs、Deployment、Statefulset、Daemonsets 和 Rollouts 等资源的滚动更新。

二、patch

 kubectl patch  ds filebeat  -n pub-system   --patch '{"spec": {"template": {"metadata": {"annotations": {"version/config": "20221113" }}}}}'
posted @ 2022-11-30 23:45  自由早晚乱余生  阅读(720)  评论(0编辑  收藏  举报