Skip to content

K3s' kubectl prefers /etc/rancher/k3s/k3s.yaml over ~/.kube/config #1541

Description

@optix2000

Version:
k3s version v1.17.3+k3s1 (5b17a17)

K3s arguments:
curl -sfL https://get.k3s.io | sh -s - --no-flannel --no-deploy traefik

Describe the bug
kubectl prefers reading /etc/rancher/k3s/k3s.yaml over ~/.kube/config when ~/.kube/config exists.

To Reproduce

  1. Write a valid ~/.kube/config file. sudo kubectl config view --raw > ~/.kube/config
  2. Try running a kubectl command. kubectl config view

Expected behavior
K3s' kubectl follows the load rules in kubectl config --help, with a fallback to /etc/rancher/k3s/k3s.yaml as an additional last rule.

 The loading order follows these rules:

  1.  If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes
place.
  2.  If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for
your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When
a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the
last file in the list.
  3.  Otherwise, ${HOME}/.kube/config is used and no merging takes place.

Actual behavior

  • kubectl tries to read /etc/rancher/k3s/k3s.yaml and fails.
    Yes I understand that I can work around this with --write-kubeconfig-mode, but having a proper ~/.kube/config file provides interop with existing K8s tools (ie helm) and lets me work on other k8s clusters using the same kubectl command.
    Yes I also understand I can also work around this issue by exporting my own $KUBECONFIG env var, but k3s' kubectl breaks assumptions of how the command works (see below).
  • kubectl config --help says 3. Otherwise, ${HOME}/.kube/config is used and no merging takes place, which doesn't seem to be the case.

Additional context / logs

% ls -l ~/.kube/config
-rw-r--r-- 1 user user 1052 Mar 14 20:32 /home/user/.kube/config
% kubectl --v=9 config view
WARN[2020-03-14T20:48:00.146588365-07:00] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions
F0314 20:48:00.159402   23853 helpers.go:114] error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status
Closed

Relationships

None yet

Development

No branches or pull requests

Issue actions