Purpose:

In this guide, we will set up Minikube and Traefik for local development.

This setup is useful for creating a local Kubernetes cluster with ingress capabilities, allowing you to route traffic to your services efficiently.

Add-On Mart infrastructure uses Traefik Ingress Controller. If you plan to deploy applications on Add-On Mart infrastructure, do not choose other providers.

Requirements:

Application installed:

Instructions:

Step 1: Start Minikube

To create a local Kubernetes cluster, you need to start Minikube using Docker as the driver. This will allow you to run Kubernetes cluster in a Docker container on your local machine.

Parameters Explained:

  • --driver=docker - Specifies that Minikube should use Docker as the driver to run the Kubernetes cluster, allowing it to operate within a Docker container on your machine.
Command
minikube start --driver=docker
Output example
  😄  minikube v1.33.1 on Ubuntu 22.04
    ▪ MINIKUBE_ACTIVE_DOCKERD=minikube
✨  Using the docker driver based on user configuration
📌  Using Docker driver with root privileges
👍  Starting "minikube" primary control-plane node in "minikube" cluster
🚜  Pulling base image v0.0.44 ...
🔥  Creating docker container (CPUs=2, Memory=3900MB) ...
🐳  Preparing Kubernetes v1.30.0 on Docker 26.1.1 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Step 2: Deploy Traefik

Traefik is an ingress controller that manages the routing of external traffic to your services within the Kubernetes cluster.

We will deploy it in the previously created Minikube cluster using it using Helm, a package manager for Kubernetes.

Traefik is an Add-On Mart requirement. Based on it Traefik has to be chosen for compatibility with Add-On Mart resources.

Parameters Explained:

  • traefik - The name of the Helm release for Traefik. This identifies the deployment within your Kubernetes cluster.

  • traefik/traefik - The Helm chart used to install Traefik. It contains the configurations and resources needed to deploy Traefik in the cluster.

  • --version 24.0.0 - Specifies the version of the Traefik Helm chart to be installed, ensuring compatibility with your setup.

  • --set providers.kubernetesCRD.allowCrossNamespace=true - Configures Traefik to allow cross-namespace routing, enabling it to handle requests across different namespaces within the cluster.

  • --set ingressRoute.dashboard.entryPoints="{web,traefik}" - Sets the entry points for the Traefik dashboard, allowing access via specified ports (web and traefik).

Before installing Traefik, we need to add the official Traefik Helm chart repository.

Command
helm repo add traefik https://traefik.github.io/charts

Start traefik deployment.

Command
helm install traefik traefik/traefik \
--version 24.0.0 \
--set providers.kubernetesCRD.allowCrossNamespace=true \
--set ingressRoute.dashboard.entryPoints="{web,traefik}"
Output example
NAME: traefik
LAST DEPLOYED: Wed Aug  7 11:56:24 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Traefik Proxy v2.10.4 has been deployed successfully on default namespace!

Step 3: Start Minikube Tunnel

The Minikube tunnel creates a network route to your cluster, allowing access to LoadBalancer services from your local machine.

Pay attention, minikube tunnel command should always be running (we suggest to start it in separate terminal window)
This is essential for accessing the Traefik ingress controller.

Command
  minikube tunnel

The output shown below represents a typical example; however, it may vary depending on the operating system or application version.

Output example
  Status:
        machine: minikube
        pid: 273892
        route: 10.96.0.0/12 -> 192.168.49.2
        minikube: Running
        services: [traefik]
    errors: 
                minikube: no errors
                router: no errors
                loadbalancer emulator: no errors

Step 4: Check Resources and External IP Address of the Traefik Service

To verify that Traefik is running correctly and obtained its external IP address, you can use the kubectl command. If you don't have "kubectl" you can install it (kubectl install )  or use "minikube kubectl".

This will list all resources in the default namespace.

Command
  kubectl get all
Output example
NAME                           READY   STATUS    RESTARTS   AGE
pod/traefik-7c6599d7b9-njfvl   1/1     Running   0          59s

NAME                 TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)                      AGE
service/kubernetes   ClusterIP      10.96.0.1      <none>         443/TCP                      99s
service/traefik      LoadBalancer   10.107.47.31   10.107.47.31   80:30915/TCP,443:31639/TCP   59s

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/traefik   1/1     1            1           59s

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/traefik-7c6599d7b9   1         1         1       59s


Parameters Explained:

  • EXTERNAL-IP - Displays the external IP (address depending on the network configuration it could be a private IP address, address from the range LAN uses or 127.0.0.1 IP address) for the Traefik service, allowing you to access the Traefik dashboard and route traffic to your applications.

To verify that the tunnel provides access to Traefik and the application is functioning correctly, you can attempt to access the Traefik dashboard using the  URL http://<external_ip>/dashboard/ 


Step 5: Update /etc/hosts with External IP and Domain

To route traffic to your local application using a domain name, you need to update the /etc/hosts file with the Traefik external IP address and the desired domain.

Add an IP address and hostname to the /etc/hosts file using the command stated below. Alternatively, you can use your favorite text editor (e.g., vi, nano, etc.) to manually add IP address and hostname to the /etc/hosts file.

Command
  echo "<external_ip> <domain>" | sudo tee -a /etc/hosts

Parameters Explained:

  • <external_ip> - The external IP address of the Traefik service obtained from the previous step.

  • <domain> - The custom domain name you wish to use for your local application (e.g., local_application.com).

Check that appropriate data was inserted into /etc/hosts file.

Command
  grep "local_application" /etc/hosts
Output example
  10.107.47.31 local_application.com

Step 6: Clean up procedures

In case the previously configured cluster needs to be removed, you can simply use the following command:

Command
  minikube delete

Conclusion:

By following these steps, you'll successfully set up Minikube and Traefik for local development, enabling you to test and deploy applications with ingress capabilities.