1、需要自行安装k9s
2、config文件放在home的.kube隐藏文件夹下
shell
#!/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
使用效果: