《kubernetes-1.8.0》12-addon-ingress-nginx

《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:提供一个缺省的后台错误页面 404
  • namespace.yaml:创建一个独立的命名空间 ingress-nginx
  • rbac.yaml:创建对应的role rolebinding 用于rbac
  • tcp-services-configmap.yaml:修改L4负载均衡配置的configmap
  • udp-services-configmap.yaml:修改L4负载均衡配置的configmap
  • with-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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值