Skip to content
Kubernetes

Kubernetes

Kubernetes is a container orchestration system created by Google.
Just as there are multiple Linux distributions, there are multiple Kubernetes distributions.
K3s is a lightweight Kubernetes distribution created by Rancher.

All these projects are now managed by the Cloud Native Computing Foundation.

Tooling Installation

k3sup is a command-line tool for deploying a K3s cluster on one or more machines.
We will install it with pkgx.
~/tp $ yq -i e '.dependencies["github.com/alexellis/k3sup"]="^0.13.1"' pkgx.yaml
~/tp $ yq '.dependencies["github.com/alexellis/k3sup"]' pkgx.yaml
^0.13.1

Deploying a k3s cluster

~/tp $ cat <<'EOS' > deploy-k3s.bash
#!/bin/bash

declare -r BOOTSTRAP_IP="$(terraform output -raw bootstrap_ip)"
declare -r BOOTSTRAP_USER="$(terraform output -raw bootstrap_user)"
declare -a COMPUTE_IP=($(terraform output -json | jq -j '.compute_ip.value|join(" ")'))
declare -a COMPUTE_USER=($(terraform output -json | jq -j '.compute_user.value|join(" ")'))

k3sup install \
    --cluster \
    --host "${BOOTSTRAP_IP}" \
    --user "${BOOTSTRAP_USER}" \
    --k3s-channel stable

ssh -l ${BOOTSTRAP_USER} ${BOOTSTRAP_IP} <<'EOF'
curl -fsS https://pkgx.sh |sh
eval "$(pkgx integrate)"

mkdir -p work
cat <<EOT > work/pkgx.yaml
dependencies:
  jq: ^1.7
  helm.sh: ^3.12.3
  k9s: ^0.27.4
  gnu.org/coreutils: ^9.4.0
EOT
cd work
dev
EOF

for i in ${!COMPUTE_IP[@]}; do \
    k3sup join \
        --server-host "${BOOTSTRAP_IP}" \
        --server-user "${BOOTSTRAP_USER}" \
        --host "${COMPUTE_IP[$i]}" \
        --user "${COMPUTE_USER[$i]}" \
        --k3s-channel stable
done
EOS
~/tp $ bash deploy-k3s.bash