Solving unable to read etc rancher k3s k3s yaml K3S Error
Posted September 18, 2023
Learn how to solve the Unable to read /etc/rancher/k3s/k3s.yaml, please start server with -write-kubeconfig-mode to modify kube config permissions error in your K3s Clusters.
Dive into this guide and learn how to solve the WARN[0003] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with –write-kubeconfig-mode to modify kube config permiss error: error loading config file “/etc/rancher/k3s/k3s.yaml”: open /etc/rancher/k3s/k3s.yaml: permission denied Error in your K3s Clusters.
What is /etc/rancher/k3s/k3s.yaml Error
Like K8s, K3s Kubernetes distribution uses a kubeconfig
file to any of your Kubernetes configurations. K3s saves the kubeconfig
file in the /etc/rancher/k3s/k3s.yaml
path. If you attempt to run a cluster, K3s must read this file to successfully run either worker or master nodes.
Your K3s server must read /etc/rancher/k3s/k3s.yaml
to access kubeconfig. So the Unable to read /etc/rancher/k3s/k3s.yaml tells you K3s failed to read kubeconfig
.
If the baremetal user
runing the k3s cluster doesn’t have permissions to read k3s.yaml
, then expect to get /etc/rancher/k3s/k3s.yaml, please start server with -write-kubeconfig-mode to modify kube config permissions
Troubleshooting your /etc/rancher/k3s/k3s.yaml Errors
Let’s check how this error is occurring on the server. First, you must ensure your K3s server is running:
sudo systemctl status k3s
If you get alternative results, run the following command to start a K3s server:
sudo k3s server
To test if K3s is working, run the following command:
kubectl get nodes
Resolving/etc/rancher/k3s/k3s.yaml Error
If kubeconfig
lacks permissions to k3s.yaml
file, the error will be as follows:
Let’s solve the error.
Step One: Re-installing K3s server
The first set of the solution involves reinstalling k3s on your machine:
Solution One: reinstall k3s, but this time install the server server with 644 permissions:
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
Solution Two: If still you have Unable to read /etc/rancher/k3s/k3s.yaml Error try addind a K3S_KUBECONFIG_MODE
parameter to your intallation command:
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s -
Confirm if the unable to read etc rancher k3s k3s yaml K3S error is resolved by running the following:
kubectl get nodes
# OR
kubectl cluster-info
Step Two: Elevate Permissions Without Restaling K3s
If you are avoiding reinstalling your K3S server, the following commands are perfect for you:
First, check /etc/rancher/k3s/k3s.yaml
permissions. Do this by running the following command:
ls -l /etc/rancher/k3s/k3s.yaml
Solution One: Elevet permissions to this file:
sudo chmod 644 /etc/rancher/k3s/k3s.yaml
Reboot your machine and rerun the above command to ensure the Permissions are added.
Solution Two: Copy KUBECONFIG_MOD
Permissions to k3s.service.env
file as root on existing installation :
echo K3S_KUBECONFIG_MODE=\"644\" >> /etc/systemd/system/k3s.service.env
You may be required to reboot your machine to ensure these changes reflect to K3s.
Solution Three Start K3s Server with -write-kubeconfig-mode
Option:
For this to work, first stop the server:
sudo systemctl stop k3s
Then start the server as follows:
sudo k3s server --write-kubeconfig-mode 644
Solution Four: Configure Kubectl
K3s may be failing to communicate with its K3s API server, so configure Kubectl as follows:
- Create a Kubectl config file
mkdir ~/.kube
- Generate
kubeconfig
for your clusters
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config && sudo chown $USER ~/.kube/config
- Copy and export the
kubeconfig
setting
sudo chmod 600 ~/.kube/config && export KUBECONFIG=~/.kube/config
Solution Five: Copy .kube/config
to the desired clusters:
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/k3s-config && sudo chown $USER: ~/.kube/k3s-config && export KUBECONFIG=~/.kube/k3s-config
If you have no .kube/config
in your system, the following command comes in handy:
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config && sudo chown $USER: ~/.kube/config && unset KUBECONFIG
Restart k3s:
sudo systemctl restart k3s
The solution depends on how you have k3s installed on your machine. Ensure you reboot your machine once you have these changes so they can reflect your kubectl
as expected.
Wrapping up
All the above solutions are valid unable to read etc rancher k3s k3s yaml K3S Error. So do let us know which one worked for you and why.
Confirm if the error is resolved by running the following:
kubectl get nodes
# OR
kubectl cluster-info
If you have any errors on your K3s server, leave a comment, and we will try to troubleshoot and solve it for you!