Traefik
Traefik is a leading modern reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components and configures itself automatically and dynamically.
Traefik is designed to be as simple as possible to operate, but capable of handling large, highly-complex deployments across a wide range of environments and protocols in public, private, and hybrid clouds. It also comes with a powerful set of middlewares that enhance its capabilities to include load balancing, API gateway, orchestrator ingress, as well as east-west service communication and more.
This recipe describes how customers can standardize the configuration, deployment and lifecycle management of Traefik as a custom system add-on across their fleet of clusters.
What Will You Do¶
In this exercise,
- You will create a customized Traefik add-on using Traefik's official Helm chart
- You will use the add-on in a custom cluster blueprint
- You will then apply this cluster blueprint to a managed cluster
- You will then deploy a test workload to use the Traefik ingress controller
Assumptions¶
- You have already provisioned or imported one or more EKS clusters using the controller.
Step 1: Create Custom Values File¶
In this step, you will create a custom values file for the Traefik Helm chart. This values file will configure Traefik to use the AWS loadbalancer.
- Save the below YAML to a file named traefik-values.yaml
service:
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
Step 2: Create Namesapce¶
You will now create a managed namespace from the controller for the Traefik resources.
- Ensure you are logged into the console
- In your project, navigate to Infrastructure -> Namespaces
- Click on New Namespace
- Enter traefik for the name
- Select Wizard for Type
- Click Save
- Click "Save & Go To Placement"
- Select one of your clusters for placement
- Click "Save & Go To Publish"
- Click "Publish"
- Click "Exit"
Step 3: Create Addon¶
In this step, you will create a custom cluster add-on from the Catalog. The add-on will then be used in a custom cluster blueprint.
- In the Rafay console, navigate to Catalog in the left side tree
- Search for "traefik"
- Click on traefik
- Click Create Add-On
- Enter traefik for the name of the add-on
- Select the previously created namespace
- Click Create
- Enter v1 for the version name
- Click Upload Files under the Values File(s) section
- Select the previously saved traefik-values.yaml file
- Click Save Changes
Step 4: Create Bluprint¶
In this step, you will create a custom cluster blueprint which contains the previously created addon.
- In the Rafay console, navigate to Infrastructure -> Blueprints in the left side tree
- Click New Blueprint
- Enter traefik for the name of the blueprint
- Click Save
- Enter v1 for the version name
- Select minimal for the base blueprint
- Click Configure Add-Ons
- Click the + symbol to add the traefik add-on to the blueprint
- Click Save Changes
- Click Save Changes
Step 5: Apply Blueprint¶
In this step, you will apply the previously created blueprint to the cluster. Applying the blueprint will install the Traefik ingress controller.
- In the Rafay console, navigate to Infrastructure -> Clusters in the left side tree
- Click the gear icon on your cluster
- Select Update Blueprint
- Select traefik for the blueprint and v1 for the version
- Click Save and Publish
The blueprint will begin being applied to the cluster
Afer a short period of time, the blueprint will be applied to the cluster.
- Click Exit
Step 6: Deploy Workload Resources¶
In this step, you will deploy the resources needed for a test workload that will use the Traefik ingress controller.
- Save the following YAML to a file named traefik-workload.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: whoami
labels:
app: whoami
spec:
replicas: 1
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: traefik/whoami
ports:
- name: web
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: whoami
spec:
ports:
- name: web
port: 80
targetPort: web
selector:
app: whoami
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: whoami
port:
name: web
- In the Rafay console, navigate to Applications -> Workloads in the left side tree
- Click New Workload -> Create New Workload
- Enter traefik-workload for the name
- Select K8s YAML for the package type
- Select Upload files manually
- Select traefik for the namespace
- Click Continue
- Click Choose File
- Select the previously saved traefik-workload.yaml file
- Click Save and Go To Placement
- Select the cluster to deploy the workload to
- Click Save and Go To Publish
- Click Publish to deploy the workload
- Click Exit
Step 7: Verify Workload¶
In this step, you will verify that the previously deployed workload is running and can be accessed through the Traefik ingress.
- In the Rafay console, navigate to Infrastructure -> Clusters in the left side tree
- Click kubectl on your cluster
- Enter the following command:
kubectl get services -n traefik
You will see something similar to the following screenshot.
- Copy the EXTERNAL-IP of the service named traefik
- Enter the EXTERNAL-IP into a web browswer (Be sure to use http:// and not https://) to access the test workload through the Traefik ingress.
You will see something similar to the following screenshot showing access to the test workload, whoami.
Recap¶
Congratulations! You have successfully created a custom cluster blueprint with the Traefik ingress controller as a custom add-on. You can now use this blueprint on as many clusters as you require.