Installing script for k3s nodes
This commit is contained in:
96
scripts/k3s-install.sh
Executable file
96
scripts/k3s-install.sh
Executable file
@@ -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 <action> [args]
|
||||
actions:
|
||||
token
|
||||
server
|
||||
agent <server-url> <node-token>
|
||||
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
|
||||
Reference in New Issue
Block a user