索引總目錄:istio從入門到放棄系列
nginx
一、介紹
api
Istio 故障注入與其餘在網絡層引入錯誤(例如延遲數據包或者直接殺死 Pod)的機制不一樣,Istio 容許在應用程序層注入故障。這使得能夠注入更多相關的故障,好比 HTTP 錯誤代碼等。
bash
Istio 能夠注入兩種類型的故障,而這兩種故障都是使用虛擬服務來配置的:網絡
延遲:模擬增長網絡延遲或上游服務過載。
app停止:模擬服務故障而致使調用服務不可用。停止一般以 HTTP 錯誤代碼或 TCP 鏈接失敗表示
ide
二、故障延遲
spa
2.1 客戶端資源
orm
apiVersion: apps/v1 kind: Deployment metadata: name: client spec: replicas: 1 selector: matchLabels: app: client template: metadata: labels: app: client spec: containers: - name: busybox image: busybox imagePullPolicy: IfNotPresent command: [ "/bin/sh", "-c", "sleep 3600" ]
部署並使用istio注入,最終獲得如下server
2.2 服務端資源blog
apiVersion: v1 kind: Service metadata: name: nginx-svc spec: selector: server: nginx ports: - name: http port: 80 targetPort: 80 protocol: TCP --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx labels: server: nginx spec: replicas: 1 selector: matchLabels: server: nginx template: metadata: labels: server: nginx spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent
2.3 虛擬服務
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: test-vs spec: hosts: - nginx-svc http: - fault: delay: percentage: value: 100 fixedDelay: 10s route: - destination: host: nginx-svc
三、驗證故障注入
進入客戶端容器中,訪問nginx服務
kubectl exec -it client-8496866cdf-vkmcw /bin/sh
wget -q -O - http://nginx-svc
能夠看出時間延遲在十多秒,加上操做時間,和上面設置的時間是吻合的。
四、故障停止
修改虛擬服務文件
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: test-vs spec: hosts: - nginx-svc http: - fault: abort: percentage: value: 100 httpStatus: 503 route: - destination: host: nginx-svc
五、再次進入客戶端驗證
kubectl exec -it client-8496866cdf-vkmcw /bin/sh
wget -q -O - http://nginx-svc