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
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Istio/Recheck] Hướng dẫn kiểm tra các feature của cụm istio mới cài lên đã work ngon lành chưa?

Posted on August 18, 2021November 23, 2021 By nim No Comments on [Istio/Recheck] Hướng dẫn kiểm tra các feature của cụm istio mới cài lên đã work ngon lành chưa?

Nếu bạn chưa cài istio thì sem bài sau nhé:

https://notes.nimtechnology.com/2021/08/05/su-dung-istio-operator-va-istioctl-de-cai-dat-istio/

Từ đây là bạn đã cài istio rồi nhé.

Để run 1 app hoàn chỉnh thì mình tham khảo yaml sau:

https://raw.githubusercontent.com/DickChesterwood/istio-fleetman/master/_course_files/1%20Telemetry/5-application-no-istio.yaml

Các bạn có thể lên udemy tìm khoá học về istio của anh này.

Dưới này là file của mình:

https://raw.githubusercontent.com/mrnim94/recheck-instio/main/deployment/deployment-test.yaml

Khi deploy sẽ ntn

đã có inject sidecar rồi

GIờ test kết nối tự pod có istio-proxy sem như thế nào thì mình mình có 1 hình minh hoạ chút

giờ bạn apply app busybox có inject sidecar rồi thử ping, curl ta lả ra ngoài he (vd: ping service khác, ping 8.8.8.8).

https://raw.githubusercontent.com/mrnim94/recheck-instio/main/busybox/busybox-deployment.yaml

Contents

Toggle
  • 1. Giờ chúng ta test vài tính năng của ingress gateway nhé.
    • 1.1 Test với service
    • 1.2 Test với service Headless các bạn lấy file manifest theo đường dẫn Git nhé
    • 1.3 Giờ thì ngịch canary chút
      • 1.3.1 canary by weight
      • 1.3.2 canary by header
    • 1.4 Test với Service GRPC (update thu 30 Sep 2021)
  • 2 Authentication
    • 2.1 Giờ Test mTLS and Authentication
    • 2.2 Giờ bạn muốn Force request là required HTTPS/mTLS:
    • 2.3 Enable mutual TLS per workload
    • 2.4 Giờ bạn muốn strict mTLS lên tất cả các port và ngoài trừ 1 vài port
    • 2.5 Thêm phần nữa là Policy precedence – Ưu tiên
    • 2.5 End-user authentication –> researching
  • 3. Authorization Policy
    • 3.1 Đầu tiên:
    • 3.2 Tiếp theo ví dụ nữa
  • 4 Envoy Filler
  • 5. ServiceEntry
  • 6. Cors Policy

1. Giờ chúng ta test vài tính năng của ingress gateway nhé.

1.1 Test với service

---
# Source: istio/templates/gateway.yaml
kind: Gateway
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: ingress-gateway-configuration
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - "fleetman-webapp.tiki.nimtechnology.com"
      port:
        name: http
        number: 80
        protocol: HTTP
---
# Source: istio/templates/virtualservice.yaml
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: fleetman-webapp
  namespace: default
spec:
  gateways:
    - "ingress-gateway-configuration"
  hosts:
    - "fleetman-webapp.tiki.nimtechnology.com"
  http:
    - name: fleetman-webapp.tiki.nimtechnology.com
      match:
        - uri:
            prefix: /
      route:
        - destination:
            host: fleetman-webapp
            port:
              number: 80

HÌnh chi tiết vãi
giải thích destination rule trỏ đến serivce nào?

Có bạn sẽ thắc mắc sao biết cài selector là istio:ingressgateway

chúng ta trở lại phần cài đặt istio thì bạn sẽ thấy có 1 deployment tên là istio-ingressgateway và được đánh label là istio: ingressgateway

Điều ngày nghĩa là ingress A mà bạn tạo cho các app A thì nó sẽ thuộc về isito-ingressgateway A và có trường hợp multi istio sẽ khá rõ về điều này.

giờ chúng ta kiểm tra lại ingress istio đang là ip bao nhiêu thì bạn vào dns hoặc file cấu hình cho domain đó thì phân giải ra ip đó

Truy cập như này là ngon.

1.2 Test với service Headless các bạn lấy file manifest theo đường dẫn Git nhé

https://github.com/mrnim94/recheck-instio/tree/main/deployment-service-headless

1.3 Giờ thì ngịch canary chút

