Bài học

Ngày 83 - Istio Ambient Mesh

Tìm hiểu kiến trúc ambient và lab Istio không cần sidecar cho từng workload.

- 15 phút đọc

Nội dung khóa học

Ngày 83 - Istio Ambient Mesh
Mục lục

Ambient Mesh

Sau Ngày 82, chúng ta xem ambient mode của Istio, một cách đưa workload vào mesh mà không cần inject sidecar vào từng Pod. Ambient được giới thiệu năm 2022 và vẫn thuộc Istio.

Bài gốc viết khi ambient còn alpha và dùng Istio 1.18.0-alpha.0. Trạng thái, API và hỗ trợ nền tảng đã có thể thay đổi; xem tài liệu ambient hiện hành trước khi chọn phiên bản hoặc triển khai. Các khẳng định nguồn về K3s chỉ phản ánh thời điểm đó.

Kiến trúc và đánh đổi

Ambient có thể giảm nhu cầu inject và quản lý sidecar cho mỗi workload. Tác động lên CPU, memory, latency và vận hành phụ thuộc cấu hình, waypoint và workload; cần đo thực tế. Việc bật ambient không tự hoàn thành toàn bộ yêu cầu zero trust.

Các thành phần trong mô hình nguồn:

  • Istiod: control plane, cấu hình và certificate.
  • ztunnel: proxy layer 4 theo node, hỗ trợ danh tính, mTLS và policy layer 4.
  • Istio CNI: hướng lưu lượng workload vào data plane phù hợp.
  • Waypoint: proxy layer 7 ở phía đích, dùng cho các tính năng và policy layer 7 khi được cấu hình.
  • HBONE: cơ chế tunnel giữa các thành phần, sử dụng port được nêu trong nguồn là 15008.
Các lớp ambient

Xem bài viết kiến trúc bảo mật ambient và ztunnel viết bằng Rust. Không nên giả định mọi CRD hay tính năng sidecar có hành vi giống hệt trong mọi phiên bản ambient; kiểm tra tài liệu tương thích.

Lab lịch sử

Chỉ để đối chiếu nguồn: Các lệnh dưới đây cài bản alpha cũ và thay đổi cluster. Không dùng chúng làm hướng dẫn cài đặt production. Chọn bản được hỗ trợ, kiểm tra checksum và tài liệu hiện hành, rồi thử trong môi trường cô lập.

Tải và giải nén binary theo nguồn:

wget https://github.com/istio/istio/releases/download/1.18.0-alpha.0/istio-1.18.0-alpha.0-linux-amd64.tar.gz
tar -xf istio-1.18.0-alpha.0-linux-amd64.tar.gz istio-1.18.0-alpha.0/
cd istio-1.18.0-alpha.0/
export PATH=$PWD/bin:$PATH

Tạo cluster kind:

kind create cluster --config=- <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: ambient
nodes:
- role: control-plane
- role: worker
- role: worker
EOF
Creating cluster "ambient" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ Preparing nodes 📦 📦 📦
 ✓ Writing configuration 📜
 ✓ Starting control-plane 🕹️
 ✓ Installing CNI 🔌
 ✓ Installing StorageClass 💾
 ✓ Joining worker nodes 🚜
Set kubectl context to "kind-ambient"
You can now use your cluster with:

kubectl cluster-info --context kind-ambient

Thanks for using kind! 😊

Kiểm tra node:

kubectl get nodes -o wide

Cài ambient profile và xem output ví dụ:

istioctl install --set profile=ambient --skip-confirmation
marino@mwlinux02:~$ istioctl install --set profile=ambient --skip-confirmation
✔ Istio core installed
✔ Istiod installed
✔ CNI installed
✔ Ingress gateways installed
✔ Ztunnel installed
✔ Installation complete
Making this installation the default for injection and validation.

Kiểm tra Pod:

kubectl get pods -n istio-system
marino@mwlinux02:~$ kubectl get pods -n istio-system
NAME                                  READY   STATUS    RESTARTS   AGE
istio-cni-node-2wxwt                  1/1     Running   0          40s
istio-cni-node-6cptk                  1/1     Running   0          40s
istio-cni-node-khvbq                  1/1     Running   0          40s
istio-ingressgateway-cb4d6fd7-mcgtz   1/1     Running   0          40s
istiod-7596fdbb4c-8tfz8               1/1     Running   0          46s
ztunnel-frxrc                         1/1     Running   0          47s
ztunnel-lq4gk                         1/1     Running   0          47s
ztunnel-qbz6w                         1/1     Running   0          47s

Triển khai và kiểm tra ứng dụng

Triển khai Bookinfo, sleep và notsleep:

kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/sleep/sleep.yaml
kubectl apply -f samples/sleep/notsleep.yaml

Nguồn giới thiệu Gateway và VirtualService sau:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: bookinfo-gateway
spec:
  # The selector matches the ingress gateway pod labels.
  # If you installed Istio using Helm following the standard documentation, this would be "istio=ingress"
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080

Áp dụng:

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

Kiểm tra kết nối:

kubectl exec deploy/sleep -- curl -s http://istio-ingressgateway.istio-system/productpage | grep -o "<title>.*</title>"
kubectl exec deploy/sleep -- curl -s http://productpage:9080/ | grep -o "<title>.*</title>"
 kubectl exec deploy/notsleep -- curl -s http://productpage:9080/ | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>

Bật ambient cho namespace:

kubectl label namespace default istio.io/dataplane-mode=ambient

Chạy request và xem log ztunnel:

for i in {1..10}; do   kubectl exec deploy/notsleep -- curl -s http://productpage:9080/ | grep -o "<title>.*</title>";   sleep 1; done
kubectl logs -n istio-system -l app=ztunnel
2023-03-25T15:21:34.772090Z  INFO inbound{id=50c102c520ed8af1a79e89b9dc38c4ba peer_ip=10.244.1.4 peer_id=spiffe://cluster.local/ns/default/sa/notsleep}: ztunnel::proxy::inbound: got CONNECT request to 10.244.2.8:9080
2023-03-25T15:21:29.935241Z  INFO outbound{id=a9056d62a14941a70613094ac981c5e6}: ztunnel::proxy::outbound: proxy to 10.244.2.8:9080 using HBONE via 10.244.2.8:15008 type Direct

Output minh họa HBONE và danh tính workload trong lab của tác giả. Kiểm tra chính sách, mã hóa và telemetry của môi trường thực tế thay vì chỉ dựa trên một log.

Tóm tắt

Chúng ta đã xem các lớp ambient và quy trình lab lịch sử. Kết thúc phần service mesh, bạn có thể tìm hiểu thêm tại 70 Days of Service Mesh. Tiếp theo là Ngày 84.

Bài viết được chuyển ngữ từ Day 83 — 90DaysOfDevOps 2023, thuộc dự án 90DaysOfDevOps; ghi công Michael Cade và các cộng tác viên. Bản tiếng Việt có hiệu đính, bổ sung ghi chú và được chia sẻ theo giấy phép Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International. Sơ đồ được lấy từ bài viết Istio được nguồn tham chiếu.