Install Traefik Ingress Controller on Kubernetes using Helm 3

In this article we are going to cover Install Helm 3 on Kubernetes Cluster, Install Traefik Ingress Controller on Kubernetes using Helm 3.

Creating Deployment and service for nginx app and NodeJs app, Creating Traefik Ingress Resources and Exposing the apps.

Pointing Traefik Ingress Loadbalancer in Domain Name provider and Accessing Traefik Dashboard.

Here we are installing Traefik 2 on Kubernetes Cluster.

Prerequisites:

  • Kubernetes KOPS Cluster with v1.19.0+

#1: Install Helm 3 on Kubernetes Cluster

Install helm3 on Kubernetes Cluster on Kubernetes Cluster using below command

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

To check helm3 version

helm version

Output:

version.BuildInfo{Version:"v3.5.3", GitCommit:"041ce5a2c17a58be0fcd5f5e16fb3e7e95fea622", GitTreeState:"dirty", GoVersion:"go1.15.8"}

#2: Install Traefik Ingress Controller on Kubernetes using Helm 3

Add the Traefik ingress helm repo in Kubernetes kops cluster, follow this Traefik ingress official page to install latest Traefik ingress helm chart

helm repo add traefik https://helm.traefik.io/traefik

Update the helm repo

helm repo update

Install Traefik Ingress Controller on Kubernetes using Helm 3

helm install traefik traefik/traefik

To install Traefik in specific namespace use below commands

kubectl create ns traefik-v2
helm install --namespace=traefik-v2 \
    traefik traefik/traefik

To check Traefik ingress controller service

kubectl get svc

Output:

NAME         TYPE           CLUSTER-IP     EXTERNAL-IP                                                               PORT(S)                      AGE
kubernetes   ClusterIP      100.64.0.1     <none>                                                                    443/TCP                      9m35s
traefik      LoadBalancer   100.71.30.91   ad51e01b1a2064541852a2e6e8227e26-764563388.ap-south-1.elb.amazonaws.com   80:30915/TCP,443:32466/TCP   5m21s

We have covered Install Traefik Ingress Controller on Kubernetes using Helm 3

#3. Creating Deployment and service for nginx app and NodeJs app

Lets deploy the sample nginx and nodejs app on Traefik ingress controller

#3.1. Creating Deployment and service for Nginx app

Create the nginx app deployment

sudo nano nginx-deploy.yml

paste the below deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nginx-web
  namespace: default
  labels:
    app: nginx-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-web
  template:
    metadata:
      labels:
        app: nginx-web
    spec:
      containers:
      - name: nginx
        image: "nginx"

Create the nginx app service

sudo nano nginx-svc.yml

paste the below code

apiVersion: v1
kind: Service
metadata:
  name: nginx-web
  namespace: default
spec:
  selector:
    app: nginx-web
  ports:
  - name: http
    targetPort: 80
    port: 80

deploy the nginx app deployment and service on kubernetes

kubectl create -f nginx-deploy.yml
kubectl create -f nginx-svc.yml

#3.2. Creating Deployment and service for nodejs app

Create the nodejs app deployment

sudo nano nodejs-deploy.yml

paste the below code, here we are using sample nodejs AWS ECR image

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nodejs-app
  namespace: default
  labels:
    app: nodejs-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-app
  template:
    metadata:
      labels:
        app: nodejs-app
    spec:
      containers:
      - name: nodejs-app
        image: "908198849120.dkr.ecr.ap-south-1.amazonaws.com/nodejsapp:latest"
        ports:
          - containerPort: 3000

Create the nodejs app service

sudo nano nodejs-svc.yml

paste the below code

apiVersion: v1
kind: Service
metadata:
  name: nodejs-app
  namespace: default
spec:
  selector:
    app: nodejs-app
  ports:
  - name: http
    targetPort: 3000
    port: 80

deploy the nodejs app deployment and service on kubernetes

kubectl create -f nodejs-deploy.yml
kubectl create -f nodejs-svc.yml

#4. Creating Traefik Ingress Resources and Exposing the apps

Lets create the Traefik ingress resource on Kubernetes to expose the apps

sudo nano traefik-ingress.yml

Paste the below nginx and nodejs app details, here service name should match with service.yml’s

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: traefik-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: traefik
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: nginxapp.fosstechnix.info
    http:
      paths:
      - backend:
          service:
            name: nginx-web
            port:
              number: 80
        path: /
        pathType: Prefix
  - host: nodejsapp.fosstechnix.info
    http:
      paths:
      - backend:
          service:
            name: nodejs-app
            port:
              number: 80
        path: /
        pathType: Prefix

deploy the traefik ingress resource on Kubernetes KOPS cluster

kubectl create -f traefik-ingress.yml   

To check Kubernetes pods using kubectl

kubectl get pods

Output:

NAME                          READY   STATUS    RESTARTS   AGE
nginx-web-5bf45d88df-zs42j    1/1     Running   0          11m
nodejs-app-76c4545979-b5jm7   1/1     Running   0          10m
traefik-5c454b7c44-jwx4j      1/1     Running   0          33m

To check kubernetes deployments using kubectl

kubectl get deploy

Output:

NAME         READY   UP-TO-DATE   AVAILABLE   AGE
nginx-web    1/1     1            1           11m
nodejs-app   1/1     1            1           10m
traefik      1/1     1            1           33m

To check Kubernetes service using kubectl

kubectl get svc

Output:

NAME         TYPE           CLUSTER-IP       EXTERNAL-IP                                                               PORT(S)                      AGE
kubernetes   ClusterIP      100.64.0.1       <none>                                                                    443/TCP                      37m
nginx-web    ClusterIP      100.64.219.116   <none>                                                                    80/TCP                       11m
nodejs-app   ClusterIP      100.70.17.76     <none>                                                                    80/TCP                       10m
traefik      LoadBalancer   100.71.30.91     ad51e01b1a2064541852a2e6e8227e26-764563388.ap-south-1.elb.amazonaws.com   80:30915/TCP,443:32466/TCP   33m

To check kubernetes ingress using kubectl

kubectl get ingress

Output:

NAME              CLASS    HOSTS                                                  ADDRESS   PORTS   AGE
traefik-ingress   <none>   nginxapp.fosstechnix.info,nodejsapp.fosstechnix.info 

#5. Pointing Traefik Ingress Loadbalancer in Domain Name provider

To access apps using domain name, here we have pointed loadbalancer url in Domain name provider as CNAME.

How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 1

Now access nginx app using domain name

nodejsapp.fosstechnix.info
How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 2

Now access nodejs app using domain name

How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3 3

#6: Accessing Traefik Dashboard

By default traefik dashboard is not exposed when we install traefik using helm chart for security reason,

There are multiple ways to access traefik dashboard, lets access traefik dashboard by forwarding traefik pod to any address using below command.

kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name) --address 0.0.0.0 9000:9000

Now you can access traefik with IP address of instance from instance.

http://127.0.0.1:9000/dashboard/

OR

Cluster Node IP with port number

http://65.2.81.244:9000/dashboard/#/
Install Traefik Ingress Controller on Kubernetes using Helm 3 1

Conclusion:

We have covered Install Helm 3 on Kubernetes Cluster, Install Traefik Ingress Controller on Kubernetes using Helm 3.

Creating Deployment and service for nginx app and NodeJs app, Creating Traefik Ingress Resources and Exposing the apps.

Pointing Traefik Ingress Loadbalancer in Domain Name provider and Accessing Traefik Dashboard.

Related Articles:

How to Install Nginx Ingress Controller Kubernetes KOPS using Helm 3

Reference:

Traefik Ingress GitHub Page

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap