CodeBlanks Logo Icon CodeBlanks

Traffic yönetimi

Istio ile trafik yönlendirmeyi öğrenirsin.

Traffic yönetimi

Istio trafiği iki nesneyle yönetir: DestinationRule bir servisin alt kümelerini (subset, ör. sürümler) ve bağlantı ayarlarını tanımlar; VirtualService isteklerin hangi alt kümeye, hangi oranla gideceğini belirler. Kanarya dağıtımı için yeni sürüme trafiğin küçük bir yüzdesi verilir:

apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
  name: api
spec:
  host: api
  subsets:
    - name: v1
      labels: {surum: v1}
    - name: v2
      labels: {surum: v2}
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: api
spec:
  hosts: [api]
  http:
    - route:
        - destination: {host: api, subset: v1}
          weight: 90
        - destination: {host: api, subset: v2}
          weight: 10

Dayanıklılık ayarları

VirtualService yeniden deneme ve zaman aşımını; DestinationRule devre kesiciyi (aşırı hata veren örneği bir süre devreden çıkarma) tanımlar:

# VirtualService
  http:
    - route: [{destination: {host: api, subset: v1}}]
      timeout: 3s
      retries:
        attempts: 3
        perTryTimeout: 1s
        retryOn: 5xx,reset,connect-failure
# DestinationRule
  trafficPolicy:
    outlierDetection:
      consecutive5xxErrors: 5
      interval: 30s
      baseEjectionTime: 60s

Uygulama Kanarya yönlendirmesi

Bir VirtualService'in spec bölümünü yaz (spec: ile başlayarak): hosts: [api]; http altında tek route: api/v1'e weight: 80, api/v2'ye weight: 20; timeout: 3s.

Başlangıç kodu

terminal
# buraya yaz

Örnek çözüm

terminal
spec:
  hosts: [api]
  http:
    - route:
        - destination:
            host: api
            subset: v1
          weight: 80
        - destination:
            host: api
            subset: v2
          weight: 20
      timeout: 3s

Beklenen çıktı

virtualservice.networking.istio.io/api configured

Soru ve cevaplar

Dersin sorularını cevaplarıyla birlikte inceleyebilirsin. Kendini denemek istersen dersi interaktif olarak çöz.

1 Mesh olmadan iki Deployment ile kanarya yapınca oran nasıl belirlenir?

  • Rastgele
  • Service ağırlığıyla
  • Mümkün değildir
  • Kopya sayılarının oranıyla (ör. 9:1); mesh ile kopyadan bağımsız yüzde verilir Doğru cevap

Açıklama: Kubernetes Service'inde ağırlık alanı yoktur.

2 Yeni sürüme gidecek trafik oranını yaz.

Soru
        - destination: {host: api, subset: v2}
          ____: 10
Cevap
        - destination: {host: api, subset: v2}
          weight: 10

Açıklama: Ağırlıkların toplamı 100 olmalıdır.

3 Eşleştir.

Kavram Anlamı
DestinationRule Alt kümeler ve politika
VirtualService Yönlendirme kuralları
weight Trafik oranı
outlierDetection Devre kesici

Uzman bölümündeki tüm dersler