kubernetes - configmap 更改不会自动反映在相应的 pod 上
问题描述
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: consoleservice1
spec:
selector:
matchLabels:
app: consoleservice1
replicas: 3 # tells deployment to run 3 pods matching the template
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template: # create pods using pod definition in this template
metadata:
labels:
app: consoleservice1
spec:
containers:
- name: consoleservice
image: chintamani/insightvu:ms-console1
readinessProbe:
httpGet:
path: /
port: 8385
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
ports:
- containerPort: 8384
imagePullPolicy: Always
volumeMounts:
- mountPath: /deploy/config
name: config
volumes:
- name: config
configMap:
name: console-config
为了创建 configmap,我使用了这个命令:
kubectl create configmap console-config --from-file=deploy/config
在 configmap 中更改时,它不会自动反映,每次我必须重新启动 pod。我怎样才能自动完成?
解决方案
Pod 和 configmap 在 Kubernetes 中是完全独立的,如果 configmap 发生更改,Pod 不会自动重启。
实现这一目标的选择很少。
使用 wave,它是一个 Kubernetes 控制器,如果 configmap https://github.com/pusher/wave有任何变化,它会查找特定的注释并更新部署
使用https://github.com/stakater/Reloader,reloader 可以观察 configmap 的变化并且可以更新 pod 来选择新的配置。
kind: Deployment metadata: annotations: reloader.stakater.com/auto: "true" spec: template: metadata:
您可以在部署和 CI/CD 中添加自定义 configHash 注释,或者在部署应用程序时使用
yq
configmap 的哈希替换该值,以便在 configmap 发生任何更改的情况下。Kubernetes 将检测部署注解的变化,并使用新配置重新加载 pod。
yq w --inplace deployment.yaml spec.template.metadata.annotations.configHash $(kubectl get cm/configmap -oyaml | sha256sum)
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: application
spec:
selector:
matchLabels:
app: consoleservice1
replicas: 3
template:
metadata:
labels:
app: consoleservice1
annotations:
configHash: ""
参考:这里
推荐阅读
- reactjs - react中如何使用react-router链接组件
- c# - 没有 ParameterInjection 或 Constructor Injection 的 GetRequiredService
- rx-java - 使用 retryWhen 时没有成功
- android - 通过意图(或任何远程方法)禁用和启用谷歌播放保护扫描
- r - 在 R 中优化 + if
- npm - 在 ember 项目中将 bower 移动到 npm 时出错
- angular - 所需的 ng-packgr 入口点不存在
- powershell - 逐行阅读 Invoke-WebRequest
- c++ - 该库的用户是否使用静态库的 cpp 中的编译指示?
- batch-file - 将文件或文件夹放在同一个蝙蝠上时备份它