<p>This is my existing clusterrolebinding </p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: example-role
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: test-role
subjects:
- kind: ServiceAccount
  name: test-sa
  namespace: ns1
</code></pre>

<p>i am planning to add the same ServiceAccount (test-sa) in another namespace (for eg:ns2) and bind it with my ClusterRole "test-role" .</p>

<p>what i have tried</p>

<pre><code>subjects:
- kind: ServiceAccount
  name: test-sa
  namespace: ns2
</code></pre>

<p>i tried to apply the yaml file above like </p>

<pre><code>kubectl patch  clusterrolebinding &lt;clusterrolebinding-name&gt; --type="strategic"  --patch "$(cat role.yaml)"
</code></pre>

<p>Result</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: example-role
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: test-role
subjects:
- kind: ServiceAccount
  name: test-sa
  namespace: ns2
</code></pre>

<p>It is adding the  ClusterRoleBinding with sa in new namespace but my existing binding in namespace ns1 got removed .. is there any way to merge the new changes instead of replace ..iam trying do it in an automated way ..like a bash script for editing this cluserrolebinding,thats why i choose kubectl patch</p>

<p>You can try below command. It worked. Refer <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#patching-resources" rel="noreferrer">here</a>.</p>

<pre><code>kubectl patch clusterrolebinding example-role --type='json' -p='[{"op": "add", "path": "/subjects/1", "value": {"kind": "ServiceAccount", "name": "test-sa","namespace": "ns2" } }]'
</code></pre>

<p><code>op</code> - operation <code>add</code></p>

<p><code>subjects/1</code> - add to subjects array's first position</p>

<pre><code>subjects:
- kind: ServiceAccount
  name: test-sa
  namespace: ns1
- kind: ServiceAccount
  name: test-sa
  namespace: ns2
</code></pre>
