部署traefik服务
主要是三个yaml文件:traefik-deployment.yaml,traefik-rbac.yaml,ui.yaml
也可以使用traefik-ds.yaml,这个方式体现。
[root@k8smaster traefiks]# ll
总用量 12
-rw-r--r--. 1 root root 1114 12月 26 22:14 traefik-deployment.yaml
-rw-r--r--. 1 root root 788 12月 26 22:13 traefik-rbac.yaml
-rw-r--r--. 1 root root 471 12月 26 22:14 ui.yaml
[root@k8smaster traefiks]# kubectl apply -f traefik-rbac.yaml clusterrole.rbac.authorization.k8s.io/traefik-ingress-controller created clusterrolebinding.rbac.authorization.k8s.io/traefik-ingress-controller created [root@k8smaster traefiks]# kubectl apply -f traefik-deployment.yaml serviceaccount/traefik-ingress-controller created deployment.apps/traefik-ingress-controller created service/traefik-ingress-service created [root@k8smaster traefiks]# kubectl apply -f ui.yaml service/traefik-web-ui created ingress.extensions/traefik-web-ui created
[root@k8smaster demo]# kubectl get svc -n kube-system -owide |grep traefik # 80-业务端口, 8080-ui页面,还缺一个443端口(需要保留)。
traefik-ingress-service NodePort 10.96.253.173 <none> 80:30164/TCP,8080:30637/TCP 37h k8s-app=traefik-ingress-lb
traefik-web-ui ClusterIP 10.105.88.89 <none> 80/TCP 37h k8s-app=traefik-ingress-lb
[root@k8smaster demo]# curl -H "host: traefik-ui.minikube" 192.168.1.82:30164
<a href="/dashboard/">Found</a>.
[root@k8smaster demo]# curl -H "host: traefik-ui.minikube" 192.168.1.82:30164/dashboard/
<!doctype html><html class="has-navbar-fixed-top"><head...
[root@k8smaster demo]# curl 192.168.1.82:30637/dashboard/
<!doctype html><html class="has-navbar-fixed-top"><head...
[root@k8smaster ~]# curl k8snode2:30637
浏览器访问,http://192.168.1.82:30637/dashboard/,如下,
下面开始实例验证了。
参考:https://blog.csdn.net/qq_33816243/article/details/127118553
[root@k8smaster demo]# kubectl get pods NAME READY STATUS RESTARTS AGE myapp1-76c788c697-5hj4b 1/1 Running 0 2m58s myapp2-84c669669f-x45mm 1/1 Running 0 70s [root@k8smaster demo]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38h myapp1 ClusterIP 10.98.31.249 <none> 80/TCP 2m59s myapp2 ClusterIP 10.104.162.151 <none> 80/TCP 2m55s [root@k8smaster demo]# curl 10.98.31.249 Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a> [root@k8smaster demo]# curl 10.104.162.151 Hello MyApp | Version: v7 | <a href="hostname.html">Pod Name</a>[root@k8smaster demo]# kubectl apply -f myapp1-ingress.yaml ingress.extensions/traefik-ingress created [root@k8smaster demo]# curl -H "host: myapp1.test.com" 192.168.1.82:30164 Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>[root@k8smaster demo]# curl -H "host: myapp2.test.com" 192.168.1.82:30164 Hello MyApp | Version: v7 | <a href="hostname.html">Pod Name</a> [root@k8smaster demo]# curl -H "host: myapp2.test.com" 192.168.1.82:30164/hostname.html myapp2-84c669669f-x45mm