<p>I am new to k8's and trying to update storageClassName in a StatefulSet.(from default to default-t1 only change in the yaml)</p>

<p>I tried running <code>kubectl apply -f test.yaml</code></p>

<p>The only difference between 1st and 2nd Yaml(one using to apply update) is storageClassName: default-t1 instead of default</p>

<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  podManagementPolicy: "Parallel"
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: default
      resources:
        requests:
          storage: 1Gi
</code></pre>

<p>Every-time I try to update it I get <code>The StatefulSet "web" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden</code></p>

<p>What am I missing or what steps should I take to do this?</p>

<p>There's no easy way as far as I know but it's possible.</p>
<ol>
<li>Save your current StatefulSet configuration to yaml file:</li>
</ol>
<pre><code>kubectl get statefulset some-statefulset -o yaml &gt; statefulset.yaml
</code></pre>
<ol start="2">
<li>Change <code>storageClassName</code> in <code>volumeClaimTemplate</code> section of StatefulSet configuration saved in yaml file</li>
<li>Delete StatefulSet without removing pods using:</li>
</ol>
<pre><code>kubectl delete statefulset some-statefulset --cascade=orphan
</code></pre>
<ol start="4">
<li>Recreate StatefulSet with changed StorageClass:</li>
</ol>
<pre><code>kubectl apply -f statefulset.yaml
</code></pre>
<ol start="5">
<li>For each Pod in StatefulSet, first delete its PVC (it will get stuck in terminating state until you delete the pod) and then delete the Pod itself</li>
</ol>
<p>After deleting each Pod, StatefulSet will recreate a Pod (and since there is no PVC) also a new PVC for that Pod using changed StorageClass defined in StatefulSet.</p>
