title: Moving Pod to another node automatically
body: <p>Is it possible for a pod/deployment/statefulset to be moved to another node or be recreated on another node automatically if the first node fails? The pod in question is set to 1 replica. So is it possible to configure some sort of failover for kubernetes pods? I've tried out pod affinity settings but nothing is moved automatically it has been around 10 minutes.</p>
  <p>the yaml for the said pod is like below:</p>
  <pre><code>kind: PersistentVolumeClaim
  apiVersion: v1
  metadata:
    name: ceph-rbd-sc-pvc
  spec:
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 2Gi
    storageClassName: ceph-rbd-sc
  ---
  apiVersion: v1
  kind: Pod
  metadata:
    name: ceph-rbd-pod-pvc-sc
    labels:
      app: ceph-rbd-pod-pvc-sc
  spec:
    containers:
    - name:  ceph-rbd-pod-pvc-sc
      image: busybox
      command: [&quot;sleep&quot;, &quot;infinity&quot;]
      volumeMounts:
      - mountPath: /mnt/ceph_rbd
        name: volume
    nodeSelector:
      etiket: worker
    volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: ceph-rbd-sc-pvc
    affinity:
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              name: ceph-rbd-pod-pvc-sc
          topologyKey: &quot;kubernetes.io/hostname&quot;
  </code></pre>
  <p>Edit:</p>
  <p>I managed to get it to work. But now i have another problem, the newly created pod in the other node is stuck in &quot;container creating&quot; and the old pod is stuck in &quot;terminating&quot;. I also get <code>Multi-Attach error for volume</code> stating that the pv is still in use by the old pod. The situation is the same for any deployment/statefulset with a pv attached, the problem is resolved only when the failed node comes back online. Is there a solution for this?</p>