Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log & Monitor
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Istio/Recheck Envoy] Test các features liên quan đến EnvoyFilter trên Istio .

Posted on September 5, 2021January 13, 2022 By nim 1 Comment on [Istio/Recheck Envoy] Test các features liên quan đến EnvoyFilter trên Istio .

ps: các EnvoyFilter này mình không áp dụng được cho Service Headless

Chúng ta có câu lênh loop curl sẽ sài nhiều

while true; do curl http://fleetman-webapp.nimtechnology.com; echo; sleep 0.5; done

Contents

  • Envoy – Istio
    • 4.1) X-Forwarded-For
    • 4.2) max-body-size (upload/download file)
    • 4.3 Partially enable accesslog
      • 4.3.1) access log TCP
      • 4.3.2) Access log http
      • 4.3.3 turn debug log by command (update Thu, January 13th, 2021)
    • 4.4. Rate Limit
      • 4.4.1 Global rate limit
        • 4.4.1.1 filter-ratelimit-svc của Global rate limit
        • 4.4.1.2 filter-ratelimit-svc của Local rate limit

Envoy – Istio

4.1) X-Forwarded-For

Lần các sẽ test là apply của bạn có nhận được IP Public của User hay không?

các bạn sử file yaml trong github này:
https://github.com/mrnim94/recheck-instio/tree/main/xff

Mô hình của mình là

App(httpbin) <– ingress-istio(192.168.101.221) <– Kong gateway(192.168.101.9) <– fortigate <– router(internet)

trên kiali
>>>Bạn chạy câu lệnh này

curl -s -H 'X-Forwarded-For: 56.5.6.7, 72.9.5.6, 98.1.2.3' fleetman-webapp.nimtechnology.com/get?show_env=true

Anh em sẽ hỏi ủa ip của Kong âu

https://blog.wescale.fr/2020/02/20/istio-k8s/

Chúng ta sem bài viết trên

Step one: Disable the SNAT kube-proxy

In order for the Ingress Gateway Envoy to add the x-envoy-external-address header, you must first bypass the kube-proxy. In order to achieve this, we must patch the ingress-gateway service by passing the value of externalTrafficPolicy to Local instead of Cluster:

kubectl -n istio-system patch svc istio-ingressgateway -p '{"spec":{"externalTrafficPolicy":"Local"}}'

Ở đoạn tiếp theo họ bảo cấu hình envoy filter/xff_num_trusted_hops nhưng ở lap của mình ko cấu hình thấy vẫn show ip ầm ầm chưa hiều lắm

Ở version 1.8+ istio có thể cấu hình xff_num_trusted_hops bằng file operator

https://istio.io/latest/docs/ops/configuration/traffic-management/network-topologies/

https://istio.io/latest/blog/2020/show-source-ip/

Giờ cấu hình xff_num_trusted_hops và chỉ định rõ namespace và workload

File yaml ở link dưới
https://github.com/mrnim94/recheck-instio/tree/main/xff

>>>>>>dùng lệnh này để curl

while true; do curl http://fleetman-webapp.nimtechnology.com/ip; echo; sleep 0.5; done
Thử sem IP mới thêm là gì
Đây là IP của istio-ingressgateway

4.2) max-body-size (upload/download file)

Cái này là khi anh em upload file hay load file nặng thì bị thông báo là “Payload Too Large”

các link để anh em tham khảo:

https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/

https://github.com/istio/istio/issues/26152

Global Mesh Options

Đường links file yaml

https://github.com/mrnim94/recheck-instio/tree/main/deployment-upload-file

Thành quả sau khi apply
Sem cấu hình file envoy

Update Mon 6 Sep

Chúng ta có thể áp EnvoyFilter chỉ định namespace về default và workloadSelector về deployment nhất định.

4.3 Partially enable accesslog

  • Enable Envoy’s access logging

https://istio.io/latest/docs/tasks/observability/logs/access-log/

cái này giống như cấu hình global trên toàn cluster istio, thì bạn cấy hình access-log thông qua operator.

spec:
  meshConfig:
    accessLogFile: /dev/stdout

Cá nhân mình nghĩ thì ko khuyển khích này gì nên workload nào cũng sinh ra log access sẽ rất tốn về volume ở những hệ thống lớn.

  • Enable accesslog for some namespaces or workloads

https://imroc.cc/istio/trick/partially-enable-accesslog/

Các này sẽ tối ưu về resource hơn nhưng sẽ khá phức tạp vì sẽ cần cấu hình EnvoyFilter

Bạn cần deploy 3 workload như ảnh.
mình sẽ cung cấp file yaml

Giờ ta cấu hình access log trên 1 namespace mà ta muốn

Khi bạn chưa apply EnvoyFilter log access thì nó ko sinh ra log ở proxy

Giờ làm sao coi log của isito-proxy, mình dùng rancher nhé

Đây là màn hình hiển thị log container trên rancher và bạn đợi mãi mà chúng ta chả thấy gì
Vì đã cấu hình đâu mà có.
apply envoy filter thôi
>>>Bạn curl liên lục vào thanh niên repeater

while true; do curl -sS fleetman-webapp.nimtechnology.com\?addr\=http://go-demo-8; echo; sleep 0.5; done
Bạn thấy show như hình là curl đúng nhé
Giờ quay lại proxy log bán như mưa. bạn kiểm tra 2 các workload web đều có log nhé
(DB thì không có log access đâu nhé.)

Chỉ định 1 workload cụ thể:

Chỉ bạn cách lấy workload selector cho đúng

Giờ bạn apply lại envoy mới sửa, rối nhớ redeploy các workload trong ns default nhé.

Sau khi update thì sẽ thây envoy ngả vàng, ấn sync thôi

giờ bạn kiểm tra lại thì thanh niên repeater có log access còn thanh niên go-demo-8 thì ko có log access.
anh em kéo lên hình ở trên rồi tưởng tưởng nó show như nào giúp mình nhé chụp nhiều mọi tay quá.

4.3.1) access log TCP

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: arcturus-access-log
  namespace: marketplace 
spec:
  configPatches:
  - applyTo: NETWORK_FILTER
    match:
      listener:
        filterChain:
          filter:
            name: envoy.filters.network.tcp_proxy
    patch:
      operation: MERGE
      value:
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
          access_log:
          - name: envoy.access_loggers.file
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
              format: |
                [%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% "%DYNAMIC_METADATA(istio.mixer:status)%" "%UPSTREAM_TRANSPORT_FAILURE_REASON%" %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%" %UPSTREAM_CLUSTER% %UPSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_REMOTE_ADDRESS% %REQUESTED_SERVER_NAME% %ROUTE_NAME%
              path: /dev/stdout
  workloadSelector:
    labels:
      workload.user.cattle.io/workloadselector: nimtechnology

4.3.2) Access log http

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: enable-accesslog
  namespace: default
