This commit is contained in:
51
使用文档/其他/Service实现代理外部服务.md
Normal file
51
使用文档/其他/Service实现代理外部服务.md
Normal file
@@ -0,0 +1,51 @@
|
||||
> 本文作者:丁辉
|
||||
>
|
||||
|
||||
# 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. 访问测试
|
||||
Reference in New Issue
Block a user