Istio ICA考试之路---3-2

发布于:2024-06-04 ⋅ 阅读:(145) ⋅ 点赞:(0)

1. 题目

Using Kubernetes context cluster-2 
In the sandbox namespace, create a VirtualService named api-vs for the host 
api.sandbox.svc.cluster.local with the following configurations:

Inject a 5 second delay for 20% of requests from the revision: dev workload. 
Route traffic to v1 (host api.sandbox.svc.cluster.local).
Inject an HTTP 500 failure for 50% of reffic to the v2 subset (host 
api.sandbox.svc.cluster.local).

2. 解题

2.1 获取模板

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
  hosts:
  - ratings
  http:
  - fault:
      delay:
        fixedDelay: 7s
        percentage:
          value: 100
    match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: ratings
        subset: v1
  - fault:
      delay:
        fixedDelay: 7s
        percentage:
          value: 100
    match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: ratings
        subset: v1

2.2 整理yaml

这里文档中省略了metadata的3行,可以从前面任意一个yaml复制粘贴过来

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: api-vs
  namespace: sandbox
spec:
  hosts:
  - api.sandbox.svc.cluster.local
  http:
  - fault:
      delay:
        fixedDelay: 5s
        percentage:
          value: 20
    match:
    - sourceLabels:
        revision: dev
    route:
    - destination:
        host: api.sandbox.svc.cluster.local
        subset: v1
  - fault:
      abort:
        httpStatus: 500
        percentage:
          value: 50
    route:
    - destination:
        host: api.sandbox.svc.cluster.local
        subset: v2

部署生效

kubectl apply -f 3-2.yaml

3. 测试

部署2个测试容器,分别是test和test2.test注入标签subset=v1

kubectl run --image nginx:1.25 test -n sandbox
kubectl run --image nginx:1.25 test2 -n sandbox
kubectl label po -n sandbox test subset=v1

通过test测试容器访问,20%概率触发延迟注入

time kubectl exec test -n sandbox -- curl -Is api.sandbox.svc.cluster.local

在这里插入图片描述
通过test2测试容器访问,50%概率触发500故障注入

or i in {1..10};do kubectl exec test2 -n sandbox -- curl -Is api.sandbox.svc.cluster.local|grep HTTP;done

发起20次请求,一共10次被500
在这里插入图片描述
此题完成


网站公告

今日签到

点亮在社区的每一天
去签到