<p>I have an application running inside <code>kubernetes</code> which has a file mounted through <code>configmaps</code>. Now, from inside the application I want to perform some action when this file (from configmap) gets updated (lets say through <code>kubectl update configmaps xyz</code> command).</p>

<p>Lets say I have created a configmap using the following command:</p>

<pre><code>kubectl create configmap myy-config --from-file=config.json
</code></pre>

<p>and I have my Deployment created like this:</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        -
          image: "xyz"
          name: myapp
          ports:
            -
              containerPort: 5566
          volumeMounts:
            -
              mountPath: /myapp/config
              name: config
      dnsPolicy: ClusterFirstWithHostNet
      volumes:
        -
          name: config
          configMap:
            name: my-config
</code></pre>

<p>Now, if I do <code>kubectl exec -it &lt;pod&gt; sh</code> I can see the file. If I edit the configmap using <code>kubectl edit configmap my-config</code> and change the content, the application running in my pod doesn't get the file changed notification. I am using GO Lang for the application and it doesn't receive the fsnotify on the file <code>/myapp/config/config.json</code> even though I can see that after the edit, the file has changed.</p>

<p>If I run the same application in my laptop, of course, the code gets the fsnotify and my application updates it configuration. The same code from within the kubernetes with the file coming from configmap, it doesn't work. I have read other SOF questions <a href="https://stackoverflow.com/questions/37317003/restart-pods-when-configmap-updates-in-kubernetes">like this</a> and various others, but nothing specifically has solution for the problem I face.</p>

<p>I understand that the file (which comes from the configmap) is a symlink and the actual file is in a folder called <code>..data/config.json</code>. I tried to add that file also, but still not getting the fsnotify signal. Is it possible to get fsnotify signal for files which come from configmap (as well as secrets) within the application? If so, can someone please help me and show how to do it (preferably in GO lang)?</p>

<p>You might be experience a problem <a href="https://medium.com/@xcoulon/kubernetes-configmap-hot-reload-in-action-with-viper-d413128a1c9a" rel="nofollow noreferrer">like this</a>:</p>
<blockquote>
<p>When a ConfigMap changes, the real path to the config files it contains changed, but this is kinda “hidden” by 2 levels of symlinks: [..]</p>
</blockquote>
<p>So it seems you need to follow the chain of symlinks and watch that. Since your application is written in <code>go</code> you could just use <a href="https://github.com/spf13/viper" rel="nofollow noreferrer"><code>spf13/viper</code></a> since the feature <a href="https://github.com/spf13/viper/commit/e0f7631cf3ac7e7530949c7e154855076b0a4c17" rel="nofollow noreferrer">WatchConfig and Kubernetes</a> was added.</p>
<p>Alternatively you can get notified by the Kubernetes API on <a href="https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/config-map-v1/#list-list-or-watch-objects-of-kind-configmap-1" rel="nofollow noreferrer">changes of a ConfigMap</a>. This requires configuring some <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-examples" rel="nofollow noreferrer">access rules</a> upfront most probably.</p>
