108 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/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 NFS libs"
 | |
| apt-get install -y nfs-common
 | |
| 
 | |
| 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 <<EOF
 | |
| server: $rke2_server_url
 | |
| token: $(cat /vagrant/tmp/node-token)
 | |
| node-ip: $ip_address
 | |
| EOF
 | |
| curl -sfL https://raw.githubusercontent.com/rancher/rke2/$rke2_version/install.sh \
 | |
|   | \
 | |
|     INSTALL_RKE2_CHANNEL="$rke2_channel" \
 | |
|     INSTALL_RKE2_VERSION="$rke2_version" \
 | |
|     INSTALL_RKE2_TYPE="agent" \
 | |
|     sh -
 | |
| 
 | |
| h2 "Start rke2 agent service" 
 | |
| systemctl cat rke2-agent
 | |
| systemctl enable rke2-agent.service
 | |
| systemctl start rke2-agent.service
 | |
| 
 | |
| 
 | |
| h2 "Configure system path for rke2"
 | |
| # symlink the utilities and setup the environment variables to use them.
 | |
| # NB kubectl should not be available in worker nodes as rke2 does not
 | |
| #    install a kubeconfig.
 | |
| ln -fs /var/lib/rancher/rke2/bin/{kubectl,crictl,ctr} /usr/local/bin/
 | |
| cat >/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
 |