定义ingress 403页面

背景

默认的ingress controller提供的403 error页面太丑了,想要定制化一下

实现

1.增加一个configmap,定义403页面
2.挂载到ingress-controller的pod里
3.对单个ingress对象增加annotation注解

开始吧

增加一个configmap

1
2
3
4
5
6
meitu403.html: | 
<head><meta charset="UTF-8"></head>
<html>
<h1 align="center">禁止外部访问</h1>
<p align="center">请连接美图wifi或者有线!</p>
</html>

挂载到ingress-controller的pod里

1
2
3
volumeMounts:
- mountPath: /etc/nginx/conf
name: nginx-whitelist-volume
1
2
3
4
5
volumes:
- configMap:
defaultMode: 420
name: nginx-whitelist
name: nginx-whitelist-volume

增加annotation

1
nginx.ingress.kubernetes.io/server-snippet: error_page 403 /meitu403.html; location  /meitu403.html { internal; root /etc/nginx/conf; allow all; }

效果展示

png1