Kubernetes之Ingress组件部署
这里不做kubernetes暴露服务的三种方式,只解说Ingress方式。
Service后端分类,手机后端分类,通过ingress动态注入,
一、原理说明
如下,ingress包含两大组件:ingress controller和ingress。
Ingress:即为Nginx配置,在pod内部实现
Ingress-Controller:暴露服务,生成模板,读取ingress走向。
Ingress也是标准的kubernetes资源。
二、部署ingress
官网下载4个包:
先部署命名空间,
新版本的configmap包含了tcp、udp配置。
[root@master ing]# pwd
/root/yaml/ingress-Nginx/ing
[root@master ing]# ls
configmap.yaml namespace.yaml rbac.yaml with-rbac.yaml
完成ingress服务配置。
老版本有依赖,不需要这个default-http pod。
三、部署Ingress-Controller
手动部署,确保ingress-controller可以接入外部流量。
[root@master ing]# wget https://raw.githubusercontent.com/kubernetes/ingress-Nginx/master/deploy/provider/bareMetal/service-nodeport.yaml
[root@master ing]# vim service-nodeport.yaml
修改默认配置,将ingress-controller固定暴露端口。
[root@master ing]# kubectl apply -f service-nodeport.yaml
service/ingress-Nginx created
[root@master ~]# kubectl get svc -n ingress-Nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-Nginx NodePort 10.104.234.98 <none> 80:30080/TCP,443:30443/TCP 16m
[root@master ~]# curl 10.104.234.98
[root@master ~]# curl node1:30080
如下截图,正常显示。
测试对外服务ingress-controller是否运行成功,如上,查看错误信息为404,出现Nginx提示,表示成功部署,运行正常。
四、发布测试服务
准备后端服务。
[root@master ~]# kubectl run httpd --image=httpd
[root@master ~]# kubectl expose deployment httpd --port=80
[root@master ~]# kubectl get pods |grep httpd
httpd-5d8cbbcd67-ct56t 1/1 Running 1 108m
[root@master ~]# kubectl get svc/httpd
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
httpd ClusterIP 10.105.142.50 <none> 80/TCP 21h
[root@master ~]#
如下,后端通过pod、svc服务都可以正常访问。
后端准备好,现在可以发布。
[root@master ingress-Nginx]# vim ingress_httpd.yaml
[root@master ingress-Nginx]# vim ingress_httpd.yaml
[root@master ~]# kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
httpd-test foo.bar.com 80 19h
[root@master ~]# kubectl get ing -n ingress-Nginx
No resources found.
[root@master ~]# kubectl get ing
[root@master ~]# kubectl describe ing/httpd-test
五、测试服务
配置域名hosts文件
[root@node1 ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.19.133 node1 foo.bar.com
192.168.19.134 master
192.168.19.135 node2 foo.bar.com
如下,访问正常。
整个过程:
部署ingress—>部署ingress controller
部署应用deploy(pod)—>部署应用svc—>暴露域名服务
六、多个服务
[root@master ingress-Nginx]# cat ingress_deploy-demo.yaml
测试后端服务,
如上,正常。
进入容器查看相关配置信息。
[root@mar ~]# kubectl exec -it nginx-ingress-controller-689498bc7c-c76gt -n ingress-Nginx – sh
$ pwd
/etc/nging
$ more Nginx.conf
自此,完成ingress配置,相关yaml文件:https://github.com/Wangwang12345/k8s
遗留问题:这里测试了一下同一个域名下多个服务,发现只能存在一个/根路径访问?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。