K8S上部署Ingress+Traefik教程
2019-01-15 本文已影响0人
Firetheworld
Ingress+Traefik介绍:
导入相关的yaml文件以及docker images
[root@k8s-node10-18-223-243 traefik]# ll
总用量 51320
-rw-r--r-- 1 root root 986 9月 26 11:43 dspod.yaml
-rwxrwxrwx 1 root root 56 9月 26 10:36 eage.sh
-rw-r--r-- 1 root root 194 6月 26 16:52 ingress-lb.yaml
-rw-r--r-- 1 root root 460 5月 22 17:23 ingress.yaml
-rw-r--r-- 1 root root 104 5月 22 16:18 namespace.yaml
-rw-r--r-- 1 root root 357 5月 22 16:15 rbac.yaml
-rw-r--r-- 1 root root 86 5月 22 16:39 sa.yaml
-rw-r--r-- 1 root root 52516352 7月 4 13:32 traefik.latest.tar
- 修改yaml文件,添加域名、修改hostname
[root@k8s-node10-18-223-243 traefik]# cat ingress.yaml
apiVersion: v1
kind: Service
metadata:
name: traefik-web-ui
namespace: zteict-k8s
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- name: web
port: 80
targetPort: 8580
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
namespace: zteict-k8s
spec:
rules:
- host: traefik-ui.k8s
http:
paths:
- path: /
backend:
serviceName: traefik-web-ui
servicePort: web
[root@k8s-node10-18-223-243 traefik]# cat ingress.yaml | grep host
- host: traefik-ui.k8s
[root@k8s-node10-18-223-243 traefik]# cat dspod.yaml |grep hostname
kubernetes.io/hostname: k8s-node10-18-223-243
- 给主机添加标签
[root@k8s-node10-18-223-243 traefik]# cat eage.sh
kubectl label nodes k8s-node10-18-223-243 edgenode=true
[root@k8s-node10-18-223-243 traefik]# chmod +x eage.sh && ./eage.sh
node/k8s-node10-18-223-24 labeled
- 启动Ingress+Traefik
[root@k8s-node10-18-223-243 traefik]# kubectl apply -f .
deployment.extensions/traefik-ingress-lb created
service/traefik-web-ui created
service/traefik-web-ui unchanged
ingress.extensions/traefik-web-ui created
namespace/zteict-k8s configured
serviceaccount/ingress unchanged
clusterrolebinding.rbac.authorization.k8s.io/ingress configured
serviceaccount/ingress unchanged
- 本地上访问前,需要进行hosts文件修改,在C:\Windows\System32\drivers\etc下的hosts添加
10.18.223.243 traefik-ui.k8s
效果如下
Ingress+Traefik