Files
Kubernetes/使用文档/其他/Service实现代理外部服务.md
offends e5581862c5
All checks were successful
continuous-integration/drone Build is passing
新增RustFs文档,修改了一些文件
2025-12-25 00:39:45 +08:00

52 lines
872 B
Markdown

> 本文作者:丁辉
>
# Service实现代理外部服务
## 基础环境准备
部署一个 Docker Nginx 服务暴露本地 10000 端口
```bash
docker run -it --rm --name nginx-demo -p 10000:80 nginx:latest
```
## 基于 Endpoints 实现
1. 创建 Endpoints,Service
```yaml
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Endpoints
metadata:
name: nginx-proxy # 必须与 Service 同名
namespace: default
subsets:
- addresses:
- ip: 127.0.0.1 # 替换为 Nginx 服务器访问地址
ports:
- port: 10000
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: nginx-proxy
namespace: default
spec:
ports:
- port: 80
targetPort: 80
type: ClusterIP
EOF
```
2. 查看
```bash
kubectl get ep,svc
```
3. 访问测试