In my previous post, I shared my my experiences with k3s. Today I will show how easy it is to set up and host a simple static web page.
Prerequisites
You will need a server (or your computer) and a DNS domain name. For my playground, I used OVH Public Cloud instance -
D2-2 with Debian 11, and *.k3s.domain.com
domain name.
Install k3s
Installing k3s is very simple. Just execute curl -sfL https://get.k3s.io | sh -
(although, I am not a fan of this
method, as it’s best to download the script and take a look at it first). After executing the command, wait for 1-2
minutes for the cluster to be ready. You can check its status by executing command below. If it does not throw any
errors - everything is OK.
|
|
Exposing the website with Traefik ingress
If you are familiar with k8s, then there is nothing fancy going on here ;) We need a deployment with definition of containers, service and ingress.
First, create a namespace: k3s kubectl create namespace pages
Create a deployment with a simple nginx
container and default page, use k3s kubectl apply -f deployment.yml
:
|
|
Define a service that exposes the nginx port internally, use k3s kubectl apply -f service.yml
:
|
|
Ingress configuration, use k3s kubectl apply -f ingress.yml
:
|
|
After creating all the resources, you can check if everything is created correctly by running the command:
k3s kubectl -n pages get deployment,pods,service,ingress
Next steps
I suggest installing cert-manager as the next step and then updating the ingress to generate certificates, as described here.
Updated ingress.yml
looks as follows:
|
|