Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Krew be Installed as Super User (su)? #857

Open
sosukeinu opened this issue Jun 14, 2024 · 5 comments
Open

Can Krew be Installed as Super User (su)? #857

sosukeinu opened this issue Jun 14, 2024 · 5 comments
Labels
kind/support Categorizes issue or PR as a support question. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@sosukeinu
Copy link

Hello,

I'm trying to use krew with RKE2 which runs by default as the superuser. When I install krew in the userspace, kubectl (which is located at /var/lib/rancher/rke2/bin/kubectl and KUBECONFIG is here /etc/rancher/rke2/rke2.yaml) has no idea where or how to access krew when I type sudo /var/lib/rancher/rke2/bin/kubectl krew update.

I know it is probably pretty simple, but is there a trick to getting krew to work for superuser rather than current user?

Thank you for your time,
Jon

@ahmetb
Copy link
Member

ahmetb commented Jun 14, 2024

I'm trying to understand wdym by

kubectl [...] has no idea where or how to access krew

kubectl looks at $PATH to find plugins. So when you type kubectl krew it will look for kubectl-krew executable in directories listed in $PATH.

If you followed the installation instructions on Krew website, the binary is likely at $HOME/.krew/bin/kubectl-krew which won't work when you run kubectl as a different user. You may want to symlink that path to /usr/local/bin.

Krew installs any state into $HOME/.krew of the current user. You can override that with a custom path specified through $KREW_ROOT environment variable. Maybe you can set $KREW_ROOT to somewhere like /usr/local/krew and symlink /usr/local/krew/bin/kubectl-krew to /usr/local/bin/kubectl-krew so that multiple users can use the same krew installation+plugins at the same time (granted, $KREW_ROOT variable must be set in their shells as well).

/kind support

@k8s-ci-robot k8s-ci-robot added the kind/support Categorizes issue or PR as a support question. label Jun 14, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 12, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 12, 2024
@carlosaya
Copy link

carlosaya commented Nov 4, 2024

I have been trying this as well and thus far am unable to get it to work. I am doing the following to install krew:

(
  export KREW_ROOT=/var/opt/krew
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
  sudo chmod -R 0755 /var/opt/krew/store/krew/
)

I have the following in /etc/profile.d/krewpath.sh:

export KREW_ROOT=/var/opt/krew
export PATH=$PATH:/var/opt/krew/bin

When I login, I can see the following...

$ echo $KREW_ROOT
/var/opt/krew

$ echo $PATH
/home/packer/.local/bin:/home/packer/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/opt/krew/bin

$ ls -lah /var/opt/krew/bin
total 0
drwxr-xr-x 2 root root 26 Nov  4 17:30 .
drwxr-xr-x 6 root root 59 Nov  4 17:30 ..
lrwxrwxrwx 1 root root 36 Nov  4 17:30 kubectl-krew -> /var/opt/krew/store/krew/v0.4.4/krew

$ ls -lah /var/opt/krew/store/krew/v0.4.4/krew
-rwxr-xr-x 1 root root 12M Nov  4 17:30 /var/opt/krew/store/krew/v0.4.4/krew

Everything there looks good as far as I can tell, yet...

$ kubectl krew
Error: unknown command "krew" for "kubectl"

$ kubectl plugin list
Unable to read directory "/home/packer/.local/bin" from your PATH: open /home/packer/.local/bin: no such file or directory. Skipping...
Unable to read directory "/home/packer/bin" from your PATH: open /home/packer/bin: no such file or directory. Skipping...
: no such file or directory. Skipping...bin\r" from your PATH: open /var/opt/krew/bin
The following compatible plugins are available:

/usr/bin/kubectl-anthos
  - error: unable to identify /usr/bin/kubectl-anthos as an executable file: stat /usr/bin/kubectl-anthos: no such file or directory
error: one plugin warning was found

Invoking kubectl-krew directly works fine:

$ /var/opt/krew/bin/kubectl-krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."
<snip>

Any ideas? 🙏

@carlosaya
Copy link

Following up, it works fine if I copy the binaries to /usr/bin. Maybe kubectl doesn't follow symlinks? Had the issue with both kubectl krew and kubectl hns (which I installed via krew).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants