测试yaml
[root@k8s-master-1 example-v1]
apiVersion: v1
kind: Namespace
metadata:
name: circuit-break
---
apiVersion: v1
kind: Service
metadata:
name: busybox-httpd
namespace: circuit-break
spec:
ports:
- name: http
port: 80
targetPort: 80
selector:
app: httpd
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox-httpd
namespace: circuit-break
spec:
replicas: 1
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: busybox-httpd
image: busybox:1.28
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
command: ["/bin/sh","-c","echo 'this is busybox-httpd' > /var/www/index.html;httpd -f -h /var/www"]
[root@k8s-master-1 example-v1]
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: busybox-httpd
namespace: circuit-break
spec:
host: busybox-httpd.circuit-break.svc.cluster.local
trafficPolicy:
connectionPool:
http:
http1MaxPendingRequests: 1
maxRequestsPerConnection: 1
tcp:
maxConnections: 1
outlierDetection:
baseEjectionTime: 3m
consecutive5xxErrors: 1
interval: 1s
maxEjectionPercent: 100
[root@k8s-master-1 example-v1]
apiVersion: v1
kind: Service
metadata:
name: fortio
namespace: circuit-break
labels:
app: fortio
service: fortio
spec:
ports:
- port: 8080
name: http
selector:
app: fortio
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fortio-deploy
namespace: circuit-break
spec:
replicas: 1
selector:
matchLabels:
app: fortio
template:
metadata:
annotations:
proxy.istio.io/config: |-
proxyStatsMatcher:
inclusionPrefixes:
- "cluster.outbound"
- "cluster_manager"
- "listener_manager"
- "server"
- "cluster.xds-grpc"
labels:
app: fortio
spec:
containers:
- name: fortio
image: fortio/fortio:latest_release
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http-fortio
- containerPort: 8079
name: grpc-ping
部署
[root@k8s-master-1 example-v1]
namespace/circuit-break created
service/busybox-httpd created
deployment.apps/busybox-httpd created
[root@k8s-master-1 example-v1]
destinationrule.networking.istio.io/busybox-httpd created
[root@k8s-master-1 example-v1]
service/fortio configured
deployment.apps/fortio-deploy configured
模拟请求
在 DestinationRule 配置中,您定义了 maxConnections: 1 和 http1MaxPendingRequests: 1 。这些规则意味着,如果并发的连接和请求数超过一个,在 istio-proxy 进行进一步的请求和连接时,后续请求或连接将被阻止
[root@k8s-master-1 example-v1]
............................................................
Sockets used: 9 (for perfect keepalive, would be 2)
Jitter: false
Code 200 : 12 (60.0 %)
Code 503 : 8 (40.0 %)
Response Header Sizes : count 20 avg 130.8 +/- 106.8 min 0 max 218 sum 2616
Response Body/Total Sizes : count 20 avg 240.4 +/- 0.4899 min 240 max 241 sum 4808
All done 20 calls (plus 0 warmup) 4.064 ms avg, 442.0 qps
[root@k8s-master-1 example-v1]
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.circuit_breakers.default.remaining_pending: 1
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.circuit_breakers.default.rq_pending_open: 0
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.circuit_breakers.high.rq_pending_open: 0
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.upstream_rq_pending_active: 0
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.upstream_rq_pending_failure_eject: 0
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.upstream_rq_pending_overflow: 47
cluster.outbound|80||busybox-httpd.circuit-break.svc.cluster.local.upstream_rq_pending_total: 57
|