⑥. Ingress的限流操作
- ①. 在master进行如下的命令操作
[root@k8smaster ~]# kubectl apply -f ingress-limit-rule.yaml ingress.networking.k8s.io/ingress-limit-rate created [root@k8smaster ~]# kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE ingress-host-bar nginx hello.xiaozhi.com,demo.xiaozhi.com 192.168.68.145 80 21m ingress-limit-rate nginx haha.xiaozhi.com 80 8s [root@k8smaster ~]# kubectl get svc -A |grep ingress ingress-nginx ingress-nginx-controller NodePort 10.96.183.241 <none> 80:32128/TCP,443:31148/TCP 169m ingress-nginx ingress-nginx-controller-admission ClusterIP 10.96.31.69 <none> 443/TCP 169m
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-limit-rate annotations: nginx.ingress.kubernetes.io/limit-rps: "1" spec: ingressClassName: nginx rules: - host: "haha.xiaozhi.com" http: paths: - pathType: Exact path: "/" backend: service: name: nginx-demo port: number: 8000
②. 上面的yaml文件是精准匹配,流量限制1s一个请求进来,如果这个时候我们大量的刷新浏览器,就会出现503