写在最前
1. 前置条件
2. 部署流程
2.1 下载安装
我的版本比较低是1.21.x,要注意你的kubernetes版本是否对应上否则会安装失败,ingress-nginx镜像源下载不了我换成国内的了 my-ingress-nginx-v1.3.1.yaml
https://github.com/kubernetes/ingress-nginx
# 下载
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml
# 将 externalTrafficPolicy: Local 改成 Cluster 允许所有节点都能访问
346 externalTrafficPolicy: Local
# 留意是不是LoadBalancer,因为要搭配metallb或openELB来使用
365 type: LoadBalancer
可以看到metalLB或者openELB提供的IP已经被ingress-nginx识别到了
2.2 配置优化
3. 维护页面
如需临时进入维护状态只需要将~/hello中的hello给删掉即可维护完毕再加回hello,即可在不影响原服务容器运行的前提下,阻止外部流量访问前端服务,同时向用户展示维护提示页。
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: xxxxxxx
namespace: xxxxxxx
annotations:
kubernetes.io/ingress.class: nginx
kubesphere.io/creator: tanqidi
nginx.ingress.kubernetes.io/server-snippet: >-
location ~/hello { default_type text/html; return 200 '<!DOCTYPE html><html
lang="zh-CN"><head><meta charset="UTF-8"/><meta name="viewport"
content="width=device-width,initial-scale=1"/><title>系统维护中</title><style>body{margin:0;background:#f0f4f8;color:#2c3e50;font-family:"Helvetica
Neue",Helvetica,Arial,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;text-align:center;}svg{width:72px;height:72px;margin-bottom:24px;stroke:url(#grad);stroke-width:1.8;fill:none;stroke-linecap:round;stroke-linejoin:round;}h1{font-weight:700;font-size:2.8rem;margin:0
0 12px;}p{margin:0 0
28px;font-size:1.2rem;line-height:1.5;color:#34495e;}a{color:#2980b9;font-weight:600;text-decoration:none;box-shadow:inset
0 -2px 0 #2980b9;transition:box-shadow 0.3s,color
0.3s;}a:hover{box-shadow:none;color:#1c5980;}</style></head><body><svg
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24
24"><defs><linearGradient id="grad" x1="0" y1="0" x2="1" y2="1"><stop
offset="0%" stop-color="#3498db"/><stop offset="100%"
stop-color="#2980b9"/></linearGradient></defs><circle cx="12" cy="12"
r="9"/><path d="M12 8v4l3
3"/></svg><h1>系统维护中</h1><p>我们正在努力升级服务,请稍后再访问。感谢您的理解与支持!</p><a href="#"
onclick="location.reload()">刷新页面</a></body></html>'; }