Home K3S & Rancher Installation Script
Post
Cancel

K3S & Rancher Installation Script

Why K3S and Rancher?

K3s is a lightweight, certified Kubernetes distribution designed for production workloads in resource-constrained environments such as edge, IoT, and ARM-based systems. It was developed by Rancher Labs, a software company that provides open-source tools and solutions for managing and deploying containers and Kubernetes.

Rancher is a complete software stack for teams adopting containers. It addresses the operational and security challenges of managing multiple Kubernetes clusters, while providing DevOps teams with integrated tools for running containerized workloads. Rancher provides centralized management, monitoring, and alerting for multiple clusters, regardless of where they are located, and it includes a rich set of features for automating the deployment and scaling of containerized applications.

K3s is a popular Kubernetes distribution that is often used with Rancher, as Rancher provides an easy-to-use interface for managing K3s clusters. Together, K3s and Rancher provide a lightweight and powerful solution for deploying and managing containerized workloads at scale.

Rancher support matrix

The Rancher support matrix is a table that lists the versions of Kubernetes, Rancher, and other components that are compatible with each other. It is used to help users determine which versions of Rancher and Kubernetes they should use together, and which versions of other components are compatible with those versions.

The matrix is divided into three sections:

Rancher Server Support Matrix: This section lists the versions of Rancher that are compatible with each version of Kubernetes. It also lists the versions of Docker, Helm, and Istio that are supported with each version of Rancher.

Kubernetes Version Support Matrix: This section lists the versions of Kubernetes that are compatible with each version of Rancher. It also lists the versions of etcd, Calico, and other components that are supported with each version of Kubernetes.

Rancher Kubernetes Engine (RKE) Support Matrix: This section lists the versions of RKE that are compatible with each version of Kubernetes. It also lists the versions of Docker, etcd, and other components that are supported with each version of RKE.

The Rancher support matrix is regularly updated to reflect the latest versions and compatibility information. It is important to consult the matrix before deploying Rancher and Kubernetes, to ensure that you are using compatible versions of all components.

Full script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

# Set K3S_VERSION to the desired version
K3S_VERSION=v1.21.3+k3s1

# Install K3S
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${K3S_VERSION} sh -

# Wait for K3S to start up
sleep 5

# Get the K3S cluster token and server URL
K3S_TOKEN=$(sudo cat /var/lib/rancher/k3s/server/node-token)
K3S_EMAIL="webadmin@example.com"
RANCHER_HOSTNAME="rancher.example.com"

# Install Helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

# Add Rancher repository

sudo helm repo add rancher-stable https://releases.rancher.com/server-charts/stable

# Create a namespace for Rancher
sudo kubectl create namespace cattle-system

################################################################

# Only need these steps if you want to use LetsEncrypt

# If you have installed the CRDs manually instead of with the `--set installCRDs=true` option added to your Helm install command, you should upgrade your CRD resources before upgrading the Helm chart:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.crds.yaml

# Add the Jetstack Helm repository
helm repo add jetstack https://charts.jetstack.io

# Update your local Helm chart repository cache
helm repo update

# Install the cert-manager Helm chart
helm install cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --create-namespace \
  --version v1.11.0

################################################################

# Install Rancher using certificate from files

helm install rancher rancher-stable/rancher \
  --namespace cattle-system \
  --set hostname=${RANCHER_HOSTNAME} \
  --set ingress.tls.source=secret
kubectl -n cattle-system create secret tls tls-rancher-ingress \
  --cert=tls.crt \
  --key=tls.key

# Install Rancher using external SSL certificate
sudo helm install rancher rancher-stable/rancher \
  --namespace cattle-system \
  --set hostname=${RANCHER_HOSTNAME} \
  --set ingress.tls.source=letsEncrypt \
  --set letsEncrypt.email=${K3S_EMAIL} \
  --set tls=external
This post is licensed under CC BY 4.0 by the author.