Kerbernetes的Ingress资源管理
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.Ingress概述
管理对集群中服务的外部访问的API对象,通常是HTTP。Ingress是允许入站连接访问群集服务的规则集合。 Ingress可以配置为提供外部可接收的url、负载平衡通信、SSL终端和基于名称的虚拟主机等功能。 Ingress其实也是一个控制器(Controller),只不过它并不被"kube-controller-manager"打包管理,而且一般情况下Ingress作为Pod来运行。 Ingress仅是用于定义流量转发和调度的通用格式的配置信息,它们需要转换为特定的具有http协议转发和调度功能的应用程序(例如nginx,haproxy,traeik等)的配置文件,并由相应的应用程序生效相应的配置后完成流量转发。 此类能理解Ingress定义的配置信息,并可将其转换为自身配置的应用程序,即为Ingress Controller。 此类的控制区需要由Kubernetes管理员额外以Addons的形式部署为Pod资源对象,它们通过API Server获取Ingress的相关定义; 这与其他类型的控制器不同,它们通常作为"kube-controller-manager"二进制文件的一部分运行,并且通常作为集群创建的一部分自动启动; 选择最适合集群的入口控制器(ingress controller)实现,或者实现一个新的入口控制器(ingress controller),Kubernetes目前支持并维护GCE和nginx控制器(https://github.com/kubernetes/ingress-nginx)。 Ingress自身不支持使用标签选择器挑选真正提供服务的Pod对象,因此,它需要由Service对象的辅助完成此类功能(如借助Service的标签选择器功能过滤出后端的Pod)。 Ingress自身不运行使用标签选择器挑选真正提供服务的Pod对象,它需要由Service对象的辅助完成此类功能。 Ingress Controller根据Igress定义的配置调度流量时,其报文将由Ingress Controller直接调度后直达Pod对象,而不再经由Service调度。 Ingress Controller也是Pod对象,它能够与各后端Pod直接进行通信。 Ingres官方文档: https://kubernetes.io/docs/concepts/services-networking/ingress/
二.在K8S集群部署Ingress-nginx
1>.参考kubernetes的官方文档(https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md)
2>.部署ingress-nginx
[root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]# kubectl get namespace NAME STATUS AGE default Active 3d17h kube-node-lease Active 3d17h kube-public Active 3d17h kube-system Active 3d17h myservice Active 4h19m testing Active 21h testing2 Active 11h [root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.28.0/deploy/static/mandatory.yaml namespace/ingress-nginx created configmap/nginx-configuration created configmap/tcp-services created configmap/udp-services created serviceaccount/nginx-ingress-serviceaccount created clusterrole.rbac.authorization.k8s.io/nginx-ingress-clusterrole created role.rbac.authorization.k8s.io/nginx-ingress-role created rolebinding.rbac.authorization.k8s.io/nginx-ingress-role-nisa-binding created clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress-clusterrole-nisa-binding created deployment.apps/nginx-ingress-controller created limitrange/ingress-nginx created [root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]# kubectl get namespace NAME STATUS AGE default Active 3d17h ingress-nginx Active 11s kube-node-lease Active 3d17h kube-public Active 3d17h kube-system Active 3d17h myservice Active 4h20m testing Active 21h testing2 Active 11h [root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]# kubectl get pods -n ingress-nginx -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-ingress-controller-5556bd798f-hhmhn 1/1 Running 0 47s 10.244.3.5 node203.yinzhengjie.org.cn <none> <none> [root@master200.yinzhengjie.org.cn ~]# [root@master200.yinzhengjie.org.cn ~]#