From d0b87c96dfdeb6f9d1d05250e1098235412c8fcc Mon Sep 17 00:00:00 2001 From: lachtan Date: Sat, 6 Nov 2021 11:38:14 +0100 Subject: [PATCH] Installing script for k3s nodes --- scripts/k3s-install.sh | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 scripts/k3s-install.sh diff --git a/scripts/k3s-install.sh b/scripts/k3s-install.sh new file mode 100755 index 0000000..29a84fa --- /dev/null +++ b/scripts/k3s-install.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +set -E -o errexit -o nounset -o pipefail + +readonly SOURCE=${BASH_SOURCE:-k3s-install} +readonly SCRIPT_NAME=$(basename "$SOURCE") +readonly ERROR_CODE=90 + +function print_help() { + cat <<-EOT +use: $SCRIPT_NAME [args] +actions: + token + server + agent + status server|agent + config + help +EOT + exit $ERROR_CODE +} + +function read_token() { + cat /var/lib/rancher/k3s/server/node-token +} + +function install_server() { + curl -sfL https://get.k3s.io | sh - +} + +function install_agent() { + curl -sfL https://get.k3s.io | K3S_URL="$1" K3S_TOKEN="$2" sh - +} + +function status_server() { + systemctl status k3s +} + +function status() { + case $1 in + server) + systemctl status k3s + ;; + agent) + systemctl status k3s-agent + ;; + *) + echo "Unknown k3s type: $1" + exit $ERROR_CODE + ;; + esac +} + +function show_config_path() { + echo "/etc/rancher/k3s/k3s.yaml" +} + +if [ "$#" == "0" ]; then + print_help +fi + +action=$1 +shift + +case "$action" in + -h|--help|help) + print_help + ;; + + token) + read_token + ;; + + server) + install_server + ;; + + agent) + k3s_url="$1" + k3s_token="$2" + install_agent "$k3s_url" "$k3s_token" + ;; + + status) + status $1 + ;; + + config) + show_config_path + ;; + + *) + echo "Unknown action: $action" + exit $ERROR_CODE + ;; +esac