title: Restart kubernetes deployment after changing configMap
body: <p>I have a deployment which includes a configMap, persistentVolumeClaim, and a service. I have changed the configMap and re-applied the deployment to my cluster. I understand that this change does not automatically restart the pod in the deployment:</p>
  
  <p><a href="https://stackoverflow.com/questions/56954670/configmap-change-doesnt-reflect-automatically-on-respective-pods?noredirect=1&amp;lq=1">configmap change doesn&#39;t reflect automatically on respective pods</a></p>
  
  <p><a href="https://stackoverflow.com/questions/56979319/updated-configmap-yaml-but-its-not-being-applied-to-kubernetes-pods?noredirect=1&amp;lq=1">Updated configMap.yaml but it&#39;s not being applied to Kubernetes pods</a></p>
  
  <p>I know that I can <code>kubectl delete -f wiki.yaml &amp;&amp; kubectl apply -f wiki.yaml</code>. But that destroys the persistent volume which has data I want to survive the restart. How can I restart the pod in a way that keeps the existing volume?</p>
  
  <p>Here's what wiki.yaml looks like:</p>
  
  <pre><code>apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: dot-wiki
  spec:
    accessModes:
      - ReadWriteOnce
    volumeMode: Filesystem
    resources:
      requests:
        storage: 4Gi
  ---
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: wiki-config
  data:
    config.json: |
      {
        "farm": true,
        "security_type": "friends",
        "secure_cookie": false,
        "allowed": "*"
      }
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: wiki-deployment
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: wiki
    template:
      metadata:
        labels:
          app: wiki
      spec:
        securityContext:
          runAsUser: 1000
          runAsGroup: 1000
          fsGroup: 1000
        initContainers:
        - name: wiki-config
          image: dobbs/farm:restrict-new-wiki
          securityContext:
            runAsUser: 0
            runAsGroup: 0
            allowPrivilegeEscalation: false
          volumeMounts:
            - name: dot-wiki
              mountPath: /home/node/.wiki
          command: ["chown", "-R", "1000:1000", "/home/node/.wiki"]
        containers:
        - name: farm
          image: dobbs/farm:restrict-new-wiki
          command: [
            "wiki", "--config", "/etc/config/config.json",
            "--admin", "bad password but memorable",
            "--cookieSecret", "any-random-string-will-do-the-trick"]
          ports:
          - containerPort: 3000
          volumeMounts:
            - name: dot-wiki
              mountPath: /home/node/.wiki
            - name: config-templates
              mountPath: /etc/config
        volumes:
        - name: dot-wiki
          persistentVolumeClaim:
            claimName: dot-wiki
        - name: config-templates
          configMap:
            name: wiki-config
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: wiki-service
  spec:
    ports:
    - name: http
      targetPort: 3000
      port: 80
    selector:
      app: wiki
  </code></pre>