一、安装traefik

  • 需提前安装好MetalLB
helm repo add traefik https://helm.traefik.io/traefik
helm repo update

k create ns traefik
helm install traefik traefik/traefik --namespace traefik


#国内会报镜像拉取错误
手动修改docker.io/traefik:v3.1.0 即可

查看
k get all -n traefik

查看CRD
k get crd -n traefik |grep traefik


查看仪表盘
k get svc -l app.kubernetes.io/name=traefik -n traefik
<EXTERNAL-IP>是外部IP


#卸载
helm uninstall traefik traefik/traefik

二、部署一个demo

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
      - name: whoami-container
        image: whoami:v1.5.0
---
apiVersion: v1
kind: Service
metadata:
  name: whoami-service
spec:
  ports:
  - name: http
    targetPort: 80
    port: 80
  selector:
    app: whoami
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-ingress
spec:
  rules:
  - host: "test.xx.cn"
    http:
      paths:
      - path: /whoami
        pathType: Exact
        backend:
          service:
            name: whoami-service
            port:
              number: 80

kubectl apply -f /dataF/k0s_files/traefik-demo.yaml

测试


局域网
curl http://172.16.122.64/whoami
公网
curl http://47.99.x.196/whoami
域名
curl http://test.xxx.cn/whoami

repo国内源

添加阿里云repo
#删除默认
helm repo remove stable
helm repo add stable https://burdenbear.github.io/kube-charts-mirror/
helm repo add  micro http://mirror.azure.cn/kubernetes/charts    微软仓库(推荐使用):
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts 
helm repo update
helm repo list

搜索
helm search repo traefik
安装指定的版本
helm install traefik traefik/traefik  --version=v30.0.2

升级traefik部署

helm upgrade  --values custom-traefik-values.yaml  traefik  traefik/traefik --namespace traefik

镜像拉取错误处理

k edit service/traefik  -n traefik
k edit deployment/traefik  -n traefik
修改image名称