-
Notifications
You must be signed in to change notification settings - Fork 120
/
init-kubectl.sh
60 lines (50 loc) · 1.62 KB
/
init-kubectl.sh
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
#!/bin/bash
set -e
if [ "${WELCOME_BANNER}" ]; then
echo ${WELCOME_BANNER}
fi
arg1=$1
arg2=$2
mkdir -p /nonexistent
mount -t tmpfs -o size=${SESSION_STORAGE_SIZE} tmpfs /nonexistent
cd /nonexistent
cp /root/.bashrc ./
cp /etc/vim/vimrc.local .vimrc
echo 'source /opt/kubectl-aliases/.kubectl_aliases' >> .bashrc
echo -e 'PS1="> "\nalias ll="ls -la"' >> .bashrc
mkdir -p .kube
export HOME=/nonexistent
if [ -z "${arg2}" ]; then
echo $arg1| base64 -d > .kube/config
else
echo `kubectl config set-credentials webkubectl-user --token=${arg2}` > /dev/null 2>&1
echo `kubectl config set-cluster kubernetes --server=${arg1}` > /dev/null 2>&1
echo `kubectl config set-context kubernetes --cluster=kubernetes --user=webkubectl-user` > /dev/null 2>&1
echo `kubectl config use-context kubernetes` > /dev/null 2>&1
fi
if [ ${KUBECTL_INSECURE_SKIP_TLS_VERIFY} == "true" ];then
{
clusters=`kubectl config get-clusters | tail -n +2`
for s in ${clusters[@]}; do
{
echo `kubectl config set-cluster ${s} --insecure-skip-tls-verify=true` > /dev/null 2>&1
echo `kubectl config unset clusters.${s}.certificate-authority-data` > /dev/null 2>&1
} || {
echo err > /dev/null 2>&1
}
done
} || {
echo err > /dev/null 2>&1
}
fi
chown -R nobody:nogroup .kube
export TMPDIR=/nonexistent
envs=`env`
for env in ${envs[@]}; do
if [[ $env == GOTTY* ]];
then
unset ${env%%=*}
fi
done
unset WELCOME_BANNER PPROF_ENABLED KUBECTL_INSECURE_SKIP_TLS_VERIFY SESSION_STORAGE_SIZE KUBECTL_VERSION
exec su -s /bin/bash nobody