Skip to content

Instantly share code, notes, and snippets.

@felipemeamaral
Last active September 30, 2023 05:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipemeamaral/569168e0c8939d39c25df3311fcc52d6 to your computer and use it in GitHub Desktop.
Save felipemeamaral/569168e0c8939d39c25df3311fcc52d6 to your computer and use it in GitHub Desktop.
Install Rancher 2.5.x on k3d using k3s on macOS

Rancher Workshop

Prerequisites

  1. Docker
  2. kubectl
  3. Helm 2
  4. K3D ≥ 3.0.0

For example, with macOS and Homebrew:

# Install tools
brew cask install docker
brew install k3d kubernetes-cli helm@2

# You have to add helm@2 to PATH, or symlink helm@2, for example:
ln -s /usr/local/opt/helm@2/bin/helm /usr/local/bin/helm

Or using Debian/Ubuntu/Mint:

# Install tools
sudo apt-get install -y docker.io kubernetes-cli
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
curl -L https://git.io/get_helm.sh | bash

# You have to add helm@2 to PATH, or symlink helm@2, for example:
ln -s /usr/local/opt/helm@2/bin/helm /usr/local/bin/helm

For other platforms, see https://github.com/rancher/k3d

Ensure you install version ≥ 3.0.0 of K3D.

Install

Step 0: Create Temporary Domain

We will use generate a variable to hold the domain name:

export $MYDOMAIN=rancher.localhost

Step 1: Install Kubernetes

We'll use k3d to create a quick Kubernetes installation.

k3d cluster create rancher \
  --k3s-server-arg "--no-deploy=traefik@server:*" \
  --api-port 6550 --servers 1 --agents 1 \
  --port 80:80@loadbalancer --port 443:443@loadbalancer \
  --wait

kubectl cluster-info

kubectl get node          # or kubectl get no
kubectl get storageclass  # or kubectl get sc
kubectl get namespace     # or kubectl get ns
kubectl get pod -A
kubectl get svc -A

Step 2: Install Helm 2 Tiller (Skip for Helm 3)

Let's install Helm 2 tiller.

kubectl -n kube-system create serviceaccount tiller

kubectl create clusterrolebinding tiller \
  --clusterrole=cluster-admin \
  --serviceaccount=kube-system:tiller

helm init --service-account=tiller

# Wait for tiller to be ready
kubectl -n kube-system rollout status deploy/tiller-deploy

# You can also watch pods state changes
kubectl get po -n kube-system -w

helm version

Step 3: Install Nginx-Ingress

Instead of Traefik, let's use nginx-ingress controller.

helm repo update
helm install --name nginx-ingress stable/nginx-ingress \
  --version 1.33.0 --set-string controller.config.ssl-redirect=false

# Wait for nginx-ingress to be ready
kubectl rollout status deploy/nginx-ingress-controller

# This should respond with 404 from default backend!
curl http://localhost

If our nginx-ingress controller is working correctly, you should see a 404 not found message, because we haven't installed anything.

Step 4: Install cert-manager

We'll need to install cert-manager for our Rancher installation.

helm repo add jetstack https://charts.jetstack.io
helm repo update
kubectl create namespace cert-manager
kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.2/cert-manager.crds.yaml
helm install \
  --name cert-manager \
  --namespace cert-manager \
  --version v0.15.2 \
  jetstack/cert-manager

Step 5: Install Rancher

Finally, let's install latest rancher. Don't forget to change MYDOMAIN!

helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
helm repo update

kubectl create namespace cattle-system
helm install --name rancher rancher-latest/rancher \
  --namespace cattle-system \
  --set hostname="$MYDOMAIN" \
  --set replicas=1 \
  --wait

# Wait for rancher to start
kubectl -n cattle-system rollout status deploy/rancher

Step 6: Login to Rancher

That's it, open up a browser and start exploring Rancher.

open https://$MYDOMAIN/

The End

Thanks for participating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment