Skip to main content

  1. Log in
  2. Sign up

DevOps

    1. Home
    2. Questions
    3. Tags

    4. Users
    5. Jobs
    6. Companies
    7. Unanswered
  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

https://devops.stackexchange.com/questions/16043/error-error-loading-config-file-etc-rancher-k3s-k3s-yaml-open-etc-rancher

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

Share

Improve this question

asked May 31, 2022 at 19:53

](https://devops.stackexchange.com/users/18965/evan-carroll)

Evan Carroll

2,611

66 gold badges

3333 silver badges

8181 bronze badges

Add a comment

2 Answers

Sorted by:

32

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 export KUBECONFIG=~/.kube/config to your ~/.profile or ~/.bashrc to make it persist on reboot.

Share

Improve this answer

edited Nov 29 at 18:45

](https://devops.stackexchange.com/users/44615/emil-carpenter)

Emil Carpenter

103

33 bronze badges

answered May 31, 2022 at 19:53

](https://devops.stackexchange.com/users/18965/evan-carroll)

Evan Carroll

2,611

66 gold badges

3333 silver badges

8181 bronze badges

  • If the “sudo k3s kubectl …” line is giving an error stating “sudo: k3s: command not found”, then you can try by adding /usr/local/bin/ in front of “k3s”. Which would make that line as this: sudo /usr/local/bin/k3s kubectl config view --raw > "$KUBECONFIG"

    – UNOPARATOR

    Commented Aug 1, 2022 at 7:30

  • @UNOPARATOR the only way that could make a difference is if /usr/local/bin is not in your $PATH which would be pretty awkward anyway.

    – Evan Carroll

    Commented Aug 1, 2022 at 15:34

  • In my case with a CentOS 8 Stream server, after the k3s installation that line wasn’t working. There was no mention of adding that to $PATH but it might be considered common practice and not mentioned because of that. I’m no linux expert of any kind, just commented in case someone like me encounters the same issue.

    – UNOPARATOR

    Commented Aug 2, 2022 at 5:06

  • When you run echo $PATH you should see /usr/local/bin in your path. Almost certainly CentOS does that. (also, CentOS is dead, everyone went to Rocky).

    – Evan Carroll

    Commented Aug 2, 2022 at 14:47

  • 1

    @UNOPARATOR, the problem is that on CentOS by default sudo will use a PATH value different from your own PATH. This other value does not include /usr/local/bin, which is why it couldn’t find the k3s command. One way to resolve this is to add /usr/local/bin to the secure_path option in /etc/sudoers. See superuser.com/questions/927512/… for details. Ubuntu and Debian do not have this issue (secure_path includes /usr/local/bin).

    – Stanley Yu

    Commented Dec 28, 2023 at 20:55

Show 3 more comments

0

Prefix you command with sudo.

Run:

sudo k3s kubectl version

Share

Improve this answer

answered May 22 at 21:43

](https://devops.stackexchange.com/users/45321/user10339671)

user10339671

1

Add a comment

Your Answer

Sign up or log in

Sign up using Google

Sign up using Email and Password

Post as a guest

Name

Email

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

##

Not the answer you’re looking for? Browse other questions tagged

or ask your own question.

Linked

6k3s: The connection to the server localhost:8080 was refused - did you specify the right host or port?

1With kubectl, I’m getting Unable to connect to the server: x509: certificate signed by unknown authority

-1How can I get an installation of k3s working with KubeApps?

0Does /etc/rancher/k3s/registries.yaml affect `k3s ctr` and `k3s crictl`?

Hot Network Questions

Question feed

DevOps
Company
Stack Exchange Network

Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.12.18.20664

Updated: