kubectl安装kubectl-kc

kubecm 安装

krew的安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

(
  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
)

添加以下内容到

1
2

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

重启终端输入

1
kubectl krew

安装kubecm

1
kubectl krew install kc

注意这个安装后的命令为

1
kubectl-kc

这里通过alias 来替换一下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 kubecm list
+------------+-----------------------------------+-----------------------------+--------------------------------+--------------------------------+--------------+
|   CURRENT  |                NAME               |           CLUSTER           |              USER              |             SERVER             |   Namespace  |
+============+===================================+=============================+================================+================================+==============+
|            |                dev                |   cluster.local-tf26gt9mmk  |   kubernetes-admin-tf26gt9mmk  |     https://10.7.20.26:6443    |    default   |
+------------+-----------------------------------+-----------------------------+--------------------------------+--------------------------------+--------------+
|      *     |   hxf-kubernetes-admin@cluster.l  |   cluster.local-cm2bg82gtt  |   kubernetes-admin-cm2bg82gtt  |   https://master.k8s.io:16443  |    default   |
|            |                ocal               |                             |                                |                                |              |
+------------+-----------------------------------+-----------------------------+--------------------------------+--------------------------------+--------------+

Cluster check succeeded!
Kubernetes version v1.30.4
Kubernetes master is running at https://master.k8s.io:16443
[Summary] Namespace: 25 Node: 6 Pod: 80

添加context如下

1
2
# config-dv 为配置文件,context-name 为展示名称
kubecm add -f config-dv --context-name dev

切换context

1
kubecm switch 

来进行context的选择即可。

Licensed under CC BY-NC-SA 4.0
最后更新于 Dec 31, 2024 09:01 UTC
comments powered by Disqus
Built with Hugo
主题 StackJimmy 设计