https://github.com/flytrap/test-ip
测试k8s中 真实ip是否可以获取
https://github.com/flytrap/test-ip
Last synced: about 1 month ago
JSON representation
测试k8s中 真实ip是否可以获取
- Host: GitHub
- URL: https://github.com/flytrap/test-ip
- Owner: flytrap
- License: apache-2.0
- Created: 2024-05-29T08:45:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-05-20T05:55:49.000Z (about 2 months ago)
- Last Synced: 2026-05-20T09:22:52.890Z (about 2 months ago)
- Language: Go Template
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# test-ip
测试 Kubernetes 中真实 IP 是否可以获取。
## 功能
获取客户端真实 IP 和请求头信息,用于验证网关代理(如 Istio IngressGateway)是否正确传递客户端请求信息。
## API
### GET /test/ip
获取客户端真实 IP 地址。
```bash
curl -H "Host: ok.com" http:///test/ip
```
响应示例:
```json
{
"ip": "192.168.1.100"
}
```
### GET /test/header
获取请求头信息。
```bash
curl -H "Host: ok.com" http:///test/header
```
响应示例:
```json
{
"Accept": "*/*",
"Host": "ok.com",
"X-Real-IP": "192.168.1.100",
...
}
```
## 部署
### 1. 构建镜像
```bash
docker build -t test-ip:latest .
```
### 2. 部署应用
```bash
kubectl apply -f deployment.yaml
```
这会创建 Deployment 和 Service 资源。
### 3. 部署 Istio 网关配置
```bash
kubectl apply -f gateway.yaml
```
这会创建 Gateway 和 VirtualService 资源,将 `ok.com` 域名的流量路由到你的 test-ip 服务。
### 4. 访问服务
通过 Istio IngressGateway 域名 `ok.com` 访问服务。
## Istio 配置
- **Gateway**: `test-gateway` - 监听 80 端口,接收 `ok.com` 域名流量
- **VirtualService**: `test-vs` - 将流量路由到 `test-ip` 服务的 8080 端口