bash
mkdir -p /data/k8sEnv/{kubeconfig,venv}
echo "alias ak8s='cd /data/k8sEnv/kubeconfig && source /data/k8sEnv/venv/k8sEnv'" >> /etc/profile
source /etc/profile
bash
# /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