<p><strong>Problem summary:</strong>  </p>

<p>I am following the <a href="https://kubernetes.io/docs/tutorials/stateful-application/cassandra/" rel="nofollow noreferrer">Kubernetes guide to set up a sample Cassandra cluster</a>. The cluster is up and running, and I would like to add a second volume to each node in order to try enable backups for Cassandra that would be stored on a separate volume.</p>

<p><strong>My attempt to a solution:</strong></p>

<p>I tried editing my <a href="https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/cassandra/cassandra-statefulset.yaml" rel="nofollow noreferrer">cassandra-statefulset.yaml</a> file by adding a new <code>volumeMounts</code> and <code>volumeClaimTemplates</code> entry, and reapplying it, but got the following error message:</p>

<pre><code>$ kubectl apply -f cassandra-statefulset.yaml 
storageclass.storage.k8s.io/fast unchanged
The StatefulSet "cassandra" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden
</code></pre>

<p>I then tried to enable rolling updates and patch my configuration following the documentation here:
<a href="https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/</a></p>

<pre><code>$ kubectl patch statefulset cassandra -p '{"spec":{"updateStrategy":{"type":"RollingUpdate"}}}'
statefulset.apps/cassandra patched (no change)
</code></pre>

<p>My <code>cassandra-backup-patch.yaml</code>:</p>

<pre><code>spec:
  template:
    spec:
      containers:
        volumeMounts:
        - name: cassandra-backup
          mountPath: /cassandra_backup
  volumeClaimTemplates:
  - metadata:
      name: cassandra-backup
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: fast
      resources:
        requests:
          storage: 1Gi

</code></pre>

<p>However this resulted in the following error:</p>

<pre><code>$ kubectl patch statefulset cassandra --patch "$(cat cassandra-backup-patch.yaml)"
The request is invalid: patch: Invalid value: "map[spec:map[template:map[spec:map[containers:map[volumeMounts:[map[mountPath:/cassandra_backup name:cassandra-backup]]]]] volumeClaimTemplates:[map[metadata:map[name:cassandra-backup] spec:map[accessModes:[ReadWriteOnce] resources:map[requests:map[storage:1Gi]] storageClassName:fast]]]]]": cannot restore slice from map
</code></pre>

<p>Could anyone please point me to the correct way of adding an additional volume for each node or explain why the patch does not work? This is my first time using Kubernetes so my approach may be completely wrong. Any comment or help is very welcome, thanks in advance.</p>

cline
<p>The answer is in your first log:</p>
<pre><code>The StatefulSet &quot;cassandra&quot; is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy'
</code></pre>
<p>You can't change some fields in a <code>statefulset</code> after creation. You will likely need to delete and recreate the <code>statefulset</code> to add a new <code>volumeClaimTemplate</code>.</p>
<p>edit:
It can many times be useful to leave your pods running even when you delete the <code>statefulset</code>. To accomplish this use the <code>--cascade=false</code> flag on the delete operation.</p>
<pre><code>kubectl delete statefulset &lt;name&gt; --cascade=false
</code></pre>
<p>Then your workload will stay running while you recreate your statefulset with the updated VPC.</p>
