Skip to content

Instantly share code, notes, and snippets.

@mak3r
Last active October 7, 2022 14:19
Show Gist options
  • Save mak3r/5e53406d303f46aa3c31af1cc792fe42 to your computer and use it in GitHub Desktop.
Save mak3r/5e53406d303f46aa3c31af1cc792fe42 to your computer and use it in GitHub Desktop.
k3s-basic-config

Install a standard k3s configuration

  • Run the command below to install a standard k3s configuration into the /etc/rancher/k3s directory.
  • This will set the kubeconfig permissions bits and setup to overwrite the install users ~/.kube/config file with the k3s kubeconfig
  • The user executing the script must have sudo privileges

Usage

  1. Install the config file
    • curl -sfL https://gist.github.com/mak3r/5e53406d303f46aa3c31af1cc792fe42/raw/install-k3s-config.sh | sh -
  2. Install k3s or restart k3s
    • Install
    • curl -sfL https://get.k3s.io | sh -
    • Restart
    • systemctl restart k3s
  3. Change the owner of the kubeconfig
    • sudo chown $(whoami):$(id -gn $(whoami)) ~/.kube/config
write-kubeconfig: "/home/{USER}/.kube/config"
write-kubeconfig-mode: "0600"
tls-san:
- "{HOSTNAME}"
- "{IP}"
#!/bin/sh
sudo mkdir -p /etc/rancher/k3s
USER=$(whoami)
HOSTNAME=$(hostname)
IP=$(hostname -i | cut -d " " -f 2)
curl -sfL https://gist.github.com/mak3r/5e53406d303f46aa3c31af1cc792fe42/raw/config.yaml | sed "s/{USER}/$USER/g" | sed "s/{HOSTNAME}/$HOSTNAME/g" | sed "s/{IP}/$IP/g" > config.yaml
sudo mv config.yaml /etc/rancher/k3s/config.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment