<p>I have the below Kubernetes storage class</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Name:            encrypted-gp2
IsDefaultClass:  No
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"encrypted-gp2"},"parameters":{"encrypted":"true","fsType":"ext4","type":"gp2"},"provisioner":"kubernetes.io/aws-ebs","volumeBindingMode":"WaitForFirstConsumer"}

Provisioner:           kubernetes.io/aws-ebs
Parameters:            encrypted=true,fsType=ext4,type=gp2
AllowVolumeExpansion:  True
MountOptions:          &lt;none&gt;
ReclaimPolicy:         Delete
VolumeBindingMode:     WaitForFirstConsumer
Events:                &lt;none&gt;</code></pre>
</div>
</div>
</p>
<p>Now I want to patch this storage class for only ReclaimPolicy attribute so that ReclaimPolicy is switched to Retain</p>
<p>I am looking for a specific patch command in this case.</p>

Ashley
<p>It would be short and simple 🙂:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl patch sc encrypted-gp2 -p '{&quot;ReclaimPolicy&quot;:&quot;Retain&quot;}'
</code></pre>
<p>But StorageClass is immutable so you will have to create a new one:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl get sc encrypted-gp2 -o=yaml &gt; sc.yaml
</code></pre>
<p>Edit the <code>sc.yaml</code> and change the reclaim policy 🖥️. Then:</p>
<pre><code>$ kubectl replace -f sc.yaml --force 
</code></pre>
