kubectl Plugins

发布时间: 更新时间: 总字数:377 阅读时间:1m 作者: IP上海 分享 网址

k8s kubectl plugins - krew 安装部署

install

Linux/Mac

  • install 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/')" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
  tar zxvf krew.tar.gz &&
  KREW=./krew-"${OS}_${ARCH}" &&
  "$KREW" install krew
)
  • set env

.bashrc or .zshrc中添加

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
  • test
# kubectl krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."

Usage:
  kubectl krew [command]

Available Commands:
  help        Help about any command
  index       Manage custom plugin indexes
  info        Show information about an available plugin
  install     Install kubectl plugins
  list        List installed kubectl plugins
  search      Discover kubectl plugins
  uninstall   Uninstall plugins
  update      Update the local copy of the plugin index
  upgrade     Upgrade installed plugins to newer versions
  version     Show krew version and diagnostics

Flags:
  -h, --help      help for krew
  -v, --v Level   number for the log level verbosity

Use "kubectl krew [command] --help" for more information about a command.

Mac

brew install kubectx

use

kubectl krew update
kubectl krew search
kubectl krew install whoami
kubectl whoami
kubectl krew uninstall whoami

开发一个 plugin 示例

#!/bin/bash

# optional argument handling
if [[ "$1" == "version" ]]
then
    echo "1.0.0"
    exit 0
fi

# optional argument handling
if [[ "$1" == "config" ]]
then
    echo "$KUBECONFIG"
    exit 0
fi

echo "I am a plugin named kubectl-foo"
  • Using a plugin To use a plugin, make the plugin executable:
sudo chmod +x ./kubectl-foo

and place it anywhere in your PATH:

sudo mv ./kubectl-foo /usr/local/bin

You may now invoke your plugin as a kubectl command:

$ kubectl foo
I am a plugin named kubectl-foo

All args and flags are passed as-is to the executable:

$ kubectl foo version

浏览 kubernetes 对象层次结构作为树插件


kubectl krew install tree
kubectl tree --help

wget https://github.com/ahmetb/kubectl-tree/releases/download/v0.4.3/kubectl-tree_v0.4.3_linux_amd64.tar.gz

mv xxx /usr/local/bin/kubectl-tree

$ kubectl krew install lineage
$ kubectl lineage --version

# Install from Source

$ git clone git@github.com:tohjustin/kube-lineage.git && cd kube-lineage
$ make install
$ kube-lineage --version

F&Q

error unable to find any kubectl plugins in your path

mv xxx  /usr/local/bin/kubectl-xxx
chmod +x  /usr/local/bin/kubectl-xxx

参考

  1. https://krew.sigs.k8s.io/
  2. https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
本文总阅读量 次 本站总访问量 次 本站总访客数
Home Archives Categories Tags Statistics