zoukankan      html  css  js  c++  java
  • 特定消费者的限制流量

    Now, let's say we would like to give a specific consumer a higher rate-limit.

    For this, we can create a KongPlugin resource and then associate it with a specific consumer.

    First, create the KongPlugin resource:

    $ echo "
    apiVersion: configuration.konghq.com/v1
    kind: KongPlugin
    metadata:
      name: harry-rate-limit
    config:
      minute: 10
      limit_by: consumer
      policy: local
    plugin: rate-limiting
    " | kubectl apply -f -
    kongplugin.configuration.konghq.com/harry-rate-limit created

    Next, associate this with the consumer:

    echo "apiVersion: configuration.konghq.com/v1
    kind: KongConsumer
    metadata:
      name: harry
      annotations:
        plugins.konghq.com: harry-rate-limit
    username: harry" | kubectl apply -f -
    kongconsumer.configuration.konghq.com/harry configured

    Note the annotation being added to the KongConsumer resource.

    Now, if the request is made as the harry consumer, the client will be rate-limited differently:

    $ curl -I $PROXY_IP/foo -H 'apikey: sooper-secret-key'
    HTTP/1.1 200 OK
    Content-Type: text/html; charset=utf-8
    Content-Length: 9593
    Connection: keep-alive
    Server: gunicorn/19.9.0
    Date: Wed, 17 Jul 2019 22:34:10 GMT
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true
    X-RateLimit-Limit-minute: 10
    X-RateLimit-Remaining-minute: 9
    demo:  injected-by-kong
    X-Kong-Upstream-Latency: 3
    X-Kong-Proxy-Latency: 1
    Via: kong/1.2.1
    
    # a regular unauthenticated request
    $ curl -I $PROXY_IP/bar
    HTTP/1.1 200 OK
    Content-Type: text/plain; charset=UTF-8
    Connection: keep-alive
    Date: Wed, 17 Jul 2019 22:34:14 GMT
    Server: echoserver
    X-RateLimit-Limit-minute: 5
    X-RateLimit-Remaining-minute: 4
    demo:  injected-by-kong
    X-Kong-Upstream-Latency: 2
    X-Kong-Proxy-Latency: 1
    Via: kong/1.2.1
  • 相关阅读:
    剑指offer 整数中1出现的次数(从1到n整数中1出现的次数)
    剑指offer 把数组排成最小的数
    剑指offer 丑数
    剑指offer 字符串的排列
    剑指offer 数组中出现次数超过一半的数字
    剑指offer 最小的K个数
    操作系统 页面置换算法(C++实现)
    剑指offer 二叉搜索树与双向链表
    剑指offer 复杂链表的复制
    操作系统 银行家算法(C++实现)
  • 原文地址:https://www.cnblogs.com/justart/p/12436463.html
Copyright © 2011-2022 走看看