简单 Ingress Controller 管理
# 查看生成的配置文件 kubectl exec -it -n "ingress-nginx" nginx-ingress-controller-67956bf89d-fv58j cat /etc/nginx/nginx.conf # 查看当前 Nginx 版本 kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version
配置 GeoIP 模块
How to block a country in Nginx ingress? : kubernetes
# 07/03/2022 我们暂时放弃通过 GeoIP 来实现安全访问控制,而采用其他方案。所以,我们这里仅简单记录配置思路,而具体配置可能存在错误;
NGINX Ingress Controller 支持 MaxMind GeoIP2 数据库,使用流程如下:
1)申请 MaxMind 的许可:
IP Geolocation and Online Fraud Prevention | MaxMind
2)调整 NGINX Ingress Controller 的配置,以使用许可;
NGINX Ingress Controller/ConfigMap/use-geoip2
3)通过 Annotation 进行相关配置:
... metadata: annotations: nginx.ingress.kubernetes.io/server-snippet: | # server block map $geoip2_city_country_code $blocked_country { default 0; AU 1; FR 1; } nginx.ingress.kubernetes.io/configuration-snippet: | # location block if ($blocked_country) { return 403; } ...
暴露 gRPC 服务
问题描述
通过 Ingress 无法访问到其后的 gRPC 服务;
原因分析
未在 Ingress 资源中设置 Annotation,指定后端协议类型;
gRPC 服务只能通过 TLS 端口进行访问;
解决方案
要满足两个条件:
1)在对应 Ingress 资源中,设置 Annotation: nginx.ingress.kubernetes.io/backend-protocol:”GRPC”;
2)在确认客户端发送请求时,使用的是 TLS 端口,并且将流量加密;