From d7a65997ce5d51ca54f3cf5af3a7698ac90bb654 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 6 Apr 2016 09:10:24 -0700 Subject: [PATCH] feat(scripts): save kubeconfig --- scripts/kube-down.sh | 6 +++--- scripts/kube-up.sh | 23 ++++++++++++++++++++--- scripts/kubectl.sh | 6 +++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts/kube-down.sh b/scripts/kube-down.sh index 208b1c076..fea5c9702 100755 --- a/scripts/kube-down.sh +++ b/scripts/kube-down.sh @@ -23,9 +23,9 @@ source "${HELM_ROOT}/scripts/common.sh" source "${HELM_ROOT}/scripts/docker.sh" KUBE_PORT=${KUBE_PORT:-8080} -KUBE_HOST=${KUBE_HOST:-$DOCKER_HOST_IP} -KUBE_HOST=${KUBE_HOST:-localhost} -KUBECTL="kubectl -s ${KUBE_HOST}:${KUBE_PORT}" +KUBE_MASTER_IP=${KUBE_MASTER_IP:-$DOCKER_HOST_IP} +KUBE_MASTER_IP=${KUBE_MASTER_IP:-localhost} +KUBECTL="kubectl -s ${KUBE_MASTER_IP}:${KUBE_PORT}" delete_kube_resources() { echo "Deleting resources in kubernetes..." diff --git a/scripts/kube-up.sh b/scripts/kube-up.sh index 48f6e6e22..6977222ea 100755 --- a/scripts/kube-up.sh +++ b/scripts/kube-up.sh @@ -26,9 +26,10 @@ source "${HELM_ROOT}/scripts/docker.sh" K8S_VERSION=${K8S_VERSION:-1.2.0} KUBE_PORT=${KUBE_PORT:-8080} -KUBE_HOST=${KUBE_HOST:-$DOCKER_HOST_IP} -KUBE_HOST=${KUBE_HOST:-localhost} -KUBECTL="kubectl -s ${KUBE_HOST}:${KUBE_PORT}" +KUBE_MASTER_IP=${KUBE_MASTER_IP:-$DOCKER_HOST_IP} +KUBE_MASTER_IP=${KUBE_MASTER_IP:-localhost} +KUBECTL="kubectl -s ${KUBE_MASTER_IP}:${KUBE_PORT}" +KUBE_CONTEXT=${KUBE_CONTEXT:-docker} require_command() { if ! command -v "$1" >/dev/null 2>&1; then @@ -150,6 +151,20 @@ spec: EOF } +# Generate kubeconfig data for the created cluster. +create_kubeconfig() { + local cluster_args=( + "--server=http://${KUBE_MASTER_IP}:${KUBE_PORT}" + "--insecure-skip-tls-verify=true" + ) + + kubectl config set-cluster "${KUBE_CONTEXT}" "${cluster_args[@]}" + kubectl config set-context "${KUBE_CONTEXT}" --cluster="${KUBE_CONTEXT}" + kubectl config use-context "${KUBE_CONTEXT}" + + echo "Wrote config for ${KUBE_CONTEXT}" +} + main() { verify_prereqs @@ -159,8 +174,10 @@ main() { start_kubernetes wait_for_kubernetes + create_kube_system_namespace create_kube_dns + create_kubeconfig $KUBECTL cluster-info } diff --git a/scripts/kubectl.sh b/scripts/kubectl.sh index 0991a0bab..12ff16f59 100755 --- a/scripts/kubectl.sh +++ b/scripts/kubectl.sh @@ -21,10 +21,10 @@ source "${HELM_ROOT}/scripts/common.sh" source "${HELM_ROOT}/scripts/docker.sh" KUBE_PORT=${KUBE_PORT:-8080} -KUBE_HOST=${KUBE_HOST:-localhost} +KUBE_MASTER_IP=${KUBE_MASTER_IP:-localhost} if is_docker_machine; then - KUBE_HOST=$(docker-machine ip "$(active_docker_machine)") + KUBE_MASTER_IP=$(docker-machine ip "$(active_docker_machine)") fi -kubectl -s ${KUBE_HOST}:${KUBE_PORT} "$@" +kubectl -s ${KUBE_MASTER_IP}:${KUBE_PORT} "$@"