#!/bin/bash set -euo pipefail # # Helper functions # declare -i term_width=80 h1() { declare border padding text border='\e[1;34m'"$(printf '=%.0s' $(seq 1 "$term_width"))"'\e[0m' padding="$(printf ' %.0s' $(seq 1 $(((term_width - $(wc -m <<<"$*")) / 2))))" text="\\e[1m$*\\e[0m" echo -e "$border" echo -e "${padding}${text}${padding}" echo -e "$border" } h2() { printf '\e[1;33m==>\e[37;1m %s\e[0m\n' "$*" } rke2_channel="$1"; shift rke2_version="$1"; shift rke2_server_url="$1"; shift ip_address="$1"; shift cat >/etc/motd <<'EOF' _ ____ _ _ __| | _____|___ \ __ _ __ _ ___ _ __ | |_ | '__| |/ / _ \ __) | / _` |/ _` |/ _ \ '_ \| __| | | | < __// __/ | (_| | (_| | __/ | | | |_ |_| |_|\_\___|_____(_)__,_|\__, |\___|_| |_|\__| |___/ EOF h1 "Install rke2 agent" h2 "Version: ${rke2_version}" h2 "Server: ${rke2_server_url}" # install rke2 agent. # see https://docs.rke2.io/install/install_options/install_options/ # see https://docs.rke2.io/install/install_options/linux_agent_config/ install -d -m 700 /etc/rancher/rke2 install /dev/null -m 600 /etc/rancher/rke2/config.yaml cat >>/etc/rancher/rke2/config.yaml </etc/profile.d/01-rke2.sh <<'EOF' export CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock export CONTAINERD_NAMESPACE=k8s.io export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml EOF source /etc/profile.d/01-rke2.sh # NB do not try to use kubectl on a agent node, as kubectl does not work on a # agent node without a proper kubectl configuration (which you could copy # from the server, but we do not do it here). # install the bash completion scripts. h2 "Bash configure" crictl completion bash >/usr/share/bash-completion/completions/crictl kubectl completion bash >/usr/share/bash-completion/completions/kubectl # list runnnig pods. crictl pods # list running containers. crictl ps ctr containers ls # show listening ports. ss -n --tcp --listening --processes # show network routes. ip route # show memory info. free # show versions. crictl version ctr version