Skip to content

Instantly share code, notes, and snippets.

@rafi
Last active April 26, 2022 09:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rafi/6cf7be2c6c6bc829119e34a95c213188 to your computer and use it in GitHub Desktop.
Save rafi/6cf7be2c6c6bc829119e34a95c213188 to your computer and use it in GitHub Desktop.
K3s + K3d Workshop

K3S & K3D Workshop

Table of Contents

Prerequisites

  1. Docker
  2. kubectl
  3. Helm 2 (You can use Helm 3 too)
  4. K3D ≥ 3.0.0
  5. ngrok

For example, with macOS and Homebrew:

brew cask install docker
brew install k3d kubernetes-cli helm@2 ngrok

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

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

Ensure you install version ≥ 3.0.0 of K3D.

Step 0: Create Temporary Domain

We will use ngrok to create a temporary domain to proxy to our port 443:

ngrok http https://localhost

Copy/paste the temporary domain, e.g. a1b2c3d4e5f6.ngrok.io

Don't close this terminal! Once you quit ngrok, the temporary domain is purged.

Step 1: Create Cluster

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

k3d cluster create rancher \
  --k3s-server-arg "--no-deploy=traefik" \
  --api-port 6550 --servers 1 --agents 1 \
  --port 8084:80@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

helm2 init --service-account=tiller

kubectl get po -n kube-system -w
helm2 version

Step 3: Install Nginx-Ingress

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

helm2 repo update
helm2 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 Ghost Blog App

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

# Change this to your domain from the ngrok tool
export MYDOMAIN=a1b2c3d4e5f6.ngrok.io

helm2 install --name blog stable/ghost \
  --set-string ghostPassword=1234567890 \
  --set-string externalDatabase.password=1234567890 \
  --set service.type=ClusterIP \
  --set ingress.enabled=true \
  --set persistence.enabled=false

kubectl get pod -w
kubectl get pv,pvc -A

curl http://localhost:8084 -H "Host: $MYDOMAIN"

open http://"$MYDOMAIN":8084

Finally, open in browser: http://<ngrok-domain>:8084

The End

Thanks for participating!

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