<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dhiraj Shrotri</title>
    <description>The latest articles on DEV Community by Dhiraj Shrotri (@dhiraj-shrotri).</description>
    <link>https://dev.to/dhiraj-shrotri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3617590%2F41610d8b-c8ad-4ed5-aca0-5462cc7b5669.JPG</url>
      <title>DEV Community: Dhiraj Shrotri</title>
      <link>https://dev.to/dhiraj-shrotri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dhiraj-shrotri"/>
    <language>en</language>
    <item>
      <title>K3S troubleshooting: Fixing K3s permission denied and port binding errors on Ubuntu Server</title>
      <dc:creator>Dhiraj Shrotri</dc:creator>
      <pubDate>Sun, 30 Nov 2025 20:09:01 +0000</pubDate>
      <link>https://dev.to/dhiraj-shrotri/k3s-troubleshooting-fixing-k3s-permission-denied-and-port-binding-errors-on-ubuntu-server-422d</link>
      <guid>https://dev.to/dhiraj-shrotri/k3s-troubleshooting-fixing-k3s-permission-denied-and-port-binding-errors-on-ubuntu-server-422d</guid>
      <description>&lt;p&gt;Recently, while setting up K3s on a Beelink mini PC running Ubuntu Server, I ran into two frustrating errors while trying to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first issue was a permissions error loading the kubeconfig, and once that was fixed, a second error appeared indicating that the Kubernetes control plane wasn’t running. After debugging, here’s the full process and solution in case you run into the same problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem 1: kubeconfig Permission Denied
&lt;/h2&gt;

&lt;p&gt;The initial error looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode or --write-kubeconfig-group to modify kube config permissions
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This happens because K3s generates the Kubernetes config file owned by root with restrictive permissions (600). When we run kubectl as a regular user, kubectl can't access it. &lt;/p&gt;

&lt;p&gt;To fix the issue, we create another directory, copy the kubectl config to it and change the ownership of the directory so that kubectl can access it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now running kubectl get nodes threw a different error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The connection to the server 127.0.0.1:6443 was refused - did you specify the right host or port?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally some progress!&lt;/p&gt;

&lt;p&gt;This means kubectl can now read the config file, but the K3s API server isn’t running or reachable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 2: K3s controller-manager port conflict
&lt;/h3&gt;

&lt;p&gt;Checking the K3s service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status k3s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The logs showed this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;failed to listen on 127.0.0.1:10257: bind: address already in use
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This indicates another process is already using port 10257, which is required by the Kubernetes controller-manager. We verify what process is using the port by running the lsof command with the port as argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo lsof -i :10257
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubelite 188849 root 120u IPv6 ... TCP *:10257 (LISTEN)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;kubelite is K3s’s internal Kubernetes binary. That means a previous crashed instance left it running, preventing the new instance from starting.&lt;/p&gt;

&lt;p&gt;To fix this, stop k3s completely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl stop k3s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and kill leftover processes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pkill -f k3s
sudo pkill -f kubelite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to verify the ports are free, we run the lsof command again and that should give us no output.&lt;/p&gt;

&lt;p&gt;Finally we just restart k3s:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start k3s
sudo systemctl status k3s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we run kubectl get nodes, it should run without any issues!&lt;/p&gt;

&lt;p&gt;K3s is incredibly powerful and lightweight, but diagnosing startup issues can be intimidating if you’re new to Kubernetes internals. Understanding the logs and system service behavior helped uncover the root cause quickly.&lt;/p&gt;

&lt;p&gt;Hopefully this helps someone trying to set up K3s on bare metal or home lab hardware!&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>containers</category>
      <category>homelab</category>
    </item>
  </channel>
</rss>
