当前位置:网站首页>5个 Istio 访问外部服务流量控制最常用的例子,你知道几个?
5个 Istio 访问外部服务流量控制最常用的例子,你知道几个?
2022-08-09 21:43:00 【InfoQ】
环境准备
sleep
kubectl apply -f samples/sleep/sleep.yaml
duckling
> curl -s http://192.168.1.118/
This is the v1 version of duckling.
> curl -s http://192.168.1.119/
This is the v2 version of duckling.
访问外部服务
export SLEEP_POD=$(kubectl get pods -l app=sleep -o 'jsonpath={.items[0].metadata.name}')
kubectl exec "$SLEEP_POD" -c sleep -- curl -s http://httpbin.org/headers
{
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"User-Agent": "curl/7.81.0-DEV",
"X-Amzn-Trace-Id": "Root=1-62bbfa10-3237e3b9662c65ae005148ab",
"X-B3-Sampled": "0",
"X-B3-Spanid": "9e650093bf7ae862",
"X-B3-Traceid": "1da46d7fafa5d71c9e650093bf7ae862",
"X-Envoy-Attempt-Count": "1",
"X-Envoy-Peer-Metadata": "......",
"X-Envoy-Peer-Metadata-Id": "sidecar~......"
}
}
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: httpbin-ext
spec:
hosts:
- httpbin.org
ports:
- number: 80
name: http
protocol: HTTP
resolution: DNS
location: MESH_EXTERNAL
EOF
{
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"User-Agent": "curl/7.81.0-DEV",
"X-Amzn-Trace-Id": "Root=1-62bbfbd6-254b05344b3cde2c0c41b3b8",
"X-B3-Sampled": "0",
"X-B3-Spanid": "307c0b106c8b262e",
"X-B3-Traceid": "f684a50776c088ac307c0b106c8b262e",
"X-Envoy-Attempt-Count": "1",
"X-Envoy-Decorator-Operation": "httpbin.org:80/*",
"X-Envoy-Peer-Metadata": "......",
"X-Envoy-Peer-Metadata-Id": "sidecar~......"
}
}
X-Envoy-Decorator-Operation
设置请求超时
export SLEEP_POD=$(kubectl get pods -l app=sleep -o 'jsonpath={.items[0].metadata.name}')
kubectl exec "$SLEEP_POD" -c sleep -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/delay/5
200
real 0m 5.69s
user 0m 0.00s
sys 0m 0.00s
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin-ext
spec:
hosts:
- httpbin.org
http:
- timeout: 3s
route:
- destination:
host: httpbin.org
weight: 100
EOF
504
real 0m 3.01s
user 0m 0.00s
sys 0m 0.00s
注入 HTTP 延迟故障
export SLEEP_POD=$(kubectl get pods -l app=sleep -o 'jsonpath={.items[0].metadata.name}')
kubectl exec "$SLEEP_POD" -c sleep -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/get
200
real 0m 0.45s
user 0m 0.00s
sys 0m 0.00s
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin-ext
spec:
hosts:
- httpbin.org
http:
- fault:
delay:
fixedDelay: 3s
percentage:
value: 100
route:
- destination:
host: httpbin.org
EOF
200
real 0m 3.43s
user 0m 0.00s
sys 0m 0.00s
流量转移
duckling
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: duckling
spec:
hosts:
- duckling.com
ports:
- number: 80
name: http
protocol: HTTP
location: MESH_EXTERNAL
resolution: STATIC
endpoints:
- address: 172.24.29.118
ports:
http: 80
labels:
version: v1
- address: 172.24.29.119
ports:
http: 80
labels:
version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: duckling
spec:
hosts:
- duckling.com
http:
- route:
- destination:
host: duckling.com
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: duckling
spec:
host: duckling.com
subsets:
- labels:
version: v1
name: v1
- labels:
version: v2
name: v2
EOF
export SLEEP_POD=$(kubectl get pods -l app=sleep -o 'jsonpath={.items[0].metadata.name}')
kubectl exec "$SLEEP_POD" -c sleep -- curl -s http://duckling.com/
This is the v1 version of duckling.
duckling
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: duckling
spec:
hosts:
- duckling.com
http:
- route:
- destination:
host: duckling.com
subset: v1
weight: 50
- destination:
host: duckling.com
subset: v2
weight: 50
EOF
This is the v1 version of duckling.
This is the v2 version of duckling.
duckling
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: duckling
spec:
hosts:
- duckling.com
http:
- route:
- destination:
host: duckling.com
subset: v2
EOF
This is the v2 version of duckling.
基于请求头的路由
end-user
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: duckling
spec:
hosts:
- duckling.com
ports:
- number: 80
name: http
protocol: HTTP
location: MESH_EXTERNAL
resolution: STATIC
endpoints:
- address: 172.24.29.118
ports:
http: 80
labels:
version: v1
- address: 172.24.29.119
ports:
http: 80
labels:
version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: duckling
spec:
hosts:
- duckling.com
http:
- match:
- headers:
end-user:
exact: OneMore
route:
- destination:
host: duckling.com
subset: v2
- route:
- destination:
host: duckling.com
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: duckling
spec:
host: duckling.com
subsets:
- labels:
version: v1
name: v1
- labels:
version: v2
name: v2
EOF
export SLEEP_POD=$(kubectl get pods -l app=sleep -o 'jsonpath={.items[0].metadata.name}')
kubectl exec "$SLEEP_POD" -c sleep -- curl -s http://duckling.com/
This is the v1 version of duckling.
end-user
kubectl exec "$SLEEP_POD" -c sleep -- curl -H "end-user:OneMore" -s http://duckling.com/
This is the v2 version of duckling.
边栏推荐
猜你喜欢
Synchronization lock synchronized traces the source
Unity2D_线框材质
Optimization of SQL Statements and Indexes
poj 3070 Fibonacci(简单矩阵连乘)
[Graphic and textual] How to reinstall Win7 system
Word怎么制作双面席卡?使用Word制作双面席卡方法
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
Word第一页空白页怎么删除?删除Word第一页空白页方法教程
蓝牙模块有哪些种类?BLE低功耗蓝牙模块有什么特点?
同步锁synchronized追本溯源
随机推荐
knn到底咋回事?
凸集与凸函数
Unity_物体自转
ACM MM 2022 | Cloud2Sketch: 长空云作画,AI笔生花
Cookie、session、token
《强化学习周刊》第57期:DL-DRL、FedDRL & Deep VULMAN
消防安全培训|“蓝朋友”,开课了!
[Graphic and textual] How to reinstall Win7 system
别叫我玩,我要考PMP:考PMP选择机构需要了解的那些事儿
题解:Edu Codeforces 109(div2)
简单问题窥见数学
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
LeetCode26: remove duplicates in sorted array
【stack】【queue】【priority_queue】【deque】详解
windos安装Mysql8.0,及解决重新登录异常问题 ERROR 1045 (28000)
STC8H development (15): GPIO drive Ci24R1 wireless module
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
The round functions in the np, ceil function and floor function
技术分享 | 接口自动化测试之JSON Schema模式该如何使用?
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles