Istio超时

- 将nginx-service这里设置超时为1s,httpd设置延迟请求为5s,会导致nginx无法及时收到数据,从而模拟服务之间调用的超时情况
测试yaml
[root@k8s-master-1 example-v1]
apiVersion: v1
kind: Namespace
metadata:
name: timeout
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
namespace: timeout
data:
nginx.conf: |-
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
location / {
proxy_pass http://httpd.timeout.svc.cluster.local;
proxy_http_version 1.1;
}
}
}
[root@k8s-master-1 example-v1]
---
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: timeout
spec:
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: httpd
namespace: timeout
spec:
selector:
app: httpd
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: timeout
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
---
apiVersion: v1
kind: Pod
metadata:
name: httpd
namespace: timeout
labels:
app: httpd
spec:
containers:
- name: httpd
image: busybox:1.28
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","echo 'this is busybox-httpd' > /var/www/index.html;httpd -f -h /var/www"]
---
apiVersion: v1
kind: Pod
metadata:
name: busybox
spec:
containers:
- name: busybox
image: busybox:1.28
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","sleep 360000"]
[root@k8s-master-1 example-v1]
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: nginx
namespace: timeout
spec:
hosts:
- nginx.timeout.svc.cluster.local
http:
- route:
- destination:
host: nginx.timeout.svc.cluster.local
timeout: 1s
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: httpd
namespace: timeout
spec:
hosts:
- httpd.timeout.svc.cluster.local
http:
- fault:
delay:
percent: 100
fixedDelay: 5s
route:
- destination:
host: httpd.timeout.svc.cluster.local
---
部署
[root@k8s-master-1 example-v1]
namespace/timeout created
configmap/nginx-conf created
[root@k8s-master-1 example-v1]
service/nginx created
service/httpd created
pod/nginx created
pod/httpd created
pod/busybox created
[root@k8s-master-1 example-v1]
virtualservice.networking.istio.io/nginx created
virtualservice.networking.istio.io/httpd created
测试
[root@k8s-master-1 example-v1]
Defaulting container name to busybox.
Use 'kubectl describe pod/busybox -n default' to see all of the containers in this pod.
real 0m 5.00s
user 0m 0.00s
sys 0m 0.00s
this is busybox-httpd
[root@k8s-master-1 example-v1]
Defaulting container name to busybox.
Use 'kubectl describe pod/busybox -n default' to see all of the containers in this pod.
wget: server returned error: HTTP/1.1 504 Gateway Timeout
Command exited with non-zero status 1
real 0m 1.05s
user 0m 0.00s
sys 0m 0.00s
command terminated with exit code 1