k8s Ingress Controller 之 Traefik 部署
介绍
官网: https://traefik.io
Traefik 云原生边缘路由器 是一款开源的HTTP反向代理与负载均衡工具。
它最大的优点是能够与常见的微服务系统直接整合,可以实现自动化动态配置。
支持 Docker,Swarm mode,Kubernetes,Mesos,Marathon,Rancher (API, Metadata),Azure Service Fabric,Consul Catalog,Consul,Etcd,Zookeeper,BoltDB,Eureka,Amazon ECS,Amazon DynamoDB,File,Rest等等后端模型。
部署
部署文件: https://github.com/linuxhub/kubernetes/tree/master/install/ingress-traefik
检查端口
检查端口占用检查Kubernets集群工作节点端口占用,Traefik会使用到80,443,8080端口。ssh root@${node_ip} "netstat -nltp | egrep ':80|:443|:8080' "
创建 RBAC 授权
获取traefik-rbac.yaml文件并应用,用于service account验证kubectl apply -f https://raw.githubusercontent.com/linuxhub/kubernetes/master/install/ingress-traefik/traefik-rbac.yaml
部署 traefik
以 Daemon Set 的方式在每个 node 上启动一个 traefik,并使用 hostPort 的方式让其监听每个 node 的 80 端口kubectl apply -f https://raw.githubusercontent.com/linuxhub/kubernetes/master/install/ingress-traefik/traefik-ds.yaml
查看 Service
状态# 查看 Service
$ kubectl -n kube-system get Service traefik-ingress-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
traefik-ingress-service NodePort 10.254.171.92 <none> 80:39693/TCP,443:56079/TCP,8080:15820/TCP 142d
# 查看 pod
$ kubectl -n kube-system get pods -l name=traefik-ingress-lb --show-labels
NAME READY STATUS RESTARTS AGE LABELS
traefik-ingress-controller-5ql8g 1/1 Running 7 142d controller-revision-hash=4056369343,k8s-app=traefik-ingress-lb,name=traefik-ingress-lb,pod-template-generation=1
traefik-ingress-controller-pm2h2 1/1 Running 6 142d controller-revision-hash=4056369343,k8s-app=traefik-ingress-lb,name=traefik-ingress-lb,pod-template-generation=1
traefik-ingress-controller-qzw6p 1/1 Running 7 140d controller-revision-hash=4056369343,k8s-app=traefik-ingress-lb,name=traefik-ingress-lb,pod-template-generation=1
部署 traefik-ui
Traefik 本身还提供了一套 UI 供我们使用,其同样以 Ingress 方式暴露kubectl apply -f https://raw.githubusercontent.com/linuxhub/kubernetes/master/install/ingress-traefik/traefik-web-ui.yaml
域名配置spec:
rules:
- host: ing.linuxhub.cn
查看状态$ kubectl -n kube-system get ing traefik-web-ui
NAME HOSTS ADDRESS PORTS AGE
traefik-web-ui ing.linuxhub.cn 80 130d
使用
应用Demo: http://www.linuxhub.cn/2019/04/18/deploy-k8s-java.htmlapiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: linuxhub-web-ingress
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: demo.linuxhub.cn
http:
paths:
- path: /
backend:
serviceName: linuxhub-web-svc
servicePort: 8088
# ing 状态 |
本文作者 : 泽泽
原文链接 : http://www.linuxhub.cn/2019/04/19/install-ingress-traefik.html
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
知识 & 情怀 | 二者兼得