Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make local clusters work painlessly with kubeconfig #4401

Merged
merged 1 commit into from
Feb 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions cluster/kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ if [[ "$KUBERNETES_PROVIDER" == "gke" ]]; then
detect-project &> /dev/null
export PATH=$(get_absolute_dirname $kubectl):$PATH
kubectl="${GCLOUD}"
fi

if [[ "$KUBERNETES_PROVIDER" == "vagrant" ]]; then
# When we are using vagrant it has hard coded auth. We repeat that here so that
# we don't clobber auth that might be used for a publicly facing cluster.
config=(
"--auth-path=$HOME/.kubernetes_vagrant_auth"
)
elif [[ "${KUBERNETES_PROVIDER}" == "gke" ]]; then
# GKE runs kubectl through gcloud.
config=(
"preview"
Expand All @@ -121,12 +112,15 @@ elif [[ "${KUBERNETES_PROVIDER}" == "gke" ]]; then
"--zone=${ZONE}"
"--cluster=${CLUSTER_NAME}"
)
elif [[ "$KUBERNETES_PROVIDER" == "vagrant" ]]; then
# When we are using vagrant it has hard coded auth. We repeat that here so that
# we don't clobber auth that might be used for a publicly facing cluster.
config=(
"--auth-path=$HOME/.kubernetes_vagrant_auth"
)
fi

detect-master > /dev/null
if [[ -n "${KUBE_MASTER_IP-}" && -z "${KUBERNETES_MASTER-}" ]]; then
export KUBERNETES_MASTER=https://${KUBE_MASTER_IP}
fi
echo "current-context: \"$(${kubectl} config view -o template --template='{{index . "current-context"}}')\""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output is an empty string if the user has no current-context. Still,

current-context: 

is potentially ambiguous output, so changed to enclose the current-context in quotes. Output is now

// if user has current-context=my-context
current-context: "my-context"

// if user has empty current-context
current-context: ""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that if "." is nil you can't index it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think dot ever can be nil, unless kubectl is very, very broken. Even if no kubeconfig file exists, it still creates an internal clientconfig, which is dot refers to.


echo "Running:" "${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}" >&2
"${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}"
19 changes: 0 additions & 19 deletions cluster/local/util.sh

This file was deleted.

7 changes: 2 additions & 5 deletions docs/getting-started-guides/locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ hack/local-up-cluster.sh
This will build and start a lightweight local cluster, consisting of a master
and a single minion. Type Control-C to shut it down.

You can use the cluster/kubectl.sh script to interact with the local cluster.
You must set the KUBERNETES_PROVIDER environment variable.
You can use the cluster/kubectl.sh script to interact with the local cluster. hack/local-up-cluster.sh will
print the commands to run to point kubectl at the local cluster.

```
export KUBERNETES_PROVIDER=local
```

### Running a container

Expand Down
5 changes: 4 additions & 1 deletion hack/local-up-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ cleanup()

[[ -n "${ETCD_PID-}" ]] && kill "${ETCD_PID}"
[[ -n "${ETCD_DIR-}" ]] && rm -rf "${ETCD_DIR}"

exit 0
}

Expand Down Expand Up @@ -160,7 +161,9 @@ Logs:

To start using your cluster, open up another terminal/tab and run:

export KUBERNETES_PROVIDER=local
cluster/kubectl.sh config set-cluster local --server=http://${API_HOST}:${API_PORT} --insecure-skip-tls-verify=true --global
cluster/kubectl.sh config set-context local --cluster=local --global
cluster/kubectl.sh config use-context local
cluster/kubectl.sh
EOF

Expand Down