目录
序言
1.Ingress基本介绍
1.1 暴露服务问题
1.2 什么是Ingress
1.2 Ingress的核心组件
1.2.1 ingress
1.2.2 ingress-controller
1.2.3 反向代理负载均衡器
2.安装
2.1 下载/修改配置文件
具体位置截图:
2.2 安装资源
2.3 结果
2.4 项目示例
2.4.1 创建service及deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-nginx
name: test-nginx
spec:
replicas: 3 #3个副本
minReadySeconds: 5 #等待5秒后升级
selector:
matchLabels:
app: test-nginx
template:
metadata:
labels:
app: test-nginx
spec:
containers:
- image: nginx
name: test-nginx
---
apiVersion: v1
kind: Service
metadata:
name: test-nginx
labels:
app: test-nginx
spec:
ports:
- port: 80
targetPort: 80
selector:
app: test-nginx
2.4.2创建Ingress规则
# ingress规则中,要指定需要绑定暴露的svc名称
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-test-nginx
annotations:
kubernetes.io/ingress.class: "nginx" # 指定 Ingress Controller 的类型
nginx.ingress.kubernetes.io/use-regex: "true" # 指定我们的 rules 的 path 可以使用正则表达式
nginx.ingress.kubernetes.io/proxy-connect-timeout: "600" # 连接超时时间,默认为 5s
nginx.ingress.kubernetes.io/proxy-send-timeout: "600" # 后端服务器回转数据超时时间,默认为 60s
nginx.ingress.kubernetes.io/proxy-send-timeout: "600" # 后端服务器响应超时时间,默认为 60s
nginx.ingress.kubernetes.io/proxy-body-size: "10m" # 客户端上传文件,最大大小,默认为 20m
spec:
rules: #定义路由规则
- host: www.testnginx.com # 主机名,只能是域名,修改为项目域名
http:
paths:
- path: /
backend:
serviceName: test-nginx # 后台部署的 Service Name
servicePort: 80 # 后台部署的 Service Port
2.4.3 完整文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test-nginx
name: test-nginx
namespace: test
spec:
replicas: 3 #3个副本
minReadySeconds: 5 #等待5秒后升级
selector:
matchLabels:
app: test-nginx
template:
metadata:
labels:
app: test-nginx
spec:
containers:
- image: nginx
name: test-nginx
---
apiVersion: v1
kind: Service
metadata:
name: test-nginx
namespace: test
labels:
app: test-nginx
spec:
ports:
- port: 80
targetPort: 80
selector:
app: test-nginx
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-test-nginx
namespace: test
annotations:
kubernetes.io/ingress.class: "nginx" # 指定 Ingress Controller 的类型
nginx.ingress.kubernetes.io/use-regex: "true" # 指定我们的 rules 的 path 可以使用正则表达式
nginx.ingress.kubernetes.io/proxy-connect-timeout: "600" # 连接超时时间,默认为 5s
nginx.ingress.kubernetes.io/proxy-send-timeout: "600" # 后端服务器回转数据超时时间,默认为 60s
nginx.ingress.kubernetes.io/proxy-send-timeout: "600" # 后端服务器响应超时时间,默认为 60s
nginx.ingress.kubernetes.io/proxy-body-size: "10m" # 客户端上传文件,最大大小,默认为 20m
spec:
rules: #定义路由规则
- host: www.testnginx.com # 主机名,只能是域名,修改为项目域名
http:
paths:
- path: /
backend:
serviceName: test-nginx # 后台部署的 Service Name
servicePort: 80 # 后台部署的 Service Port