[root@k8s-master-1 example-v1]# kubectl apply -f nginx-conf.yaml
namespace/timeout created
configmap/nginx-conf created
# busybox测试容器也需要注入,否则没有超时效果,除非从gateway进入的流量[root@k8s-master-1 example-v1]# istioctl kube-inject -f deployment.yaml | kubectl apply -f -
service/nginx created
service/httpd created
pod/nginx created
pod/httpd created
pod/busybox created
[root@k8s-master-1 example-v1]# kubectl apply -f istio.yaml
virtualservice.networking.istio.io/nginx created
virtualservice.networking.istio.io/httpd created
测试
# 可以发现访问httpd服务存在5秒的延迟[root@k8s-master-1 example-v1]# kubectl exec busybox -- time wget -q -O - http://httpd.timeout.svc.cluster.local
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
# 访问nginx,可以发现报了504超时错误[root@k8s-master-1 example-v1]# kubectl exec busybox -- time wget -q -O - http://nginx.timeout.svc.cluster.local
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