install_kubectl.sh
#!/bin/sh
ROOT=$(cd `dirname $0`/../&&pwd)
BIN_DIR=/usr/local/bin
# consul-template -consul-addr "$G_CONSUL:8500" -template "$ROOT/consul-tpl/kube-config.tpl:$ROOT/config/kube-config" -once
# KUBE_CONFIG_SIZE=$(stat --printf="%s" $ROOT/config/kube-config)
if [ ! -f $ROOT/config/kube-config ]; then
# 设置集群参数
kubectl config set-cluster kubernetes \
--certificate-authority=/etc/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER}
# 设置客户端认证参数
kubectl config set-credentials admin \
--client-certificate=/etc/kubernetes/ssl/admin.pem \
--embed-certs=true \
--client-key=/etc/kubernetes/ssl/admin-key.pem
# 设置上下文参数
kubectl config set-context kubernetes \
--cluster=kubernetes \
--user=admin
# 设置默认上下文
kubectl config use-context kubernetes
# eval `curl --request PUT --data-binary @/root/.kube/config http://$G_CONSUL:8500/v1/kv/k8s/config/kube-config;`
cp /root/.kube/config $ROOT/config/kube-config
else
mkdir -p /root/.kube/
cp $ROOT/config/kube-config /root/.kube/config
fi