traefik使用kubernetes
在kubernetes集群中直接启动deployment之后就能使用traefik管理你的ingress rule
但是需要添加代理头信息及需要把access log映射到外部存储设备上需要如下配置
不知道如何添加头信息请看官方文档或者请联系我
标准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: traefik
imagePullPolicy: IfNotPresent
name: traefik-ingress-lb
securityContext:
privileged: true
volumeMounts:
- mountPath: /config
name: config
ports:
- name: http
containerPort: 80
hostPort: 80
- name: admin
containerPort: 8580
hostPort: 8580
args:
- --web
- --web.address=:8580
- --kubernetes
- --kubernetes.endpoint=http://x.x.x.x:8080
- --configFile=/config/traefik.toml
volumes:
- name: config
configMap:
name: traefik-config
nodeSelector:
edug: traefik
- args中的–configFile参数如果使用traefik.toml就必须按照目录来配置
- args中的–kubernetes.endpoint如果你想使用https去与api server交互时就不需要配置这个参数
- volumes-configMap 使用configmap管理你的traefik.toml文件内容
traefik暴露日志至外接设备
volumes:
- name: config
configMap:
name: traefik-config
---
volumeMounts:
- mountPath: /data/
name: traefik-log
- 定义volume point ,使用volumes挂载到容器即可,记得宿主机得先创建好你在traefik.toml中的目录
traefik.toml内容
traefik配置说明,有详解的字段说明及使用情况,在添加配置项时建议先阅读traefik配置说明
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等命令查看日志
- 出现问题时根据一步一步来解决,不要着急,把问题分解再找问题
- 如有问题请联系QQ: 375419830