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



  • 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



  • 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. https://github.com/k3s-io/k3s/issues/389 . This is by-design. It should be owned by root and set to 0600. Instead copy the config locally as https://devops.stackexchange.com/a/16014/18965 ,

    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.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2