<p>I am trying to access a k0s cluster with Jenkins in order to deploy from Jenkins pipeline. In order to copy/paste cluster credentials in the kubeconfig file I tried to access with &quot;~/.kube/config&quot; command but there is an error saying &quot;No such file or directory&quot; i.e when I run :</p>
<pre><code>sudo cp ~/.kube/config ~/.jenkins/.kube/
</code></pre>
<p>I get <em><strong>No such file or directory</strong></em> error. It appears as if the config file is not there or may be located elsewhere where I am not aware.
I have created a kubeconfig file for the root user (on the assumption that it doesnt exist by default) as per the documentation <a href="https://docs.k0sproject.io/main/cli/k0s_kubeconfig_create/" rel="nofollow noreferrer">here</a> :</p>
<pre><code>k0s kubeconfig create root
</code></pre>
<p>but when I reattempt to copy I am still getting same error 'No such file or directory'. The kubeconfig file <em>has been created</em> as per output from this command <code>k0s kubeconfig create root</code>  :</p>
<pre><code>WARN[2022-01-30 17:44:16] no config file given, using defaults

apiVersion: v1
clusters:

cluster:
server: https://10.XXX.XXX.XXX:6443
certificate-authority-data: xxxxxxxx
name: k0s
contexts:
context:
cluster: k0s
user: root
name: k0s
current-context: k0s
kind: Config
preferences: {}
users:
name: root
user:
client-certificate-data: xxxxxxxxxxxx
</code></pre>
<p>I can verify that the file indeed exists with command <code>k0s kubectl config view</code>:</p>
<pre><code>apiVersion: v1
clusters:

cluster:
certificate-authority-data: DATA+OMITTED
server: https://localhost:6443
name: local
contexts:
context:
cluster: local
namespace: default
user: user
name: Default
current-context: Default
kind: Config
preferences: {}
users:
name: user
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
</code></pre>
<p>One of the posts suggests using the command <code>k0s kubectl get pods -v=6</code> to see the exact location of the kubeconfig file but when I run it -v seems unsupported for k0s :</p>
<pre><code>Error: unknown shorthand flag: 'v' in -v=6
See 'k0s kubectl get --help' for usage
</code></pre>
<p>As a check I have done <code>cd ~/.kube/config</code> but there is nothing also there</p>
<p>What am I missing ?</p>

Golide
<p>I found out what I was missing :</p>
<p>~/.kube/config does NOT get created by k0s by default at all. What k0s does create by default is the &quot;break-the-glass&quot; admin kubeconfig which is located at /var/lib/k0s/pki/admin.conf</p>
<p>So I had to do :</p>
<ol>
<li><code>cp /var/lib/k0s/pki/admin.conf ~/.kube/config</code></li>
<li><code>cp ~/.kube/config/admin.conf /var/lib/jenkins</code></li>
<li>Add jenkins user to sudo users :</li>
</ol>
<p>nano -f /etc/sudoers</p>
<p>then</p>
<pre><code>jenkins ALL=NOPASSWD: ALL
</code></pre>
<p>The recommended way however is to avail dedicated access for Jenkins with proper RBAC allowing only the needed access e.g service account tokens.  As next step I will have to test this on another Jenkins instance since I can no longer revoke access (disadvantage of using admin.conf)</p>