Bạn chỉnh deploy lên replicate 1

1.3.1 canary by weight

Giờ mình cung cấp cho bạn 1 file vs và dr cho service staff-service

https://raw.githubusercontent.com/mrnim94/recheck-instio/main/deployment/combo-ingress-istio-staff-service.yaml

Giờ bạn apply thôi

curl phát sem nào:

while true; do curl http://fleetman-webapp.tiki.nimtechnology.com/api/vehicles/driver/City%20Truck; echo; sleep 0.5; done
Như này là ngon

Tiến hành cài đặt các addons của istio như: kiali, grafana, jaeger, …..

curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.11.0 TARGET_ARCH=x86_64 sh -
cd istio-1.11.0/samples/addons

kubectl -n istio-system apply -f grafana.yaml
kubectl -n istio-system apply -f jaeger.yaml
kubectl -n istio-system apply -f kiali.yaml
kubectl -n istio-system apply -f  prometheus.yaml
 Đây là thành quả

1.3.2 canary by header

Giờ có 1 cái khá hay trong istio “Dark Release” nghĩa là trên 1 tính math -> headers

Ví dụ môi trường Prod app version v1 đang chạy rồi bạn deploy app đó version 2 –> vậy làm sao để user bình thường vẫn vào v1 còn tester của bạn vào v2

thưc hiện applay yaml sau

https://raw.githubusercontent.com/mrnim94/recheck-instio/main/deployment/combo-ingress-istio-webapp-dark-release.yaml

Saù khi apply thì test kiểu j cho dễ

Bạn vào chrome tìm addons này nhé

Bình thường nếu ko thêm header thì nó sẽ ntn

Giờ bật header

Như này là đang chạy nhé

giở reload lại web

Khác rồi nè

1.4 Test với Service GRPC (update thu 30 Sep 2021)

https://istio.io/latest/docs/ops/configuration/traffic-management/protocol-selection/

Với các service GRPC như sau:

kind: Service
metadata:
  name: myservice
spec:
  ports:
  - name: grpc-0-80
    port: 80
    protocol: TCP
    targetPort: 80
  - name: http-1-8080
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    workload.user.cattle.io/workloadselector: nim-grpc-http

Istio có thể automatically detect có 2 cách

This can be configured in two ways:

  • By the name of the port: name: <protocol>[-<suffix>].
  • In Kubernetes 1.18+, by the appProtocol field: appProtocol: <protocol>.

The following protocols are supported:

  • http
  • http2
  • https
  • tcp
  • tls
  • grpc
  • grpc-web
  • mongo
  • mysql*
  • redis*
  • udp (UDP will not be proxied, but the port can be explicitly declared as UDP)
    Ở kube từ 1.18+ bạn có thể sài appProtocol ở service và ko cần khai báo prefix
kind: Service
metadata:
  name: myservice
spec:
  ports:
  - number: 3306
    name: database
    appProtocol: mysql
  - number: 80
    name: http-web
command check grpc
grpc_health_probe -addr localhost:80

2 Authentication

2.1 Giờ Test mTLS and Authentication

Bạn hiểu đơn gian là khi bạn triển khai proxy sidecar istio thì kết nối giữa các proxy là https/SSL và đây là thiết lập auto của istio -> app của bạn ko cần thay đổi gì nếu có triển khai isito nhe

Vậy nếu app ko có sidecar proxy istio gọi vào 1 app có sidecar proxy istio thì sao?

default là ở mode Permissive thì vẫn cho call http vào proxy
trên kiali bạn làm như hình là sẽ thấy các kết nối nào đang có mTLS

2.2 Giờ bạn muốn Force request là required HTTPS/mTLS:

Mình đang force trên ns default nhé!

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: default
  namespace: default
spec:
  mtls:
    mode: STRICT

xong bạn sửa service của fleetman-webapp thanh Nodeport để kiểm chứng mode Permissive:

chạy phà phà

apply PeerAuthentication

Không còn vào được nữa?
Đi qua Gateway, vs, dr Bình thường.

2.3 Enable mutual TLS per workload

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: "web-app"
  namespace: "default"
spec:
  selector:
    matchLabels:
      app: webapp
  mtls:
    mode: STRICT
thể hiện peerAuthen chọn đúng workload nào

Bạn cần sửa destiantion rule nữa vì đây là mình force strict mTLS cho 1 deployment

# Source: istio/templates/virtualservice.yaml
kind: DestinationRule
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: fleetman-webapp
  namespace: default
spec:
  host: fleetman-webapp
  trafficPolicy:
    tls:
      mode: ISTIO_MUTUAL
  subsets:
    - labels:
        version: original
      name: original
    - labels:
        version: experimental
      name: experimental

2.4 Giờ bạn muốn strict mTLS lên tất cả các port và ngoài trừ 1 vài port

all service(not required inject sidecar proxy istio) —–still connected—-> port 80 of service A
all service(required inject sidecar proxy istio) –connected–> all port left (các port còn lại) of service A

(PeerAuthentication) argocd đang bị lỗi

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: "web-app"
  namespace: "default"
spec:
  selector:
    matchLabels:
      app: webapp
  mtls:
    mode: STRICT
  portLevelMtls:
    80:
      mode: DISABLE

## đang lỗi
## admission webhook “validation.istio.io” denied the request: configuration is invalid: mesh/namespace peer authentication cannot have port level mTLS
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: "httpbin"
spec:
  host: httpbin.bar.svc.cluster.local
  trafficPolicy:
    tls:
      mode: ISTIO_MUTUAL
    portLevelSettings:
    - port:
        number: 8000
      tls:
        mode: DISABLE

2.5 Thêm phần nữa là Policy precedence – Ưu tiên

Đầu tiên bạn tạo 1 Strict mTLS cho cả namespace.

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: default
  namespace: default
spec:
  mtls:
    mode: STRICT

xong bạn cho 1 deployment được disable Strict mTLS

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: web-app
  namespace: default
spec:
  mtls:
    mode: DISABLE
  selector:
    matchLabels:
      app: webapp
###thêm disable cho dr nhé

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: fleetman-webapp
  namespace: default
spec:
  host: fleetman-webapp
  subsets:
    - labels:
        version: original
      name: original
    - labels:
        version: experimental
      name: experimental
  trafficPolicy:
    tls:
      mode: DISABLE

các bạn có thể test thử với các mode khác:

https://istio.io/latest/docs/reference/config/security/peer_authentication/#PeerAuthentication-MutualTLS-Mode

2.5 End-user authentication –> researching

3. Authorization Policy

3.1 Đầu tiên:

  • service A —-deny—> service B
  • all service —->allow—> service B
  • gt -> vs -> dr -> service B

Để làm được điều này thì:

bật strict mode trên namespace và workload mà bạn muốn bật author, Ở ví dụ này thì là service B và strict trên ns nhé!

# cấu hình authen

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  labels:
  name: default
  namespace: default
spec:
  mtls:
    mode: STRICT

cấu hình mở tất cả, chặn 1 vài thằng và chặn get

#cấu hình author

apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: default
  namespace: default
spec:
  action: DENY
  rules:
    - from:
        - source:
            namespaces:
              - author-istio
      to:
        - operation:
            methods:
              - GET

Trước đó mình có create 1 ns và workload author-istio, tiến hành curl liên tục và kiểm tra.

while true; do curl http://fleetman-webapp.default/api/vehicles/driver/City%20Truck; echo; sleep 0.5; done
apply AuthorizationPolicy và deny
root@work-space-u20:~# kubectl -n author-outline-istio get pod
NAME                                  READY   STATUS    RESTARTS   AGE
busybox-deployment-6bc9c96d4b-zknzq   2/2     Running   0          2m6s

kubectl -n author-outline-istio exec -it busybox-deployment-6bc9c96d4b-zknzq -c busybox -- sh

# curl http://fleetman-webapp.default/api/vehicles/driver/City%20Truck
{"name":"Pam Parry","photo":"https://rac-istio-course-images.s3.amazonaws.com/1.jpg"}

workload này có istio nhưng namespace ko bị deny tới defaul và vẫn có kêt nối

3.2 Tiếp theo ví dụ nữa

  • Serive A –allow–> service B
  • all service —deny-> service B
  • gt->vs->dr –deny–> service B (chỗ này chưa allow được, chưa rõ usecase thực tế có cần không?)

Chỗ này chỉ rõ namespace và selector của workload

Kiểm tra workload

apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  labels:
    app.kubernetes.io/instance: ingress-istio-apptest
  name: default
  namespace: default
