<p>Getting this error message after <code>kubectl apply -f .</code></p>

<pre><code>error: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"include (print $.Template.BasePath \"/configmap.yaml\") . | sha256sum":interface {}(nil)}
</code></pre>

<p>I've tried putting <code>checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}</code> in different places, but I don't really understand YAML or JSON to figure out the issue.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
        - name:  demo
          image: cloudnatived/demo:hello-config-env
          ports:
            - containerPort: 8888
          env:
            - name: GREETING
              valueFrom:
                configMapKeyRef:
                  name: demo-config
                  key: greeting
      annotations:
          checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
</code></pre>

<p>I just want to be able to update my pods when the config is changed. I'm supposed to <code>helm upgrade</code> here somewhere but I'm not sure what arguments to give it.</p>

Ali
<p>You can't use the <code>{{ ... }}</code> syntax with <code>kubectl apply</code>.  That syntax generally matches the <a href="https://helm.sh" rel="noreferrer">Helm</a> package manager.  Without knowing to apply the template syntax, <code>{ ... }</code> looks like YAML map syntax, and the parser gets confused.</p>

<p><code>annotations:</code> generally belong under <code>metadata:</code>, next to <code>labels:</code>.  <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/" rel="noreferrer">Annotations</a> in the Kubernetes documentation might be useful reading.</p>

<blockquote>
  <p>I just want to be able to update my pods without restarting them.</p>
</blockquote>

<p>Kubernetes doesn't work that way, with some very limited exceptions.</p>

<p>If you're only talking about configuration data and not code, you can <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume" rel="noreferrer">Add ConfigMap data to a Volume</a>; then if the ConfigMap changes, the files the pod sees will also change.  The syntax you're stumbling over is actually a workaround to force a pod to restart when the ConfigMap data changes: it is the opposite of what you're trying for, and you should delete these two lines.</p>

<p>For routine code changes, the standard path is to build and push a new Docker image, then update your Deployment object with the new image tag.  (It must be a different image tag string than you had before, just pushing a new image with the same tag isn't enough.)  Then Kubernetes will automatically start new pods with the new image, and once those start up, shut down pods with the old image.  Under some circumstances Kubernetes can even delete and recreate pods on its own.</p>
