DEV Community

Lars van Erp
Lars van Erp

Posted on

Setting up Kubernetes, Rancher and auto certificates using Let's encrypt.

A quick introduction about myself

Hey there, I'm Lars, a 23-year-old software developer with a keen interest in DevOps. And let's be honest, in 2023 when you say "DevOps," you're essentially saying "Kubernetes". I'm a firm believer in the "learn by doing" approach. Stumble, fall, but remember: each misstep is a lesson in disguise.

So, here's the deal. I'm diving headfirst into Kubernetes, despite facing two key challenges:

  • Running Kubernetes locally is not rewarding enough.
  • I like to keep my monthly costs predictable.

Given these constraints, I've decided to roll out my own Kubernetes server. Spoiler alert: I'm a Kubernetes newbie. So, don't treat this guide as a perfect "How to setup Kubernetes", but rather as an open invitation to join my Kubernetes journey.

The Setup

What I'm Working With:

  • Transip's most budget-friendly Performance VPS: Check it out here
  • Ubuntu 22.04 (Pre-installed, so that's a win)

Let's Roll Up Our Sleeves

Enough chit-chat, let's get our hands dirty. Here's a rundown of the commands I threw in my terminal.😎

I decided to roll with k3s as my base. I did start with Minukube at first, since it's praised as the easiest to start with. However k3s is made by Rancher, so that is an easier combination (I guess).

Installing k3s is simple:

curl -sfL https://get.k3s.io | sh -
Enter fullscreen mode Exit fullscreen mode

Check the node's status:

sudo k3s kubectl get node
Enter fullscreen mode Exit fullscreen mode

Download kubectl (A Kubernetes command line tool)

curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
Enter fullscreen mode Exit fullscreen mode

Install kubectl

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Enter fullscreen mode Exit fullscreen mode

Verify installation by checking the version

kubectl version --client
Enter fullscreen mode Exit fullscreen mode

Copy k3s config

cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
Enter fullscreen mode Exit fullscreen mode

Install Helm (The npm of Kubernetes)

sudo snap install helm --classic
Enter fullscreen mode Exit fullscreen mode

If snap is unavailable please follow the Helm installation guide (https://helm.sh/docs/intro/install/)

Add Rancher stable repo

helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
Enter fullscreen mode Exit fullscreen mode

Create cattle-system namespace for Rancher

kubectl create namespace cattle-system
Enter fullscreen mode Exit fullscreen mode

Install Cert Manager CRDs

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.1/cert-manager.crds.yaml
Enter fullscreen mode Exit fullscreen mode

Create cert-manager namespace

kubectl create namespace cert-manager
Enter fullscreen mode Exit fullscreen mode

Add jetstack Helm repo and update

helm repo add jetstack https://charts.jetstack.io
helm repo update
Enter fullscreen mode Exit fullscreen mode

Install cert-manager

helm install cert-manager jetstack/cert-manager --namespace cert-manager --version v1.13.1
Enter fullscreen mode Exit fullscreen mode

Check cert-manager pods and wait till they are ready

kubectl get pods --namespace cert-manager
Enter fullscreen mode Exit fullscreen mode

We need to install an older version on k3s because Rancher is not able to support the latest k3s yet:

wget https://github.com/k3s-io/k3s/releases/download/v1.26.6%2Bk3s1/k3s
Enter fullscreen mode Exit fullscreen mode

Move this older version of the k3s binary

sudo cp k3s /usr/local/bin/k3s
Enter fullscreen mode Exit fullscreen mode

Restart k3s

sudo systemctl restart k3s
Enter fullscreen mode Exit fullscreen mode

Verify node status again

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

🥳 Install Rancher 🥳

Please ensure you use the correct domain and email. The domain already needs to point to the server on install. If not, the LetsEncrypt verification will fail and your server will not receive a valid ssl certificate.

helm install rancher rancher-stable/rancher 
     --namespace cattle-system 
     --set hostname=rancher.yourdomain.com
     --set bootstrapPassword=admin 
     --set ingress.tls.source=letsEncrypt 
     --set letsEncrypt.email=youremail@email.com 
     --set letsEncrypt.ingress.class=traefik
Enter fullscreen mode Exit fullscreen mode

That's it! You should now be able to visit rancher.yourdomain.com and setup the application. Please note that the default password is set as "admin" (unless you changes the bootstrapPassword in the install command).

Next up: Creating a second node and connecting it 🚀

To be continued in a new post...

Top comments (0)