4

kubectl的node-shell插件

 1 year ago
source link: https://www.bboy.app/2023/03/13/kubectl%E7%9A%84node-shell%E6%8F%92%E4%BB%B6/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

kubectl的node-shell插件

March 13, 2023
20230313-1.webp

我一般都是使用lens的node shell功能直接搞定所有需要再节点上的操作,其实原理都是一样的,就是在节点上启动一个pod。但是有时候有的机器是没有安装lens的,所以直接使用node-shell这个插件就很好。

首先你要安装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
)

或者直接简单粗暴一点

brew install krew

之后加入环境变量

vim ~/.zshrc

export PATH="${PATH}:${HOME}/.krew/bin"

安装完krew之后就可以直接安装node-shell了

kubectl krew install kvaps/node-shell

安装完成之后直接输入下面的命令就可以使用

kubectl node-shell node1

当然,在某些地方你会发现node-shell启动的很慢(比如china),因为在创建pod的时候需要从dockerhub上去拉取镜像,但是你的网络是几乎拉取不到dockerhub上的镜像的,所以你需要修改node-shell的镜像

vim ~/.krew/store/node-shell/v1.7.0/kubectl-node_shell

image="${KUBECTL_NODE_SHELL_IMAGE:-docker.io/library/alpine}"

image="${KUBECTL_NODE_SHELL_IMAGE:-dockerproxy.com/library/alpine}"

当然你也可以改为你的镜像仓库的地址

欢迎关注我的博客www.bboy.app

Have Fun


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK