Skip to content

Instantly share code, notes, and snippets.

@mak3r
Last active April 11, 2022 16:03
Show Gist options
  • Save mak3r/61fa4b9bb0cb85b055b24573638db5ca to your computer and use it in GitHub Desktop.
Save mak3r/61fa4b9bb0cb85b055b24573638db5ca to your computer and use it in GitHub Desktop.
Process notes for k3s online training

Prep

  1. Generate a list of instances
  • sbin/generate-instance-list.sh -n mak3r-rancher-training-k3s > instance-ids.json
  • use a script to connect to those instances by list id
    • sbin/ssh-connect.sh -i 0 -k ~/.ssh/mak3r-private.pem -s
  1. Get the cloud server public IP address and replace throughout the script
  2. Prepare a local RPi server

Install and upgrade

Login

/Users/markabrams/dev/k3s-training/sbin/ssh-connect.sh -i 2 -k ~/.ssh/mak3r-private.pem -s

Demo install of k3s v0.3.0 (k8s version 1.13)

  • curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v0.3.0 sh -
  • kubectl version
  • k3s --version

Demo upgrade of k3s to latest (k8s version 1.14)

  • curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v0.7.0-rc4 sh -
  • kubectl version
  • curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v0.7.0-rc4 INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -
  • kubectl version
  • k3s --version

Demo upgrade to latest k3s

  • curl -sfL https://get.k3s.io | sh -
  • kubectl version
  • k3s --version

Demo uninstall

sudo /usr/local/bin/k3s-uninstall.sh


Multi-node clusters

Install server only

Login to the server (aws)

  1. /Users/markabrams/dev/k3s-training/sbin/ssh-connect.sh -i 2 -k ~/.ssh/mak3r-private.pem -s
  2. curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable-agent --write-kubeconfig-mode 644 --tls-san 54.196.155.129" sh -
  3. echo "export node_token=$(sudo cat /var/lib/rancher/k3s/server/node-token)"
  • copy the output of the prior command

Setup the agents

  • X86
    1. /Users/markabrams/dev/k3s-training/sbin/ssh-connect.sh -i 3 -k ~/.ssh/mak3r-private.pem -s
    2. curl -L -o k3s https://github.com/rancher/k3s/releases/download/v0.6.1/k3s
    3. chmod 755 k3s && sudo mv k3s /usr/local/bin/k3s
    4. Paste output of export node_token ... command
    5. sudo /usr/local/bin/k3s agent --server https://54.196.155.129:6443 --token "$node_token" >& k3s-agent.log &
  • ARM
    1. /Users/markabrams/dev/k3s-training/sbin/ssh-connect.sh -i 0 -k ~/.ssh/mak3r-private.pem -s
    2. curl -L -o k3s https://github.com/rancher/k3s/releases/download/v0.6.1/k3s-arm64
    3. chmod 755 k3s && sudo mv k3s /usr/local/bin/k3s
    4. Paste output of export node_token ... command
    5. sudo /usr/local/bin/k3s agent --server https://54.196.155.129:6443 --token "$node_token" >& k3s-agent.log &

k3s on ARM

local node ARM

Login to the local node (RPi)

  • ssh pi@k3s-calf.local

Install scripted

  1. curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -
  2. htop

Deployments

Create a deployment

  1. vi nginx.yaml
  2. kubectl apply -f nginx.yaml
  3. kubectl get pods --all-namespaces
  4. kubectl delete -f nginx.yaml

Demo manifests

  1. vi nginx.yaml
  2. sudo cp nginx.yaml /var/lib/rancher/k3s/server/manifests/.

k3d

  • k3d create --name cluster01 --workers 3
  1. KUBECONFIG="$(k3d get-kubeconfig --name='cluster01')"; kubectl get node
  2. k3d delete -a

k3os

VBox gist

  1. packer build k3os.json
  2. vagrant up
  3. vagrant ssh

Create clusters in Rancher

Use the UI to create the first cluster

  • Retrieve the cluster kubectl command. Run it in the first cluster

Use the CLI to create additional clusters

  1. rancher cluster create --import k3s01
  2. rancher cluster import -q k3s01
  • run output in the cluster to be imported

Cleanup

Cleanup of binary download types

  1. sudo ps aux | grep k3s | awk '{print $2}' | sudo xargs kill
  2. sudo rm /usr/local/bin/k3s

Cleanup of systemd scripted types

  1. sudo /usr/local/bin/k3s-uninstall.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment