#!/usr/bin/env bash # Installs or upgrades kubectl on Linux # Chuck for root privileges if [[ "$EUID" != "0" ]] ; then echo "Please execute script with sudo or as root." exit 1 fi # Check Dependencies if ! curl --version &>/dev/null; then echo "curl must be installed and in \$PATH" exit 1 fi INSTALLED_KUBECTL_PATH=$(which kubectl 2>/dev/null || echo NONE) INSTALLED_KUBECTL_VERSION="$($INSTALLED_KUBECTL version --client --short | cut -f3 -d' ')" LATEST_KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) if [ $INSTALLED_KUBECTL_VERSION != $LATEST_KUBECTL_VERSION ] ; then curl -#LO "https://storage.googleapis.com/kubernetes-release/release/${LATEST_KUBECTL_VERSION}/bin/linux/amd64/kubectl" \ && chmod ug+x ./kubectl if [ -x ./kubectl ] ; then DOWNLOADED_KUBECTL_VERSION="$(./kubectl version --client --short | cut -f3 -d' ')" fi else echo "The latest version is already installed." fi if [ $DOWNLOADED_KUBECTL_VERSION != $LATEST_KUBECTL_VERSION ] ; then echo "ERROR: Something went wrong with the download." else mv ./kubectl $INSTALLED_KUBECTL_PATH echo "Installation and/or upgrade complete." fi # EOF