Warning
At this point you should already have access to your kubernetes cluster in the cloud.
Tip
This example was tested on Linode (Akamai Cloud)
To install traefik on kubernetes, we are going to use helm. Follow the link see how to install it on your system, once done, we can now proceed.
helm repo add traefik https://traefik.github.io/charts
You can update the chart repository by running:
helm repo update
touch traefik-values.ymladd this content to the file
ports:
web:
redirections:
to: websecure
schema: https
websecure:
tls:
enabled: true
certResolver: letsencrypt
certificatesResolvers:
letsencrypt:
acme:
email: <your-email@mail.com>
storage: /data/acme.json
tlsChallenge: trueYou can take a look at all the possible values here traefik-helm-chart values. Also here you have some more examples of configuration traefik-helm-chart examples
Now let's install traefik in a namespace called traefik
Note
This will create a load balancer in you cloud service.
helm install traefik traefik/traefik --create-namespace --namespace traefik --values traefik-values.yml
to check that everithing is correct run this command
kubectl get pods -n traefik
and then
kubectl logs -n traefik <pod-name>
let's deploy a simple nginx service
- create a deployment manifest
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80kubectl apply -f nginx-deployment.yml
- create a service manifest
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
type: ClusterIPkubectl apply -f nginx-service.yml
- create a traefik ingressRoute manifest
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-ingressroute
labels:
app: nginx
spec:
entryPoints:
- websecure
routes:
- match: Host(`<your-domain-here.com>`)
kind: Rule
services:
- name: nginx-service
port: 80
tls:
certResolver: letsencryptkubectl apply -f nginx-ingressroute.yml
Note
Don't forget to create the dns record that points the requested URL to your load balancer