产品动态
公告
产品发布记录
ConfigMaps 资源为工作负载的 Volume,并通过 Linux 系统的 inotify (inode notify) 机制来观察配置文件的变更来更新工作节点的 /etc/hosts 文件。
因为需要修改工作节点的 /etc/hosts 文件,所以我们通常使用 Daemonset 工作负载来部署。并且,需要在每一个需要更新 hosts 的节点上运行。为了能够更广泛的运行到集群内的节点上,我们在 DaemonSet 的 yaml 文件中默认使用了下列污点容忍:tolerations:- key: node-role.kubernetes.io/mastereffect: NoSchedule- key: node.kubernetes.io/disk-pressureeffect: NoSchedule- key: node.kubernetes.io/memory-pressureeffect: NoSchedule- key: node.kubernetes.io/network-unavailableeffect: NoSchedule- key: node.kubernetes.io/not-readyeffect: NoExecute- key: node.kubernetes.io/pid-pressureeffect: NoSchedule- key: node.kubernetes.io/unreachableeffect: NoExecute- key: node.kubernetes.io/unschedulableeffect: NoSchedule
Namespace 下(如 kube-system)新建 ConfigMaps 资源 updater-config,然后再创建 DaemonSet。ConfigMaps 资源 updater-config 即可。ConfigMaps 示例如下:apiVersion: v1kind: ConfigMapmetadata:name: updater-confignamespace: kube-systemdata:hosts.yaml: |- domain: demo.tencentcloudcr.comip: 10.0.0.2disabled: false- domain: vpc-demo.tencentcloudcr.comip: 10.0.0.2disabled: false
ConfigMaps Volume,在编辑了 updater-config 后 hosts 文件更新的时间取决于工作节点 kubelet 的 sync period(默认值为一分钟)和 ConfigMaps 的 Cache TTL (默认值为一分钟)。该问题的详细资料请参考 k8s 官方文档。文档反馈