-
Notifications
You must be signed in to change notification settings - Fork 0
/
setconf
45 lines (37 loc) · 1.03 KB
/
setconf
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
#!/bin/bash
set -e
if [ -z "$1" ]; then
ke=${KUBE_ENV^^}
else
ke=${1^^}
fi
if [ -z "$ke" ]; then
exit 0
fi
if [ -z "$2" ]; then
kn=${KUBE_NS:=default}
else
kn=$2
fi
client_cert_file_var=${ke}_KUBE_CLIENT_CERT
client_key_file_var=${ke}_KUBE_CLIENT_KEY
server_var=${ke}_KUBE_SERVER
user_var=${ke}_KUBE_USERNAME
password_var=${ke}_KUBE_PASSWORD
ca_var=${ke}_KUBE_CA
if [ -z "${!ca_var}" ]; then
tlsopt="--insecure-skip-tls-verify=true"
embed="false"
else
echo "${!ca_var}" > ca_file
tlsopt="--certificate-authority=./ca_file"
embed="true"
fi
kubectl config set-cluster ${ke} --embed-certs=false --server=${!server_var} $tlsopt --embed-certs=$embed
if [ ! -z "${!client_cert_file_var}" ]; then
kubectl config set-credentials ${ke} --client-certificate=${!client_cert_file_var} --client-key=${!client_key_file_var}
else
kubectl config set-credentials ${ke} --username=${!user_var:=admin} --password=${!password_var}
fi
kubectl config set-context ${ke} --cluster=${ke} --user=${ke} --namespace=${kn}
kubectl config use-context ${ke}