Setup a Kubernetes cluster with K3S, Traefik, CertManager and Kubernetes Dashboard
Introduction
Hello everyone ! In this blog, we will see how to setup a Kubernetes cluster with:
-
K3S: it is a lightweight Kubernetes distribution created by Rancher Labs. It is fully certified by the Cloud Native Computing Foundation (CNCF) and is designed for production workloads in unattended, resource-constrained, remote locations or inside IoT appliances. K3s is highly available, production-ready, and has a very small binary size and very low resource requirements.
-
Helm: it is a package manager for Kubernetes. It simplifies the deployment of applications and services onto Kubernetes clusters by automating the creation, packaging, configuration, and deployment. Helm packages are called charts, which contain all the resource definitions necessary to run an application, tool, or service inside a Kubernetes cluster.
-
Traefik: it is an open-source Edge Router and a modern HTTP reverse proxy and load balancer. It makes deploying microservices easy by automatically and dynamically integrating with your existing infrastructure components.
-
CertManager: it is a native Kubernetes certificate management controller. It creates TLS certificates for workloads in your Kubernetes cluster and renews the certificates before they expire. CertManager can obtain certificates from a variety of certificate authorities, including Let’s Encrypt.
-
Kubernetes Dashboard: it is a web-based user interface for Kubernetes clusters. It provides a graphical representation of various aspects of a Kubernetes cluster.
Install K3S
Source: https://k3s.io/
Install the certs to your machine to connect to the cluster
Setup Vim (optional)
Setup bashrc
To automatically setup the configuration:
Install kubectx and kubens (optional)
Source: https://github.com/ahmetb/kubectx?tab=readme-ov-file#installation
- kubectx is a tool to switch between contexts (clusters) on kubectl faster.
- kubens is a tool to switch between Kubernetes namespaces (and configure them for kubectl) easily.
You can use Krew for the installation:
Or we can use the easy way with apt
package:
Install Helm
Source: https://helm.sh/docs/intro/install/#from-script
Install CertManager
Source: https://artifacthub.io/packages/helm/cert-manager/cert-manager#configuration
Then verify the instalation:
Setup with Let’s Encrypt
Source: https://letsencrypt.org/docs/staging-environment/
Here is the configuration for staging environments:
Here is the configuration for production environments:
Then, do kubectl apply -f <file>
to apply the configurations.
Note: here, we create ClusterIssuer resources. They are non-namespaced resources. If you want to limit the certificate creation to a certain namespace, you may create an Issuer.
Source: https://cert-manager.io/docs/concepts/issuer/#namespaces
To verify the installation, we can do:
Install Traefik
Note: on K3S, Traefik is installed by default (source: https://docs.k3s.io/networking/networking-services?_highlight=traefik#traefik-ingress-controller). If traefik is not already installed, you can follow these steps:
Then we can configure Traefik (here I will expose the dashboard on “traefik.alexandre-hublau.com”):
Setup our own applications
Here is a small example for deploying an application:
Kubernetes dashboard
Now, let’s install the Kubernetes Dashboard (source: https://github.com/kubernetes/dashboard?tab=readme-ov-file#installation):
Let’s setup the configurations:
To connect to the dashboard API, you need a token. To generate one, you can execute the command:
Conclusion
🎉 Tadaaa 🎉 ! We did it! We have a full working cluster! Setting up a Kubernetes cluster with K3S, Helm, Traefik, CertManager, Let’s Encrypt, and Kubernetes Dashboard offers a streamlined and efficient way to manage containerized applications.
I hope this post is useful for you. Don’t forget to check out my other blog posts where we cover various DevOps topics!
Happy clustering and may your deployments be smooth sailing! 😊🏗️
Practice code with the "Quick Sort" algorithm
Enhance your coding skills by learning how the Quick Sort algorithm works!
The SOLID/STUPID principles
Learn what are the SOLID and STUPID principles with examples
Create a Docker Swarm playground
Let's create Docker Swarm playground on your local machine
Create an Ansible playground with Docker
Let's create an Ansible playground with Docker
HashiCorp Vault - Technological watch
Learn what is HashiCorp Vault in less than 5 minutes !
How to internationalize an AstroJS website while maintaining good SEO ?
We will see how to create an implementation of i18n with AstroJS
LFTP - Deploy an application in command line
Here we will see how to automatically deploy an application with lftp in command line.
Create a WAMP environment with docker
An easy code to install Apache, MySQL and PHP with Docker !