Files
Kubernetes/网关/Ingress/创建Ingress资源提供访问.md
offends 89a07bc062
All checks were successful
continuous-integration/drone Build is passing
first commit
2025-12-20 21:10:05 +08:00

62 lines
1.2 KiB
Markdown

> 本文作者:丁辉
# 创建Ingress资源提供访问
## 准备工作
- Nginx Deployment
- Nginx Service:
Name: nginx-service
Port: 80
## 示例
1. 创建对外域名证书
```bash
kubectl create secret tls nginx-tls --key nginx.key --cert nginx.pem -n default
```
2. 创建 Ingress 资源
```yaml
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
namespace: default
annotations:
# 不限制文件上传大小 或 选择其他参数
nginx.ingress.kubernetes.io/proxy-body-size: "0"
labels:
name: nginx-ingress
spec:
rules:
# 对外域名
- host: nginx.example.com
http:
paths:
- pathType: Prefix
backend:
service:
# Nginx Serice 名称
name: nginx-service
port:
# Nginx 端口
number: 80
path: /
# 对外域名证书配置
tls:
- hosts:
- nginx.example.com
secretName: nginx-tls
EOF
```
3. 访问域名