mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
fix get-kube-local.sh
This commit is contained in:
parent
b7ab09f572
commit
a901dd3ed3
@ -23,9 +23,9 @@ set -o pipefail
|
||||
KUBE_HOST=${KUBE_HOST:-localhost}
|
||||
KUBELET_KUBECONFIG=${KUBELET_KUBECONFIG:-"/var/run/kubernetes/kubelet.kubeconfig"}
|
||||
|
||||
declare -r RED="\033[0;31m"
|
||||
declare -r GREEN="\033[0;32m"
|
||||
declare -r YELLOW="\033[0;33m"
|
||||
declare -r RED="\\033[0;31m"
|
||||
declare -r GREEN="\\033[0;32m"
|
||||
declare -r YELLOW="\\033[0;33m"
|
||||
|
||||
function echo_green {
|
||||
echo -e "${GREEN}$1"; tput sgr0
|
||||
@ -49,7 +49,7 @@ function run {
|
||||
echo_green "SUCCESS"
|
||||
else
|
||||
echo_red "FAILED"
|
||||
echo $output >&2
|
||||
echo "${output}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@ -58,13 +58,14 @@ function run {
|
||||
# Args: the IP address of the API server (e.g. "http://localhost:8080"), destination file path
|
||||
function create-kubelet-kubeconfig() {
|
||||
#local api_addr="${1}"
|
||||
local destination="${2}"
|
||||
local destination dest_dir
|
||||
destination="${2}"
|
||||
if [[ -z "${destination}" ]]; then
|
||||
echo "Must provide destination path to create Kubelet kubeconfig file!"
|
||||
exit 1
|
||||
fi
|
||||
echo "Creating Kubelet kubeconfig file"
|
||||
local dest_dir="$(dirname "${destination}")"
|
||||
dest_dir="$(dirname "${destination}")"
|
||||
mkdir -p "${dest_dir}" &>/dev/null || sudo mkdir -p "${dest_dir}"
|
||||
sudo=$(test -w "${dest_dir}" || echo "sudo -E")
|
||||
cat <<EOF | ${sudo} tee "${destination}" > /dev/null
|
||||
@ -85,7 +86,7 @@ EOF
|
||||
|
||||
function create_cluster {
|
||||
echo "Creating a local cluster:"
|
||||
echo -e -n "\tStarting kubelet..."
|
||||
echo -e -n "\\tStarting kubelet..."
|
||||
create-kubelet-kubeconfig "http://localhost:8080" "${KUBELET_KUBECONFIG}"
|
||||
run "docker run \
|
||||
--volume=/:/rootfs:ro \
|
||||
@ -102,8 +103,8 @@ function create_cluster {
|
||||
k8s.gcr.io/hyperkube-${arch}:${release} \
|
||||
/hyperkube kubelet \
|
||||
--containerized \
|
||||
--hostname-override="127.0.0.1" \
|
||||
--address="0.0.0.0" \
|
||||
--hostname-override=127.0.0.1 \
|
||||
--address=0.0.0.0 \
|
||||
--kubeconfig=${KUBELET_KUBECONFIG} \
|
||||
--pod-manifest-path=/etc/kubernetes/manifests \
|
||||
--allow-privileged=true \
|
||||
@ -113,7 +114,8 @@ function create_cluster {
|
||||
|
||||
echo -e -n "\tWaiting for master components to start..."
|
||||
while true; do
|
||||
local running_count=$(kubectl -s=http://${KUBE_HOST}:8080 get pods --no-headers --namespace=kube-system 2>/dev/null | grep "Running" | wc -l)
|
||||
local running_count
|
||||
running_count=$(kubectl "-s=http://${KUBE_HOST}:8080" get pods --no-headers --namespace=kube-system 2>/dev/null | grep -c "Running")
|
||||
# We expect to have 3 running pods - etcd, master and kube-proxy.
|
||||
if [ "$running_count" -ge 3 ]; then
|
||||
break
|
||||
@ -124,7 +126,7 @@ function create_cluster {
|
||||
echo_green "SUCCESS"
|
||||
echo_green "Cluster created!"
|
||||
echo ""
|
||||
kubectl -s http://${KUBE_HOST}:8080 clusterinfo
|
||||
kubectl -s "http://${KUBE_HOST}:8080" clusterinfo
|
||||
}
|
||||
|
||||
function get_latest_version_number {
|
||||
@ -172,7 +174,7 @@ fi
|
||||
|
||||
kubectl_url="https://storage.googleapis.com/kubernetes-release/release/${release}/bin/${platform}/${arch}/kubectl"
|
||||
|
||||
if [[ $(ls . | grep ^kubectl$ | wc -l) -lt 1 ]]; then
|
||||
if [[ ! -f ./kubectl ]]; then
|
||||
echo -n "Downloading kubectl binary..."
|
||||
if [[ $(which wget) ]]; then
|
||||
run "wget ${kubectl_url}"
|
||||
@ -195,7 +197,7 @@ create_cluster
|
||||
echo ""
|
||||
echo ""
|
||||
echo "To list the nodes in your cluster run"
|
||||
echo_yellow "\tkubectl -s=http://${KUBE_HOST}:8080 get nodes"
|
||||
echo_yellow "\\tkubectl -s=http://${KUBE_HOST}:8080 get nodes"
|
||||
echo ""
|
||||
echo "To run your first pod run"
|
||||
echo_yellow "\tkubectl -s http://${KUBE_HOST}:8080 run nginx --image=nginx --port=80"
|
||||
echo_yellow "\\tkubectl -s http://${KUBE_HOST}:8080 run nginx --image=nginx --port=80"
|
||||
|
Loading…
Reference in New Issue
Block a user