spec:
  workloadSelector:
    labels:
      app: repeater
  configPatches:
  - applyTo: NETWORK_FILTER
    match:
      context: ANY
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
    patch:
      operation: MERGE
      value:
        typed_config:
          "@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
          access_log:
          - name: envoy.access_loggers.file
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
              path: "/dev/stdout"
              log_format:
                json_format:
                  authority: "%REQ(:AUTHORITY)%"
                  bytes_received: "%BYTES_RECEIVED%"
                  bytes_sent: "%BYTES_SENT%"
                  downstream_local_address: "%DOWNSTREAM_LOCAL_ADDRESS%"
                  downstream_remote_address: "%DOWNSTREAM_REMOTE_ADDRESS%"
                  duration: "%DURATION%"
                  method: "%REQ(:METHOD)%"
                  path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
                  protocol: "%PROTOCOL%"
                  request_id: "%REQ(X-REQUEST-ID)%"
                  requested_server_name: "%REQUESTED_SERVER_NAME%"
                  response_code: "%RESPONSE_CODE%"
                  response_flags: "%RESPONSE_FLAGS%"
                  route_name: "%ROUTE_NAME%"
                  start_time: "%START_TIME%"
                  upstream_cluster: "%UPSTREAM_CLUSTER%"
                  upstream_host: "%UPSTREAM_HOST%"
                  upstream_local_address: "%UPSTREAM_LOCAL_ADDRESS%"
                  upstream_service_time: "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%"
                  upstream_transport_failure_reason: "%UPSTREAM_TRANSPORT_FAILURE_REASON%"
                  user_agent: "%REQ(USER-AGENT)%"
                  x_forwarded_for: "%REQ(X-FORWARDED-FOR)%"
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: test-enable-accesslog
spec:
  workloadSelector:
    labels:
      workload.user.cattle.io/workloadselector: deployment-platform-prod-prod-eris
  configPatches:
  - applyTo: NETWORK_FILTER
    match:
      listener:
        filterChain:
          filter:
            name: envoy.filters.network.http_connection_manager
    patch:
      operation: MERGE
      value:
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          access_log:
          - name: envoy.access_loggers.file
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
              format: |
                [%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% "%DYNAMIC_METADATA(istio.mixer:status)%" "%UPSTREAM_TRANSPORT_FAILURE_REASON%" %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%" %UPSTREAM_CLUSTER% %UPSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_REMOTE_ADDRESS% %REQUESTED_SERVER_NAME% %ROUTE_NAME%
              path: /dev/stdout

Link file manifest:

https://github.com/mrnim94/recheck-instio/tree/main/deployment-log-access

4.3.3 turn debug log by command (update Thu, January 13th, 2021)

Còn cách nữa tiện hơn là bạn exec thẳng vào pod istio-proxy và gõ comand:

curl -XPOST 'localhost:15000/logging?level=debug'

4.4. Rate Limit

Các bạn nào hay sài auto Click để click liên tục vào nút của app hay web, được 1 lúc thì nhận ra là mình đã bị chặn. Thì khả năng cao đó là rate limit nhé.

4.4.1 Global rate limit

https://istio.io/latest/docs/tasks/policy-enforcement/rate-limit/#local-rate-limit

Cấu hình Config map

Đây là config map simple nhất

Sau khi chuẩn bị xong config giờ ta cài workload ratelimit trên namespace isito-system nhé

File ở đây nhé
https://github.com/mrnim94/recheck-instio/tree/main/rate-limit/workload-ratelimit

Sau khi deploy

Tiếp theo bạn cần cấu hình 2 Envoy Filter

Giải thích sơ về applyto Cluster
Giải thích sơ vể applyto HTTP_Filter

File Nó ở link này, Bạn cần đọc nhiều tài liệu bên ngoài để hiểu hơn nhé
https://github.com/mrnim94/recheck-instio/blob/main/rate-limit/envoy-filter-ratelimit-to-ingressgateway-istio-system/filter-ratelimit.yaml

Giờ bạn apply file trên thì vẫn chưa có điều j sảy ra.

Giờ apply file bên trên

https://github.com/mrnim94/recheck-instio/blob/main/rate-limit/envoy-filter-ratelimit-to-ingressgateway-istio-system/filter-ratelimit-svc.yaml

Đúng như yêu cấu của chúng ta
Ảnh từ kiali
4.4.1.1 filter-ratelimit-svc của Global rate limit

ở Phần này chúng ta vọc file filter-ratelimit-svc.yaml

Test vhost -> domain:port

https://istio.io/latest/docs/reference/config/networking/envoy-filter/#EnvoyFilter-RouteConfigurationMatch-VirtualHostMatch

chỉnh đúng host mà sai port
web của chúng ra đi thông luôn
Chỉnh lại cho Đúng host và port
Đặt ratelimit với path /ip với đúng domain và port

Có 1 điều là khi mình đứng ở PC khác cũng truy cập vào http://fleetman-webapp.nimtechnology.com/ip
thi cũng bị nhận HTTP ERROR 429.
–> đang ratelimit theo kiểu tui hết vé rồi không bán cho ai nữa, 1phút có 1 vé thôi ai nhanh thì có.


Giờ có phần mà mình khá cần thiết là trong file này làm sao xác định action cho đúng với yêu cầu

Từ này đến giờ chúng ta rate limit theo path đúng hem.
path ở đây cũng là một header nhé, chỉ cho các bạn thấy

chúng ta lấy request headers name để ratelimit path

Giờ kiếm “request_headers” trong action envoyfilter

https://www.envoyproxy.io/docs/envoy/v1.19.1/api-v3/http_routes/http_routes#

4.4.1.2 filter-ratelimit-svc của Local rate limit

Envoy supports local rate limiting of L4 connections and HTTP requests. This allows you to apply rate limits at the instance level, in the proxy itself, without calling any other service.

https://github.com/mrnim94/recheck-instio/tree/main/local-ratelimit/example1

Trong file envoyfilter thì chú ý như sau

The local rate limit filter’s token bucket is configured to allow 10 requests/min

The filter is also configured to add an x-local-rate-limit response header to requests that are blocked

Đây là response trả về

Ở phần trên chúng ta chỉ select workload và nó áp lên all vhosts/routes

Giờ bạn muốn chỉ định all vhosts/routes một cách rõ ràng thì sao

Link file yaml
https://github.com/mrnim94/recheck-instio/tree/main/local-ratelimit/example2

Isito-EnvoyFilter, Kubernetes & Container

Post navigation

Previous Post: [Kaniko/Jenkins] Install Jenkins through helm and build/deploy app in K8s by Kaniko
Next Post: [Helm Chart] Tìm hiểu fullnameOverride và .fullname trong helm chart.

More Related Articles

[Chartmuseum] Build yourself a Helm Chart Repository server Kubernetes & Container
[Harbor] Install harbor(private docker hub) On k8s through helm and repo goharbor Harbor
[Harbor] Cài đặt Private Dockerhub – Harbor trên k8s bằng helm – repo Binami Harbor
[Istio] OMG – Metric of an Istiod pod had 2 versions. Why??? Isito-EnvoyFilter
[Upgrade Canary Istio Cluster] Do you want to upgrade the new version for Your Multi-Cluster Isito? Welcome to Nimtechnology. Very easy!!! That right. Isito-EnvoyFilter
[Harbor] Configure the replications on Harbor Harbor

Comment (1) on “[Istio/Recheck Envoy] Test các features liên quan đến EnvoyFilter trên Istio .”

  1. Pingback: [Istio/Recheck] Hướng dẫn kiểm tra cụm istio mới cài lên đã work ngon lành chưa? – NimTechnology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • Experiences for IP Addresses Shortage on EKS Clusters March 29, 2023
  • [Talisman] Discover the sensitive information in your code. March 28, 2023
  • [Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. March 27, 2023
  • [Kong Gateway] WebSocket connection failed March 26, 2023
  • [Nextcloud] Can’t download files to have a size bigger than 2Gi on NextCloud – RaspBerry March 24, 2023

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • MetalLB
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.