gpt4 book ai didi

nginx - 如何在每个 nginx-ingress 主机上添加阻止 IP 规则

转载 作者:行者123 更新时间:2023-12-05 02:56:46 25 4
gpt4 key购买 nike

我找了很多都没有找到解决办法。我想阻止/允许 ip 进入 nginx-ingress 中的每个主机定义,而不是每个位置。

这是 ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-nginx
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: test1.test.com
#Blocking rules here, only affecting test1.test.com domain
http:
paths:
- path: /
backend:
serviceName: wordpressA
servicePort: 80
- host: test2.test.com
#Blocking rules here, only affecting test2.test.com domain
http:
paths:
- path: /
backend:
serviceName: wordpressB
servicePort: 80

非常感谢您的宝贵时间

最佳答案

您需要将那些 host 定义拆分为单独的 ingress 规则。

然后你可以使用注解whitelist source range使用以下 annotation :nginx.ingress.kubernetes.io/whitelist-source-range

像这样:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app1-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/whitelist-source-range: "10.0.0.0/24"
spec:
rules:
- host: app1.com
http:
paths:
- path: /
backend:
serviceName: app1-service
servicePort: http
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app2-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/whitelist-source-range: "10.0.0.0/24"
spec:
rules:
- host: app2.com
http:
paths:
- path: /
backend:
serviceName: app2-service
servicePort: http

您还可以使用 server snipper并将 nginx 配置添加到 yaml

像这样:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/server-snippet: |
location / {
# block one workstation
deny 192.168.1.1;
# allow anyone in 192.168.1.0/24
allow 192.168.1.0/24;
# drop rest of the world
deny all;
}

关于nginx - 如何在每个 nginx-ingress 主机上添加阻止 IP 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60192577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com