<p>I have an local Kubernetes environment and I basically copy <strong>.kube/config</strong> file to my local and added &quot;<strong>context</strong>&quot;, &quot;<strong>users</strong>&quot;, and &quot;<strong>cluster</strong>&quot; informations to my current &quot;<strong>.kube/config</strong>&quot; file. That's ok, I can connect to my local file.</p>
<p>But I want to add these informations to my local config file with commands.</p>
<p>So regarding to this page, I can use &quot;<strong>certificate-authority-data</strong>&quot; as parameter like below:   ---&gt; <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" rel="noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/</a></p>
<pre><code>PS C:\Users\user\.kube&gt; kubectl config --kubeconfig=config set-cluster local-kubernetes --server=https://10.10.10.10:6443 --certificate-authority-data=LS0tLSAASDASDADAXXXSDETRDFDJHFJWEtGCmx0YVR2SE45Rm9IVjAvQkdwRUM2bnFNTjg0akd2a3R4VUpabQotLS0tLUVORCBDADADADDAADS0tXXXCg==
Error: unknown flag: --certificate-authority-data
See 'kubectl config set-cluster --help' for usage.
PS C:\Users\user\.kube&gt;
</code></pre>
<p>But it throws error like above. I'm using kubernetes latest version.</p>
<p>How can I add these informations to my local file with kubectl config command?</p>
<p>Thanks!</p>

yatta
<p>Possible solution for that is to use <code>--flatten</code> flag with config command:</p>
<pre><code>➜  ~ kubectl config view --flatten=true  
</code></pre>
<blockquote>
<p>flatten the resulting kubeconfig file into self contained output
(useful for creating portable kubeconfig files)</p>
</blockquote>
<p>That can be also exported to a file (portable config):</p>
<pre class="lang-sh prettyprint-override"><code>kubectl config view --flatten &gt; out.txt
</code></pre>
<p>You can read more about kube config in <a href="https://ahmet.im/blog/mastering-kubeconfig/" rel="noreferrer">Mastering the KUBECONFIG file</a> document.</p>
<p>Once you run this command on the server where the appropriate certificate are present you will receive base64 encoded keys: <code>certificate-authority-data</code>, <code>client-certificate-data</code> and <code>client-key-data</code>.</p>
<p>Then you can use the command provided in the <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#config" rel="noreferrer">official config document</a>:</p>
<pre><code>➜  ~ kubectl config set clusters.my-cluster.certificate-authority-data $(echo &quot;cert_data_here&quot; | base64 -i -)
</code></pre>
<p>Then you have to replace <code>(echo &quot;cert_data_here&quot; | base64 -i -)</code> with data from flatten config file.</p>
<p>Worth to mention that this info is also available with <code>-help flag</code> for kubectl config:</p>
<pre><code>kubectl config set --help   
Sets an individual value in a kubeconfig file

 PROPERTY_VALUE is the new value you wish to set. Binary fields such as 'certificate-authority-data'
expect a base64 encoded string unless the --set-raw-bytes flag is used.

 Specifying a attribute name that already exists will merge new fields on top of existing values.

Examples:
  # Set certificate-authority-data field on the my-cluster cluster.
  kubectl config set clusters.my-cluster.certificate-authority-data $(echo &quot;cert_data_here&quot; | base64
-i -)
</code></pre>
