HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajor

error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
rancherfileerrork3sopenpermissiondeniedconfigloadingyaml

Problem

When I run commands under k3s kubectl, I get
$ k3s kubectl version
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions
error: error loading config file "/etc/rancher/k3s/k3s.yaml" : open /etc/rancher/k3s/k3s.yaml: permission denied


How should I resolve this? Should I change the permissions of /etc/rancher/k3s/k3s.yaml

Solution

No, do not change permissions of /etc/rancher/k3s/k3s.yaml

First set up your an environmental variable for KUBECONFIG=~/.kube/config.

export KUBECONFIG=~/.kube/config


Then let's generate the file at that location. Your k3s.yaml file should NOT be world readable.. This is by-design. It should be owned by root and set to 0600. Instead copy the config locally as described here,
mkdir ~/.kube 2> /dev/null
sudo k3s kubectl config view --raw > "$KUBECONFIG"
chmod 600 "$KUBECONFIG"


You can add KUBECONFIG=~/.kube/config to your ~/.profile or ~/.bashrc to make it persist on reboot.

Code Snippets

export KUBECONFIG=~/.kube/config

Context

StackExchange DevOps Q#16043, answer score: 22

Revisions (0)

No revisions yet.