872 B
872 B
本文作者:丁辉
Service实现代理外部服务
基础环境准备
部署一个 Docker Nginx 服务暴露本地 10000 端口
docker run -it --rm --name nginx-demo -p 10000:80 nginx:latest
基于 Endpoints 实现
-
创建 Endpoints,Service
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 -
查看
kubectl get ep,svc -
访问测试