天天看點

traefik使用kubernetes

traefik使用kubernetes

标準traefik deployment

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: traefik-ingress-lb
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb
spec:
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      terminationGracePeriodSeconds: 60
      hostNetwork: true
      restartPolicy: Always
      serviceAccountName: ingress
      containers:
      -image:        imagePullPolicy: IfNotPresent
        name: traefik-ingress-lb
        securityContext:
          privileged: true
        volumeMounts:
          -mountPath:            name: config
        ports:
        -name:          containerPort: 80
          hostPort: 80
        -name:          containerPort: 8580
          hostPort: 8580
        args:
        - --web
        -:8580        - --kubernetes
        -http://x.x.x.x:8080
        -/config/traefik.toml
      volumes:
        -name:      
  • args中的–configFile參數如果使用traefik.toml就必須按照目錄來配置
  • args中的–kubernetes.endpoint如果你想使用https去與api server互動時就不需要配置這個參數
  • volumes-configMap 使用configmap管理你的traefik.toml檔案内容

traefik暴露日志至外接裝置

volumes:
    -name:      configMap:
         name: traefik-config

---

volumeMounts:
   -mountPath:      

traefik.toml内容

logLevel = "INFO"
defaultEntryPoints = ["http"]
[entryPoints]
  [entryPoints.http]
  address = ":80"
  compress = true
[kubernetes]
[traefikLog]
filePath = "/data/traefik.log"
format = "json"
[accessLog]
filePath = "/data/access.log"
format = "json"      

總結

  • 出現問題不要方,可以使用kubectl logs|describe等指令檢視日志
  • 出現問題時根據一步一步來解決,不要着急,把問題分解再找問題