If you are writing an app which access database, you will need to provide DB access info (IP address, port, credentials). What if you changed DB access info changed. Would you like to restart your app? Won't it result in bad user experience(traffic will disrupt)? Now you should have felt that restarting app is not the best approach.
Are you finding difficult to reconfigure your app when admin wants to change its setting in nice way. This document helps in this regard
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable.
While environment variables are great for small bits of information, sometimes you might have a lot of data that needs to be passed to your app. A common solution is to group this data into a file, and have your app read from this file. Kubernetes let’s you mount it via ConfigMaps.
You can also map multiple files to a single ConfigMap or Secret, and mount them all at once as a directory!
Configmap allows you to reconfigure your app without any downtime.
Steps
Create a config map and mention settings for your app.
In your app, listen for configmap update. In this way, your app will get notification whenever config changes
If your app is running as POD, then create RBAC rule. With this, kubernetes will authorise your app to get update.
Create a listener. It is typical widely used http based listener for any kubernetes event
Below example is authorisation for any update event
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: configmap-updater
rules:
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["my-configmap"]
verbs: ["update", "get"]
https://kubernetes.io/docs/reference/access-authn-authz/rbac/
https://medium.com/google-cloud/kubernetes-configmaps-and-secrets-68d061f7ab5b