How to migrate from nginx to traefik ingress
2 minute read
Installation
Kubeops supports deploying Traefik as a dynamic ingress controller and reverse proxy. This guide describes a concise, safe migration from an existing nginx-ingress controller to Traefik and explains how to install Traefik and replace a deprecated nginx-ingress deployment. The migration from nginx to Traefik is straightforward; the steps below show the process in order.
Prerequisites
-
A running Kubernetes cluster with an existing nginx-ingress controller.
-
It is recommended to do a login with
kosi. Refer to the official KOSI documentation for details here.
1.Create Values file
Create a values.yaml file for the Traefik installation:
# values.yaml
packages:
- name: traefik
enabled: true
values:
standard:
namespace: traefik
externalIPs: []
advanced: {}
Note: Update externalIPs and any other values as required for your environment.
2.Install Traefik
non-airgap-environment
After creating values.yaml, install Traefik:
# get your desired version/s
kosi search --hub kubeops --ps traefik
# install traefik
kosi install --hub kubeops kubeops/traefik:<desired_version> -f values.yaml --dname traefik
Example Non-airgap
kosi install --hub kubeops kubeops/traefik:2.1.0_Beta0 -f values.yaml --dname traefik
Airgap-environment
# log in to Harbor
podman login <ip_address>:<NodePort> -u <username> -p <password> --tls-verify=false
# pull your desired version
kosi pull --hub kubeops kubeops/<desired_version> -o traefik-<desired_version>.tgz -r <ip_address>:<NodePort>/kubeops -t localhost:<NodePort>/kubeops
# install Traefik
kosi install --dname traefik -p <desired_version>.tgz -f values.yaml
Example Airgap
kosi pull --hub kubeops kubeops/traefik:2.1.0_Beta0 -o traefik-2.1.0-Beta0.tgz -r 10.2.10.11:30003/kubeops -t localhost:30003/kubeops
kosi install --dname traefik -p traefik-2.1.0-Beta0.tgz -f values.yaml
3.Verify Deployment
Verify that the Traefik pods and services are running in the traefik namespace:
kubectl get pods -n traefik
kubectl get svc -n traefik
4.Remove old nginx-ingress deployment and service
# get version of installed nginx-ingress and its deployment name (--dname)
kosi list
# delete old nginx-ingress
kosi delete --hub kubeops kubeops/ingress-nginx:<installed_version> -f enterprise-values.yaml --dname <kosi_deployment_name>
Example
kosi delete --hub kubeops ingress-nginx:2.1.0_Beta0 -f values.yaml --dname traefik
Edit Traefik service
If nginx-ingress used specific NodePorts that you need to reuse, update the Traefik Service:
kubectl edit svc traefik -n traefik
Note: Default NodePorts (for example, 31080 / 31443) might not be reachable in your environment. If these ports are not accessible, determine the NodePorts previously used by nginx-ingress (for example, 30080 / 30443) and configure Traefik to use the same ports.
Update the ports:
Adjust the ports section to match the previous nginx NodePorts if required:
ports:
- name: web
nodePort: 30080
port: 80
targetPort: web
- name: websecure
nodePort: 30443
port: 443
targetPort: websecure
Verify Port Change
kubectl get svc -n traefik
Note: Ensure that the nginx Service is removed or that its NodePorts are freed before reusing those NodePorts on the Traefik Service.