Docker(三十)k8s traefik 再共有云搭建
这里用的腾讯云git clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.gitgit clone https://github.com/containous/traefik.git 项目地址:git clone https://github.com/containous/traefik.git
下载后cd 到目录 ./traefik/examples/k8s 有几个搭建的yaml
traefik-deployment.yamltraefik/examples/k8straefik-deployment.yaml
traefik-ds.yaml
ui.yaml 这里说明下,traefik 有两种部署方式,一种是deployment,还有哟中是daemonset方式 看自己的实际情况使用,这里使用deployment方式
源文件需要改下,因为用到了公有云,所以添加相应的注释来调用公有云服务
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service
namespace: kube-system
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- protocol: TCP
port: 80
name: web
- protocol: TCP
port: 8080
name: admin
type: NodePort 这个要把type的类型改成
type: LoadBalancer 同时添加注释字段来调用共有云服务
annotations:
service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-9mce91qt##这里说明下,后面的value 是lb 的子网字段,这样创建的lb 就是腾讯云的内网vpc 地址,如果不加这个注释,那么创建的
lb 就是公网地址 好了,现在可以kubectl create -f traefik-deployment.yaml来创建,traefik-ingress-controller以及对应的service
这里要提一点:80端口是service端口,是流量的入口,8080是traefik的ui 端口,也是traefik自带ui服务的端口
现在创建ingress转发规则暴露ui
---
apiVersion: v1
kind: Service
metadata:
annotations:
service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-9mce91qt
name: traefik-web-ui
namespace: kube-system
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- name: web
port: 80
targetPort: 8080
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
namespace: kube-system
spec:
rules:
- host: traefik-ui.minikube
http:
paths:
- path: /
backend:
serviceName: traefik-web-ui
servicePort: 80 这里有个地方要想清楚,就是刚才在deployment已经暴露了8080端口,为什么这里还要再创建个service 其实目的在于转发端口,因为ingress 再撞见的时候,是根据协议来的所以默认都是80
而且traefik 其实是代理了service,所以重建了一个service 用来专门被ingress 所代理转发
配置的注释和也是为了调用负载均衡的共有云服务
也就是说,从gw 过来的流量,可以打到traefik 然后在有路由规则转发到后端相应的服务器上,虽然多有了一层的转发,但是这样做的目的是为了以后能根据header host,或者path 等信息,左右恢复发布
这个时候应该是可以见,后端的traefik 的一些服务了
http://s1.运维网.com/images/20180914/1536917959612006.png
页:
[1]