基础知识
同nginx相比,traefik能够自动感知后端容器变化,从而实现自动服务发现。
traefik部署在k8s上分为daemonset和deployment两种方式各有优缺点:
daemonset 能确定有哪些node在运行traefik,所以可以确定的知道后端ip,但是不能方便的伸缩
deployment 可以更方便的伸缩,但是不能确定有哪些node在运行traefik所以不能确定的知道后端ip
一般部署两种不同类型的traefik:
面向内部(internal)服务的traefik,建议可以使用deployment的方式
面向外部(external)服务的traefik,建议可以使用daemonset的方式
建议使用traffic-type标签
traffic-type: external
traffic-type: internal
traefik相应地使用labelSelector
traffic-type=internal
traffic-type=external
1. 下载源码
git clone https://github.com/containous/traefik.git
官方网址: https://docs.traefik.io/
获取配置文件
wget https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml wget https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-deployment.yaml wget https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml wget https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/ui.yaml
依次执行
kubectl apply -f traefik-rbac.yaml
kubectl apply -f traefik-deployment.yaml
kubectl apply -f ui.yaml
查看结果
[root@master etc]# kubectl get svc -o wide -n kube-system|grep traefik traefik-ingress-service NodePort 10.99.41.85 <none> 80:32420/TCP,8080:32638/TCP 14m k8s-app=traefik-ingress-lb traefik-web-ui ClusterIP 10.107.9.178 <none> 80/TCP 10m k8s-app=traefik-ingress-lb
浏览器访问
http://47.102.*.*:32638/dashboard/
所有评论(0)