《kubernetes-1.8.0》12-addon-ingress-nginx
《kubernetes 1.8.0 测试环境安装部署》
时间:2017-11-29
一、ingress介绍
关于nginx-ingress:
官网上摘抄几句:
Typically, services and pods have IPs only routable by the cluster network. All traffic that ends up at an edge router is either dropped or forwarded elsewhere. Conceptually, this might look like:
通常,services和Pod只能通过集群内网络访问。 所有在边界路由器上的流量都被丢弃或转发到别处。 从概念上讲,这可能看起来像:
internet
|
------------
[ Services ]
An Ingress is a collection of rules that allow inbound connections to reach the cluster services.
Ingress是允许入站连接到达集群服务的一组规则。即介于物理网络和群集svc之间的一组转发规则。
其实就是实现L4 L7的负载均衡
internet
|
[ Ingress ]
--|-----|--
[ Services ]
出来ingress以外,对外的服务发现还可以使用nodeport的方式,但这样会导致节点上的端口占用很多,且不利于管理。
It can be configured to give services externally-reachable URLs, load balance traffic, terminate SSL, offer name based virtual hosting, and more. Users request ingress by POSTing the Ingress resource to the API server. An Ingress controller is responsible for fulfilling the Ingress, usually with a loadbalancer, though it may also configure your edge router or additional frontends to help handle the traffic in an HA manner.
它可以配置为提供外部可访问的URL,负载平衡流量,终止SSL,提供基于名称的虚拟主机,等等。 用户请求通过将Ingress resource发送到API server。 一个Ingress controller负责响应入口请求,通常是负载均衡方式,它也可能通过配置你的外部路由器或额外的前端,以帮助处理HA方式的流量。
二、ingress-nginx部署
ingress-nginx组件有几个部分组成:
configmap.yaml
:提供configmap可以在线更行nginx的配置default-backend.yaml
:提供一个缺省的后台错误页面 404namespace.yaml
:创建一个独立的命名空间 ingress-nginxrbac.yaml
:创建对应的role rolebinding 用于rbactcp-services-configmap.yaml
:修改L4负载均衡配置的configmapudp-services-configmap.yaml
:修改L4负载均衡配置的configmapwith-rbac.yaml
:有应用rbac的nginx-ingress-controller组件
相关yaml文件如下:
namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: ingress-nginx
default-backend.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: default-http-backend
labels:
app: default-http-backend
namespace: ingress-nginx
spec:
replicas: 1
template:
metadata:
labels:
app: default-http-backend
spec:
terminationGracePeriodSeconds: 60
containers:
- name: default-http-backend
# Any image is permissable as long as:
# 1. It serves a 404 page at /
# 2. It serves 200 on a /healthz endpoint
image: gcr.mirrors.ustc.edu.cn/google_containers/defaultbackend:1.4
livenessProbe:
httpGet:
path: /healthz
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
ports:
- containerPort: 8080
resources:
limits:
cpu: 10m
memory: 20Mi
requests:
cpu: 10m
memory: 20Mi
---
apiVersion: v1
kind: Service
metadata:
name: default-http-backend
namespace: ingress-nginx
labels:
app: default-http-backend
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: default-http-backend
- github上 image:
gcr.io/google_containers/defaultbackend:1.4
更换为gcr.mirrors.ustc.edu.cn/google_containers/defaultbackend:1.4
configmap.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-configuration
namespace: ingress-nginx
labels:
app: ingress-nginx
tcp-services-configmap.yaml