avatarHarsh Manvar

Summary

Kubernetes allows for automatic updates of ConfigMaps within a Pod without requiring a restart by mounting the ConfigMap as a volume, although this method has limitations with subpath usage.

Abstract

The website content explains that Kubernetes can update a ConfigMap inside a Pod automatically when the ConfigMap is mounted as a volume. This process eliminates the need to manually restart the Pod to apply updates. However, this auto-update feature does not work if the subpath option is used within the volume mount. The kubelet periodically checks for updates to the ConfigMap and refreshes the mounted volume accordingly, but the updates are not real-time and may take some time to propagate. It is also noted that ConfigMaps injected as environment variables do not support automatic updates and necessitate a Pod restart for changes to take effect. The article provides a YAML example demonstrating how to set up a ConfigMap and a Deployment that mounts the ConfigMap as a volume to enable automatic updates. Additionally, the article encourages readers to engage with the FAUN community through various platforms and invites support for the author by clicking the clap button.

Opinions

  • The author suggests that mounting a ConfigMap as a volume is a practical approach to updating configurations without restarting Pods.
  • The article implies that the auto-update feature for ConfigMaps in Kubernetes is efficient but acknowledges its limitations, such as the lack of support for subpath.
  • The author emphasizes the importance of community engagement by providing links to join the FAUN community across different social media and communication platforms.
  • The author seeks validation and support from readers by prompting them to show appreciation for the content through the clap button.

Update configmap without restarting POD

Updating the config map in Kubernetes POD requires the restart of POD. A possible approach to auto-update configmap inside pod without restart is mounting it’s content as volume.

Kubernetes auto-updates the config map into POD if mounted as a volume, however, it has a limitation like it won’t work if subpath used.

The kubelet checks whether the mounted ConfigMap is fresh on every periodic sync. Auto-update is not real-time, it takes time but it updates the config map without restart.

ConfigMaps injected as environment variables are not updated automatically and require a pod restart.

Official document link : https://kubernetes.io/docs/concepts/configuration/configmap/#mounted-configmaps-are-updated-automatically

Pre-requisites

K8s cluster running on Minikube, Docker desktop, GKE, EKS, OKE anywhere

Deploy the YAML

kubectl apply -f .yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  hello: world
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      app: test
  replicas: 1
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: configmaptestapp
        image: <Image>
        volumeMounts:
        - mountPath: /config
          name: data-volume
        ports:
        - containerPort: 80
      volumes:
        - name: data-volume
          configMap:
            name: test-config

So we can use this option to auto-update the volume with configmap.

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

Kubernetes
Configmap
Reloader
Restart
Recommended from ReadMedium