From 3318182ad1698e1e30e610ce717825a821c3fb19 Mon Sep 17 00:00:00 2001 From: sakshisharma84 Date: Fri, 31 May 2024 17:05:58 -0400 Subject: [PATCH] [BOP-643] Installation script (#19) --- content/docs/setup/README.md | 75 +++++++++++++++++++++ content/docs/setup/install.sh | 122 ++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100755 content/docs/setup/install.sh diff --git a/content/docs/setup/README.md b/content/docs/setup/README.md index 60920c7..9598605 100644 --- a/content/docs/setup/README.md +++ b/content/docs/setup/README.md @@ -8,3 +8,78 @@ However, as of commit `e19af33`, it still requires the following tools to be ins - `kubectl` of version `1.29.0` or above ([download](https://kubernetes.io/docs/tasks/tools/#kubectl)) - `k0sctl` of version `0.17.0` or above ([download](https://github.com/k0sproject/k0sctl/releases)) + +# Installation via script + +You can use the [installation script](./install.sh) to install the following dependencies. +- mkectl (default version: v4.0.0-alpha.0.3) +- k0sctl (default version: 0.17.8) +- kubectl (default version: v1.30.0) + +To override the default versions, you can pass the variables `K0SCTL_VERSION`,`MKECTL_VERSION`and `KUBECTL_VERSION`. + +> P.S. The script detects if kubectl is already installed in the system. If so, it will not overwrite it. + +### Usage + +1. Install the dependencies using the following command. + + ```shell + sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Mirantis/mke-docs/main/content/docs/setup/install.sh)" + ``` + +2. The script is designed to detect the os and the underlying architecture. Based on this, it shall install the appropriate binaries `k0sctl`, `kubectl` and `mkectl` in `/usr/local/bin`. + > Note: Make sure /usr/local/bin is in your PATH environment variable. + +3. Confirm successful installations by running + + a. _mkectl version command_ + + ```shell + mkectl version + ``` + Output: + ```shell + Version: v4.0.0-alpha.0.3 + ``` + b. _k0sctl version command_ + ```shell + k0sctl version + ``` + Output: + ```shell + version: v0.17.8 + commit: b061291 + ``` + c. _kubectl version command_ + ```shell + kubectl version + ``` + Output: + ```shell + Client Version: v1.30.0 + Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 + Server Version: v1.29.3+k0s + ``` + +### Debug mode +To turn the debug mode on, run +```shell +sudo DEBUG=true /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/Mirantis/mke-docs/main/content/docs/setup/install.sh)" +``` + +### Install different version +To install non-default versions of mkectl, kubectl and k0sctl, you can use `MKECTL_VERSION`, `KUBECTL_VERSION` and `K0SCTL_VERSION` respectively. + +Example usage: +```shell +sudo K0SCTL_VERSION=0.17.4 /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/Mirantis/mke-docs/main/content/docs/setup/install.sh)" +``` + +This shall install k0sctl version 0.17.4. +```shell +k0sctl version + +version: v0.17.4 +commit: 372a589 +``` diff --git a/content/docs/setup/install.sh b/content/docs/setup/install.sh new file mode 100755 index 0000000..9148be8 --- /dev/null +++ b/content/docs/setup/install.sh @@ -0,0 +1,122 @@ +#!/bin/sh +set -e + +PATH=$PATH:/usr/local/bin + +if [ -n "${DEBUG}" ]; then + set -x +fi + +detect_uname() { + os="$(uname)" + case "$os" in + Linux) echo "linux" ;; + Darwin) echo "darwin" ;; + *) echo "Unsupported operating system: $os" 1>&2; return 1 ;; + esac + unset os +} + +detect_arch() { + arch="$(uname -m)" + case "$arch" in + amd64|x86_64) echo "x64" ;; + arm64|aarch64) echo "arm64" ;; + armv7l|armv8l|arm) echo "arm" ;; + *) echo "Unsupported processor architecture: $arch" 1>&2; return 1 ;; + esac + unset arch +} + +# download_k0sctl_url() fetches the k0sctl download url. +download_k0sctl_url() { + echo "https://github.com/k0sproject/k0sctl/releases/download/v$K0SCTL_VERSION/k0sctl-$uname-$arch" +} + +# download_kubectl_url() fetches the kubectl download url. +download_kubectl_url() { + if [ "$arch" = "x64" ]; + then + arch=amd64 + fi + echo "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${uname}/${arch}/kubectl" +} + +install_kubectl() { + if [ -z "${KUBECTL_VERSION}" ]; then + echo "Using default kubectl version v1.30.0" + KUBECTL_VERSION=v1.30.0 + fi + kubectlDownloadUrl="$(download_kubectl_url)" + echo "Downloading kubectl from URL: $kubectlDownloadUrl" + curl -sSLf "$kubectlDownloadUrl" >$installPath/$kubectlBinary + sudo chmod 755 "$installPath/$kubectlBinary" + echo "kubectl is now executable in $installPath" +} + +# download_mkectl downloads the mkectl binary. +download_mkectl() { + if [ "$arch" = "x64" ] || [ "$arch" = "amd64" ]; + then + arch=x86_64 + fi + curl --silent -L -s https://s3.us-east-2.amazonaws.com/packages-stage-mirantis.com/${MKECTL_VERSION}/mkectl_${uname}_${arch}.tar.gz | tar -xvzf - -C $installPath + echo "mkectl is now executable in $installPath" +} + +main() { + + uname="$(detect_uname)" + arch="$(detect_arch)" + + printf "\n\n" + + echo "Step 1/3 : Install k0sctl" + echo "#########################" + + if [ -z "${K0SCTL_VERSION}" ]; then + echo "Using default k0sctl version 0.17.8" + K0SCTL_VERSION=0.17.8 + fi + + k0sctlBinary=k0sctl + installPath=/usr/local/bin + k0sctlDownloadUrl="$(download_k0sctl_url)" + + + echo "Downloading k0sctl from URL: $k0sctlDownloadUrl" + curl -sSLf "$k0sctlDownloadUrl" >"$installPath/$k0sctlBinary" + + sudo chmod 755 "$installPath/$k0sctlBinary" + echo "k0sctl is now executable in $installPath" + + printf "\n\n" + echo "Step 2/3 : Install kubectl" + echo "#########################" + + kubectlBinary=kubectl + + if [ -x "$(command -v "$kubectlBinary")" ]; then + VERSION="$($kubectlBinary version | grep Client | cut -d: -f2)" + echo "$kubectlBinary version $VERSION already exists." + else + install_kubectl + fi + + printf "\n\n" + echo "Step 3/3 : Install mkectl" + echo "#########################" + + if [ -z "${MKECTL_VERSION}" ]; then + echo "Using default mkectl version v4.0.0-alpha.0.3" + MKECTL_VERSION=v4.0.0-alpha.0.3 + fi + printf "\n" + + + echo "Downloading mkectl" + download_mkectl + +} + +main "$@" \ No newline at end of file