4、kubectl插件管理器Krew安装与使用
实战:kubectl 插件管理器 Krew 安装与使用-2023.3.3(测试成功)
目录
[toc]
实验环境
实验环境:1、win10,vmwrokstation虚机;2、k8s集群:3台centos7.61810虚机,1个master节点,2个node节点k8sversion:v1.22.2containerd:v1.5.5
实验软件
- 验证
#验证[root@master1 ~]#krew --helpkrewisthekubectlpluginmanager.Youcaninvokekrewthroughkubectl:"kubectl krew [command]..."Usage:kubectlkrew[command]AvailableCommands:completiongeneratetheautocompletionscriptforthespecifiedshellhelpHelpaboutanycommandindexManagecustompluginindexesinfoShowinformationaboutanavailableplugininstallInstallkubectlpluginslistListinstalledkubectlpluginssearchDiscoverkubectlpluginsuninstallUninstallpluginsupdateUpdatethelocalcopyofthepluginindexupgradeUpgradeinstalledpluginstonewerversionsversionShowkrewversionanddiagnosticsFlags:-h,--helphelpforkrew-v,--vLevelnumberfortheloglevelverbosityUse"kubectl krew [command] --help"formoreinformationaboutacommand.[root@master1 ~]#krew versionOPTIONVALUEGitTagv0.4.3GitCommitdbfefa5IndexURIhttps:BasePath/root/.krewIndexPath/root/.krew/index/defaultInstallPath/root/.krew/storeBinPath/root/.krew/binDetectedPlatformlinux/amd64[root@master1 ~]#
方法2:安装krew
软件(官方脚本)
- 安装软件(官方安装命令)
(1)步骤1:安装git
注意:这里是需要安装git的。
yuminstall-ygit
(2)执行脚本命令
(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:tarzxvf"${KREW}.tar.gz"&&./"${KREW}"installkrew)
(3)添加环境变量
[root@master1 ~]#vim .bashrcexportPATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"#追加这一行[root@master1 ~]#source .bashrc
(4)验证
#验证[root@master1 ~]#krew --helpkrewisthekubectlpluginmanager.Youcaninvokekrewthroughkubectl:"kubectl krew [command]..."Usage:kubectlkrew[command]AvailableCommands:completiongeneratetheautocompletionscriptforthespecifiedshellhelpHelpaboutanycommandindexManagecustompluginindexesinfoShowinformationaboutanavailableplugininstallInstallkubectlpluginslistListinstalledkubectlpluginssearchDiscoverkubectlpluginsuninstallUninstallpluginsupdateUpdatethelocalcopyofthepluginindexupgradeUpgradeinstalledpluginstonewerversionsversionShowkrewversionanddiagnosticsFlags:-h,--helphelpforkrew-v,--vLevelnumberfortheloglevelverbosityUse"kubectl krew [command] --help"formoreinformationaboutacommand.[root@master1 ~]#krew versionOPTIONVALUEGitTagv0.4.3GitCommitdbfefa5IndexURIhttps:BasePath/root/.krewIndexPath/root/.krew/index/defaultInstallPath/root/.krew/storeBinPath/root/.krew/binDetectedPlatformlinux/amd64[root@master1 ~]#
2、使用kubectl-plugin
1.krew插件管理器使用案例
Quickstart
Krew helps you discover and install kubectl
pluginson your machine.
You can install and use a wide variety ofkubectl
plugins to enhance your Kubernetes experience.
Let’s get started:
Install and set upKrew on your machine.
Download the plugin list:
sh$kubectlkrewupdate
这里有时会无法拉取的:(一会儿可以,一会儿不行,还是因为墙的问题……,可能会拉取github超时)
Discover plugins available on Krew:
sh$kubectlkrewsearchNAMEDESCRIPTIONINSTALLEDaccess-matrixShowanRBACaccessmatrixforserverresourcesnoadvise-pspSuggestsPodSecurityPoliciesforcluster.noauth-proxyAuthenticationproxytoapodorserviceno[...]
Choose a plugin from the list and install it:
sh$kubectlkrewinstallaccess-matrix
这里也会有时拉取不下来的:
Use the installed plugin:
sh$kubectlaccess-matrix
Keep your plugins up-to-date:
sh$kubectlkrewupgrade
Uninstall a plugin you no longer use:
sh$kubectlkrewuninstallaccess-matrix
This is practically all you need to know to start using Krew.
注意:自己的pc是有连接vpn科学上网的,但是里面的虚机好像并不能正常使用这个vpn,因此这些无法被正常拉取下来的;