当前位置:   article > 正文

k8s自动补全命令

k8s自动补全命令
mkdir -p /data/k8sEnv/{kubeconfig,venv}
echo "alias ak8s='cd /data/k8sEnv/kubeconfig && source /data/k8sEnv/venv/k8sEnv'" >> /etc/profile
source /etc/profile
  • 1
  • 2
  • 3
# /data/k8sEnv/venv/k8sEnv
#s file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {

    # reset old environment variables
    if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
        PATH="$_OLD_VIRTUAL_PATH"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi

    unset KUBECONFIG
    if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
        PS1="$_OLD_VIRTUAL_PS1"
        export PS1
        unset _OLD_VIRTUAL_PS1
    fi

    unset VIRTUAL_ENV
    if [ ! "${1-}" = "nondestructive" ] ; then
    # Self destruct!
        unset -f deactivate
    fi
}

# unset irrelevant variables
deactivate nondestructive
ERR=0

VIRTUAL_ENV="$1"
if [[ "$1"x == "x" ]]
then
    echo " $1参数错误! 没有这个集群名称"
    echo "eg: ak8s 集群名称"
    ERR=1
fi
export VIRTUAL_ENV

BASEDIR=/data/k8sEnv

if [ $ERR -eq 0 ]
then
  ENV_NAME=(`basename $VIRTUAL_ENV`)
fi

KUBECONFIG=${BASEDIR}/kubeconfig/$ENV_NAME/config

if [ ! -e ${KUBECONFIG} ] && [ $ERR -eq 0 ]
then
  echo "$1 集群不存在,请检查"
  export VIRTUAL_ENV=ERROR
  ERR=1
else
  export KUBECONFIG
fi

_OLD_VIRTUAL_PATH="$PATH"
PATH="$PATH"
export PATH

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] &&  [ $ERR -eq 0 ]  ; then
    _OLD_VIRTUAL_PS1="${PS1-}"
    if [ "x" != x ] ; then
        PS1="${PS1-}"
    else
        PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}"
    fi
    export PS1
fi

if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
    hash -r 2>/dev/null
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/669062
推荐阅读
相关标签
  

闽ICP备14008679号