# traefik **Repository Path**: greghe/traefik ## Basic Information - **Project Name**: traefik - **Description**: helm v3 安装traefik2.5.4 版本和使用 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 0 - **Created**: 2021-11-25 - **Last Updated**: 2025-07-19 ## Categories & Tags **Categories**: cloud-native **Tags**: None ## README # Traefik简单安装和使用 [Traefik](https://traefik.io/) is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. ## Introduction This chart bootstraps Traefik version 2 as a Kubernetes ingress controller, using Custom Resources `IngressRoute`: . ## 安装 ### 前提条件 使用命令 `helm version`, 确认版本v3: - Helm v3 [installed](https://helm.sh/docs/using_helm/#installing-helm) 添加Traefik's helm chart 的仓库地址: ```bash helm repo add traefik https://helm.traefik.io/traefik ``` 更新helm 仓库: ```bash helm repo update ``` ### Kubernetes 版本支持情况 [x]表示支持 | | Kubernetes v1.15 and below | Kubernetes v1.16-v1.21 | Kubernetes v1.22 and above | | ----------------------- | -------------------------- | ---------------------- | -------------------------- | | Chart v9.20.2 and below | [x] | [x] | - | | Chart 10.0.0 and above | - | [x] | [x] | 本仓库的版本是``chart:10.6.2 ``, `traefik app: 2.5.4 ` ### 步骤 ```bash $ git clone https://gitee.com/greghe/traefik.git $ cd traefik $ kubectl create ns traefik-ingress # 创建一个traefik 用户空间 $ helm install traefik . -f value.yaml -namespace traefik-ingress ``` #### 具体说明 1. 采用DaemonSet 方式部署(`设置好调度,避免安装到不必要的node上`) 2. web(8000),websecure(8443),testport(6000) 分别绑定本地端口80,443,6000端口,采用 hostPort(`以上端口在节点上不能被占用`) ```yaml ports: traefik: # traefik dashboard 端口 按实际需求是否开启 port: 9000 hostPort: 9000 expose: false exposedPort: 9000 protocol: TCP web: # 业务口80 port: 8000 hostPort: 80 protocol: TCP websecure: # 业务口443 port: 8443 hostPort: 443 protocol: TCP tls: enabled: false options: "" certResolver: "" domains: [] testport: # 按实际需求添加端口 ,本仓库开放6000 端口测试 port: 6000 hostPort: 6000 protocol: TCP metrics: port: 9100 expose: false exposedPort: 9100 ``` 3.用service ### 使用例子 1. 安装后默认开启dashboard,访问任意一个nodeip:9000/dashboard/ ,可以进入 2. traefik 2.0 开始使用CRD 中ingressRoute 来实现代理配置 . 2.1 http 例如:实现mynginx service 80 端口代理 ```yaml apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: mynginx namespace: default spec: entryPoints: - web routes: - kind: Rule match: Host(`mynginx.test.com`,`mynginx.gitee.com`) && PathPrefix(`/`) services: - name: mynginx port: 80 ``` 2.2 TCP ```yaml apiVersion: traefik.containo.us/v1alpha1 kind: IngressRouteTCP metadata: name: redis namespace: default spec: entryPoints: - testport routes: - match: HostSNI(`*`) services: - name: redis-dp port: 6379 ``` 3. 插件使用 ,例如 redirectScheme 插件实现 http 强跳 https ```yaml apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: redirectscheme spec: redirectScheme: scheme: https --- apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: mynginx namespace: default spec: entryPoints: - web routes: - kind: Rule match: Host(`mynginx.test.com`,`mynginx.gitee.com`) && PathPrefix(`/`) services: - name: mynginx port: 80 middlewares: - name: redirectscheme ```