怎么离线安装kubectl krew工具?并且通过krew工具安装kubectl 离线插件?


一、什么是krew?

 

krew是kubectl插件的一个包管理工具,通过krew可以用来安装kubectl的插件。

 

类似于yum可以用来管理和安装centos rpm包一样,krew工具可以用来安装、管理kubectl的插件。

 

但是,安装krew插件需要进行联网的操作

 

如果需要进行联网的操作,请参考下面的文档:

 

https://krew.sigs.k8s.io/docs/user-guide/setup/install/

 

本文档接下来的部分,将会介绍通过离线的方式,也就是将krew的工具包下载到本地的方式进行安装

 

二、怎么离线安装krew工具?

 

我们这次安装是在CentOS 7 x86_64的操作系统上来完成的

 

1、下载krew的软件包

 

通过下面的地址,下载krew工具包:

 

https://github.com/kubernetes-sigs/krew/releases/download/v0.4.3/krew-linux_amd64.tar.gz

 

下载之后,可以放到到本地的文件服务器上

 

http://172.20.56.117/kubernetes/kubectl-plugin/krew/v0.4.3/krew-linux_amd64.tar.gz

 

2、下载krew.yaml文件

 

https://github.com/kubernetes-sigs/krew-index/blob/master/plugins/krew.yaml

 

上传到本地文件服务器上

http://172.20.56.117/kubernetes/kubectl-plugin/krew/v0.4.3/krew.yaml

 

3、安装krew工具

 

通过下面的命令进行安装

 

krew_install_tmp=/tmp/krew/v0.4.3 &&
mkdir -p $krew_install_tmp &&
cd $krew_install_tmp &&
wget http://172.20.56.117/kubernetes/kubectl-plugin/krew/v0.4.3/krew-linux_amd64.tar.gz &&
wget http://172.20.56.117/kubernetes/kubectl-plugin/krew/v0.4.3/krew.yaml &&
tar zxvf krew-linux_amd64.tar.gz &&
./krew-linux_amd64 install --manifest=krew.yaml --archive=krew-linux_amd64.tar.gz &&
echo "export PATH=\${KREW_ROOT:-\$HOME/.krew}/bin:\$PATH" >> ~/.bash_profile &&
source ~/.bash_profile &&
kubectl krew -h

 

 

注意:这个安装的操作,要在能执行kubectl命令的机器上

 

出现帮助信息,表示krew工具安装成功:

You can invoke krew through kubectl: "kubectl krew [command]..."

Usage:
  kubectl krew [command]

Available Commands:
  completion  generate the autocompletion script for the specified shell
  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.

 

三、怎么通过krew工具离线安装kubectl插件?

 

安装完了krew工具,并不是目的,目的是通过krew工具来安装kubect的插件

 

下面的部分,介绍安装ingress-nginx的插件,因为,最近几天在研究ingress-nginx的内容,后面的例子,就以安装ingress-nginx这个插件为例子,思路都是一样的,需要其他的插件,按照这个思路来就行了

 

1、查看插件列表,下载需要的插件yaml文件

 

这个是插件目录

https://github.com/kubernetes-sigs/krew-index/tree/master/plugins

 

找到需要的插件的yaml文件,比如ingress-nginx

 

下载到本地,上传到本地文件服务器

http://172.20.56.117/kubernetes/kubectl-plugin/krew/ingress-nginx/ingress-nginx.yaml

 

2、下载插件包

 

查看ingress-nginx.yaml文件,找到对应的uri,查看下载离线包的地址

 

 

下载地址:

https://github.com/kubernetes/ingress-nginx/releases/download/controller-0.31.0/kubectl-ingress_nginx-linux-amd64.tar.gz

 

下载,并且传到本地的文件服务器

http://172.20.56.117/kubernetes/kubectl-plugin/krew/ingress-nginx/kubectl-ingress_nginx-linux-amd64.tar.gz

 

 

3、安装ingress-nginx插件

 

OK,插件的描述文件yaml有了,离线包有了,现在就可以安装了

 

使用下面的命令进行安装:

 

cd /tmp &&
wget http://172.20.56.117/kubernetes/kubectl-plugin/krew/ingress-nginx/kubectl-ingress_nginx-linux-amd64.tar.gz &&
wget http://172.20.56.117/kubernetes/kubectl-plugin/krew/ingress-nginx/ingress-nginx.yaml &&
kubectl krew install --manifest=ingress-nginx.yaml --archive=kubectl-ingress_nginx-linux-amd64.tar.gz &&
kubectl ingress-nginx -h

 

 

看到如下的帮助信息,说明kubectl ingress-nginx这个插件安装成功了

A kubectl plugin for inspecting your ingress-nginx deployments

Usage:
  ingress-nginx [command]

Available Commands:
  backends    Inspect the dynamic backend information of an ingress-nginx instance
  certs       Output the certificate data stored in an ingress-nginx pod
  conf        Inspect the generated nginx.conf
  exec        Execute a command inside an ingress-nginx pod
  general     Inspect the other dynamic ingress-nginx information
  help        Help about any command
  info        Show information about the ingress-nginx service
  ingresses   Provide a short summary of all of the ingress definitions
  lint        Inspect kubernetes resources for possible issues
  logs        Get the kubernetes logs for an ingress-nginx pod
  ssh         ssh into a running ingress-nginx pod

Flags:
      --as string                      Username to impersonate for the operation
      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --cache-dir string               Default HTTP cache directory (default "/root/.kube/http-cache")
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --context string                 The name of the kubeconfig context to use
  -h, --help                           help for ingress-nginx
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.
  -n, --namespace string               If present, the namespace scope for this CLI request
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
  -s, --server string                  The address and port of the Kubernetes API server
      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use

Use "ingress-nginx [command] --help" for more information about a command.

 

说白了,kubectl插件,就是扩展了kubectl的功能,增加了一些命令。

 

现在,kubectl krew工具的离线安装,以及通过krew离线安装kubectl的插件的演示就完事儿了。

 

其他的插件的安装,按照这个套路来就行了。

posted @ 2023-06-09 11:28  Zhai_David  阅读(493)  评论(0编辑  收藏  举报