<p>I have a Redis cluster of 6 nodes, running in my Kubernetes cluster as a stateful set. Since it was for testing and not yet on production, all of the Redis nodes were on the same machine. Of course, the machine failed, and all of Redis' nodes crashed immediately. 
When the machine was back alive the pods were recreated and was given different cluster ips, therefore they couldn't re-connect with each other.</p>

<p>I need to find a solution for a disaster case such as this. Let's assume all the nodes were reassigned with different ips, how can I configure the nodes to get to other ips?</p>

<p>The slaves are easy to reset with the CLUSTER RESET command, but the masters contain slots and data that shouldn't be deleted. </p>

<p>Should I manually re-write nodes.conf? I'm afraid this will make it even worse? I there a known method to deal with it?</p>

<p>Thanks!</p>

Yuval
<p>Found a solution:</p>

<p>The first step is to change the current pod ip in nodes.conf when the pod is starting. You can achieve that with this script</p>

<pre><code>#!/bin/sh
    CLUSTER_CONFIG="/data/nodes.conf"
    if [ -f ${CLUSTER_CONFIG} ]; then
      if [ -z "${POD_IP}" ]; then
        echo "Unable to determine Pod IP address!"
        exit 1
      fi
      echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
      sed -i.bak -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${CLUSTER_CONFIG}
    fi
    exec "$@"
</code></pre>

<p>You should start any pod by calling this script and passing to it the original redis-server start command.</p>

<p>Now every pod in the cluster has the correct IP of itself set.</p>

<ol>
<li>Make sure the cluster's pods are stable and don't crash. </li>
<li>Manually edit nodes.conf in one of the pods. Set the correct IPs instead of the deprecated ones. </li>
<li>Restart the pod you've edit with <code>redis-cli shutdown</code>. Kubernetes will set up a new pod for it. The new pod's IP will be set by the script I added above.</li>
</ol>
