zoukankan      html  css  js  c++  java
  • 第七章 HTTP流量管理(一) gateway

    Gateway: istio的一种资源类型,Istio Gateway告诉k8s的istio-ingressgateway pods可以打开哪些主机和端口(如下的80是 ingressgateway pod容器中的端口)

                       gateway是定义了哪些的hosts可以到达ingress pod。

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: galaxygateway
    spec:
      selector:
        istio: ingressgateway
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
          - "*"

    (A)  selector:

         istio: ingressgateway   , 这个label是在ingressgateway的pod中定义的。 用如下命令可以查到

    (B)  如下的port 80, 不是指主机的端口,而是ingressgateway 的pod中容器的80端口。

    servers:
      - port:
          number: 80
          name: http
          protocol: HTTP

      (C) hosts:

                 "*"

    这就在Istio的ingress网关上开辟了一个端口,但是只是接受访问和流量输入,当流量到达这个网关时,它还不知道发送到哪里去。

    现在我们的网关已准备好接收流量,我们必须告知它将收到的流量发往何处,Istio使用名为“VirtualService”类型配置流量发往何处。
    将一个网关列表配置给VirtualService,然后Istio使用VirtualService配置中定义的路由再配置那些网关.

    URI路径前缀匹配/env的将发往指定目标.(注意: 如果有多个virtualservice文件,后面的会覆盖前面的,所以要把所有的路由信息都配置到一个virtualservice)

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: flaskapp
    spec:
      hosts:
      - "*"
      gateways:
      - galaxygateway 
      http:
      - match:
        - uri:
            prefix: /env
        route:
        - destination:
            host: flaskapp.default.svc.cluster.local   # 服务的全限量名称  格式是  服务名.namespace 名称.svc.cluster.local
            port:
              number: 80          # 服务对外暴露的端口。
     (A)gateways:
      - galaxygateway 
    注意: 这里Virtualservice配置的规则针对
    galaxygateway其作用,而其属于网格外部的流量,对于网格内部流量不起作用,如果也想对网格内部的流量也其作用,这里需要把
          mesh也加上。

        (B) “*”

    如果:A:external-IP有值,说明环境中配置了负载均衡器,可以供ingress gateway使用。

              B: external-IP的值是none 或者pending,说明环境汇中没有负载均衡器,这种情况如果想直接访问gateway,就需要使用服务的node  port

                 

    Kubernetes的三种外部访问方式:NodePort、LoadBalancer和Ingress

    $ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
    $ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')

    NodePort 是31380,这个值可以改,但是范围只能是30000 - 32767。

    If routing to your application is required to run on 443/80, your Kubernetes cluster must have an external load balancer deployed.
    If one is not present, the traffic will be routed to the ingress node port.

    如果你的引用需要在443/80端口上跑,那么k8s集群必须有外部的负载均衡器,或者要使用node port。

    如何从外部访问呢:

      http://XXXXXXXXXXXXX.com:31380/env/version    ()

      curl 9.42.18.65:31380/env/version           用IP地址:port的方式访问,从这个来看,相当于L4的负载均衡器。

      
      curl -I -H Host:<域名>.com http://9.42.18.65:31380/env/version    # 在header里加上Host 伪装成gateway需要的HOSTS

           http://9.42.18.65:31380/env/version       # 必须指定ingress service 对外暴露的端口 31380

    总结:

    我上面的例子中,gateway 可以把指定的URL 告诉 ingress pod处理。 virtualservice对指定URL进行 service 调用

    1. Gateway: Istio Gateway是负责打开k8s上相关Istio的pods(pod!pod!pod!)上的端口并接收主机的流量,是接收流量与路由之间的关键链接。

    2. VirtualService: Istio VirtualService是“附加”到Gateway上的,并负责定义Gateway应实现的路由。可以将多个VirtualServices连接到Gateway,但不适用于同一个域。

  • 相关阅读:
    设计模式-策略模式
    java8 流式编程
    《JAVA8开发指南》使用流式操作
    linux如何查看端口被哪个进程占用?
    mac 启动php-fpm报错 failed to open configuration file '/private/etc/php-fpm.conf': No such file or direc
    Mac home 目录下创建文件夹
    UML由浅入深
    PHP扩展Swoole的代码重载机制
    Gedit中文乱码
    linux 内核源码arch/ 目录的前世今生
  • 原文地址:https://www.cnblogs.com/liufei1983/p/10433443.html
Copyright © 2011-2022 走看看