spec:
  selector:
   matchLabels:
     app: webapp
  action: ALLOW
  rules:
    - from:
        - source:
            namespaces:
              - author-istio
      to:
        - operation:
            methods:
              - GET
            paths: ["/ap*"]
chặn paths quá ghê
Ta thấy Chỉ có namespace author-istio connected webapp

Có Điều lưu ý là phần ALLOW với ver 1.9.7 thì nếu ko có selector -> matchLabels nó sẽ không allow, kiểu phải chỉ rõ mày muốn allow cho ai và tao sẽ chặn all

các link tham khảo author

https://istio.io/latest/docs/reference/config/security/authorization-policy/#Source

https://istio.io/latest/docs/concepts/security/#allow-all-and-deny-all

https://istiobyexample.dev/authorization/

4 Envoy Filler

Các bài test envoy thì được cập nhật ở bài viết bên dưới:

https://notes.nimtechnology.com/2021/09/05/istio-recheck-envoy-test-cac-features-lien-quan-den-envoy/

5. ServiceEntry

Cái này bạn có thể hiểu là: app web của bạn ở trong k8s sẽ kết nối với mysql ở ngoại cluster k8s và app của bạn kết nối đến db mysql bằng domain. (vd: mysql.nimtechnology.com)

Link tham khảo:

https://istio.io/latest/docs/ops/configuration/traffic-management/protocol-selection/#explicit-protocol-selection

https://imroc.cc/istio/best-practice/specify-protocol/

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: external-mysql
spec:
  hosts:
  - mysql.example.com
  location: MESH_EXTERNAL
  ports:
  - number: 4000
    name: mysql
    protocol: mysql
  resolution: DNS
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: httpbin-fleetman-webapp
spec:
  hosts:
  - fleetman-webapp.nimtechnology.com
  ports:
  - number: 80
    name: http
    protocol: HTTP
  resolution: DNS
  location: MESH_EXTERNAL
>>>update Tue 9 Nov 2021
>>>>>>>>>>>>>>>>>>>>>>>>
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: vm-postgresql
  namespace: default
spec:
  hosts:
  - vm-postgresql.nimtechnology.com
  addresses:
  - 10.8.3.240/32
  ports:
  - number: 5432
    name: ps-port
    protocol: TCP
  location: MESH_EXTERNAL
>>>update Tue 23 Nov 2021
>>>>>>>>>>>>>>>>>>>>>>>>
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: external-svc-wikipedia
spec:
  hosts:
  - wikipedia.org
  location: MESH_EXTERNAL
  ports:
  - number: 80
    name: example-grpc
    protocol: GRPC
  resolution: DNS

More detain —> Coming soon

6. Cors Policy

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  labels:
    app.kubernetes.io/instance: fulfillment-api-argocd-app
  name: fulfillment-api.nimtechnology.com
  namespace: fulfillment
spec:
  gateways:
    - mesh
    - fulfillment-api-dev-tiki-services
  hosts:
    - fulfillment-api.nimtechnology.com
  http:
    - corsPolicy:
        allowHeaders:
          - Origin
          - Authorization
          - Access-Control-Allow-Origin
          - Apikey
          - Token
          - Station
          - Warehouse
          - Clientversion
          - Content-Type
        allowOrigins:
          - exact: 'https://fulfillment-admin.nimtechnology.com'
      match:
        - uri:
            prefix: /admin
      name: fulfillment-admin-api-80
      route:
        - destination:
            host: fulfillment-admin-api.fulfillment.svc.cluster.local
            port:
              number: 80
Isito-EnvoyFilter, Kubernetes & Container

Post navigation

Previous Post: [Popup/Ajax] Tạo popup(modal/bootstrap) insert data bằng ajax và php
Next Post: [kiali/istio] Fix issue Configured: configmaps “istio” not found

More Related Articles

[Udemy] Download khóa học Udemy giá rẻ chỉ với 50k/khóa Kubernetes & Container
[Istio/multi cluster] Install multi-cluster Istio with mode “Primary-Remote” for Kubernetes on Google Cloud Platform. Isito-EnvoyFilter
[Kubernetes] Lesson5: k8s easy – Multi-container, Probes Kubernetes & Container
[ArgoCD] Hướng dẫn tạo “local user” trên argocd ArgoCD
[istio] There are a few problems inside mode “POD to POD” when using Istio Isito-EnvoyFilter
[letsencrypt] DST Root CA X3 Expiration (September 2021) BareMetal

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

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • 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
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.