<p>I have two kubeconfigs file, the first one is following which I use to communicate with the cluster and the second one is for Aquasec which is in JSON format. How can I merge these two?</p>
<pre><code>apiVersion: v1
    clusters:
    - cluster:
        certificate-authority-data: DATA+OMITTED
        server: https://656835E69F31E2933asdAFAKE3F5904sadFDDC112dsasa7.yld432.eu-west-2.eks.amazonaws.com
      name: arn:aws:eks:eu-west-2:test651666:cluster/Magento
    - cluster:
        certificate-authority-data: DATA+OMITTED
        server: https://kubernetes.docker.internal:6443
      name: docker-desktop
    - cluster:
        certificate-authority-data: DATA+OMITTED
        server: https://192.142.242.111:6443
      name: kubernetes
    contexts:
    - context:
        cluster: arn:aws:eks:eu-west-2:test651666:cluster/testing
        user: arn:aws:eks:eu-west-2:test651666:cluster/testing
      name: arn:aws:eks:eu-west-2:test651666:cluster/testing
    - context:
        cluster: docker-desktop
        user: docker-desktop
      name: docker-desktop
    - context:
        cluster: docker-desktop
        user: docker-desktop
      name: docker-for-desktop
    - context:
        cluster: kubernetes
        user: kubernetes-admin
      name: kubernetes-admin@kubernetes
    current-context: arn:aws:eks:eu-west-2:test651666:cluster/testing
    kind: Config
    preferences: {}
    users:
    - name: arn:aws:eks:eu-west-2:test651666:cluster/testing
</code></pre>

<p>You can set the <code>KUBECONFIG</code> environment variable to multiple config files delimited by <code>:</code> and kubectl will automatically merge them behind the scenes.</p>
<p>For example:</p>
<pre><code>export KUBECONFIG=config:my-config.json
</code></pre>
<p>In the export above, <code>config</code> is the default config file contained within <code>~/.kube</code> and <code>my-config.json</code> would be your second config file, which you said is in JSON format.</p>
<p>You can see the merged config using this command, which shows a unified view of the configuration that kubectl is currently using:</p>
<pre><code>kubectl config view
</code></pre>
<p>Because kubectl automatically merges multiple configs, you shouldn't need to save the merged config to a file.  But if you really want to do that, you can redirect the output, like this:</p>
<pre><code>kubectl config view --flatten &gt; merged-config.yaml
</code></pre>
<p>Check out <a href="https://ahmet.im/blog/mastering-kubeconfig/" rel="nofollow noreferrer">Mastering the KUBECONFIG file</a>, <a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/" rel="nofollow noreferrer">Organizing Cluster Access Using kubeconfig Files</a> for more explanation and to see some other examples.</p>
