install_kubectl.sh
  1. #!/bin/sh
  2. ROOT=$(cd `dirname $0`/../&&pwd)
  3. BIN_DIR=/usr/local/bin
  4. # consul-template -consul-addr "$G_CONSUL:8500" -template "$ROOT/consul-tpl/kube-config.tpl:$ROOT/config/kube-config" -once
  5. # KUBE_CONFIG_SIZE=$(stat --printf="%s" $ROOT/config/kube-config)
  6. if [ ! -f $ROOT/config/kube-config ]; then
  7. # 设置集群参数
  8. kubectl config set-cluster kubernetes \
  9. --certificate-authority=/etc/kubernetes/ssl/ca.pem \
  10. --embed-certs=true \
  11. --server=${KUBE_APISERVER}
  12. # 设置客户端认证参数
  13. kubectl config set-credentials admin \
  14. --client-certificate=/etc/kubernetes/ssl/admin.pem \
  15. --embed-certs=true \
  16. --client-key=/etc/kubernetes/ssl/admin-key.pem
  17. # 设置上下文参数
  18. kubectl config set-context kubernetes \
  19. --cluster=kubernetes \
  20. --user=admin
  21. # 设置默认上下文
  22. kubectl config use-context kubernetes
  23. # eval `curl --request PUT --data-binary @/root/.kube/config http://$G_CONSUL:8500/v1/kv/k8s/config/kube-config;`
  24. cp /root/.kube/config $ROOT/config/kube-config
  25. else
  26. mkdir -p /root/.kube/
  27. cp $ROOT/config/kube-config /root/.kube/config
  28. fi