1、需要自行安装k9s
2、config文件放在home的.kube隐藏文件夹下文章来源:https://www.toymoban.com/news/detail-855508.html
#!/bin/bash
# define log & color
readonly FG_GREY="30" #灰色
readonly FG_RED="31"
readonly FG_GREEN="32"
readonly FG_YELLOW="33"
readonly FG_BLUE="34" #前景色蓝色
readonly FG_VIOLET="35" #紫色
readonly FG_SKY_BLUE="36"
readonly FG_WHITE="37"
readonly BG_RED="41"
readonly BG_GREEN="42"
readonly BG_YELLOW="43"
readonly BG_BLUE="44"
readonly BG_VIOLET="45"
readonly BG_SKYBLUE="46"
readonly BG_WHITE="47"
readonly LOG_DEBUG="[调试]"
readonly LOG_INFO="[信息]"
readonly LOG_WARN="[警告]"
readonly LOG_ERROR="[错误]"
function debug()
{
echo -e "\033[${FG_WHITE}m${LOG_DEBUG}\033[0m $1"
}
function info(){
echo -e "\033[${FG_GREEN}m${LOG_INFO}\033[0m $1"
}
function infoText(){
echo -en "\033[${FG_GREEN}m $1 \033[0m"
}
function warn()
{
echo -e "\033[${FG_YELLOW}m${LOG_WARN}\033[0m $1"
}
function error()
{
echo -e "\033[${FG_RED}m${LOG_ERROR}\033[0m $1"
}
function coloredLog()
{
echo -e "\033[$1;$2m $3\033[0m"
}
function main() {
order=1
configs=$(ls -l ~/.kube/ |grep -v 'total'|awk '{print $9}')
for config in ${configs};do
infoText ${order} && echo -e ${config}
let order+=1
done
echo -en "\033[${FG_GREEN}m${LOG_INFO}\033[0m please choose config:"
read choostOrder
order=1
for config in ${configs};do
if [[ ${order} == ${choostOrder} ]]; then
info "chose ${choostOrder}, use config ${config}"
cd && echo $(pwd) && echo "exec k9s -A --kubeconfig=.kube/${config}"
k9s -A --kubeconfig=.kube/${config}
break
fi
let order+=1
done
}
main
使用效果:
文章来源地址https://www.toymoban.com/news/detail-855508.html
到了这里,关于【shell】利用k9s和config文件进入k8s集群脚本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!