kubernetes - Can access clusterip service from within cluster but not by using kubectl proxy
问题描述
I am trying to access a clusterip service (running kubernetes on my laptop through docker-for-mac).
Following the instructions here, I was able to successfully ping the service like this:
kubectl run curl --image=radial/busyboxplus:curl -i --tty
curl -v http://10.106.1.204:8000/api/v0.1/predictions -d '{"foo": "bar"}' -H "Content-Type: application/json"
but I can't get it to work using the service name instead of it's ip. I then tried to use kubectl proxy as described here, but I can't get it to work:
kubectl proxy --port=8080 &
curl -v http://127.0.0.1:8080/api/v1/proxy/namespaces/deploy-test/services/10.106.1.204:8000/api/v0.1/predictions
that gives me a 404 error as do all of the following:
curl -v http://127.0.0.1:8080/api/v1/proxy/namespaces/deploy-test/services/10.106.1.204:8000
curl -v http://127.0.0.1:8080/api/v1/proxy/namespaces/deploy-test/services/10.106.1.204:8000/predictions
curl -v http://127.0.0.1:8080/api/v1/proxy/namespaces/deploy-test/services/10.106.1.204:8000/api/v0.1/predictions
as well as all combinations of replacing 8000
with http
in all of the above and/or the ip with the service name.
I can confirm that the proxy is working as http://127.0.0.1:8080/api/v1/namespaces/deploy-test/pods
works.
This is the description of the service. Note that I am specifically trying to access it via the clusterip and not use Ambassador.
kubectl describe svc -n deploy-test template-product-app-seldon-prediction-service
Name: template-product-app-seldon-prediction-service
Namespace: deploy-test
Labels: seldon-app=template-product-app-seldon-prediction-service
seldon-deployment-id=template-product-app-seldon-prediction-service
Annotations: getambassador.io/config:
---
apiVersion: ambassador/v1
kind: Mapping
name: seldon_deploy-test_seldon-prediction-service_rest_mapping
prefix: /seldon/deploy-test/seldon-prediction-service/
service: template-product-app-seldon-prediction-service.deploy-test:8000
timeout_ms: 3000
---
apiVersion: ambassador/v1
kind: Mapping
name: seldon_deploy-test_seldon-prediction-service_grpc_mapping
grpc: true
prefix: /seldon.protos.Seldon/
rewrite: /seldon.protos.Seldon/
service: template-product-app-seldon-prediction-service.deploy-test:5001
timeout_ms: 3000
headers:
namespace: deploy-test
seldon: seldon-prediction-service
retry_policy:
retry_on: connect-failure
num_retries: 3
Selector: seldon-app=template-product-app-seldon-prediction-service
Type: ClusterIP
IP: 10.106.1.204
Port: http 8000/TCP
TargetPort: 8000/TCP
Endpoints: 10.1.1.4:8000
Port: grpc 5001/TCP
TargetPort: 5001/TCP
Endpoints: 10.1.1.4:5001
Session Affinity: None
Events: <none>
Any suggestions on how to do this via kubectl proxy
instead of spinning up a pod with radial/busyboxplus:curl
?
解决方案
通过 kubectl 代理访问 http 服务的一般格式如下:
http://api.host/api/v1/namespaces/NAMESPACE/services/SERVICE_NAME:SERVICE_PORT/proxy/
在您的情况下,您添加了不必要的集群 ip。尝试:
http://127.0.0.1:8080/api/v1/namespaces/deploy-test/services/template-product-app-seldon-prediction-service:8000/proxy/api/v0.1/predictions
http://127.0.0.1:43029/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard
请注意,这可能不适用于 grpc,仅适用于 http。(在这种情况下,请改用 NodePort 或 LoadBalancer)
推荐阅读
- spring-boot - 数据流服务器上的 Spring 批处理 (JSR-352) 应用示例
- r - R data.table 值取决于前一行
- angular - Angular - 生命周期:要完全加载的子组件
- ignite - 如何在 webapps 之间共享一个 Ignite 实例?
- vue.js - 如何在 vuetify 中删除列表项的填充
- regex - 在大写字母之前插入空格但不在缩写之间插入空格的pythonic方法
- redux - Redux persistedState 对象没有设置默认的 redux 状态
- php - 在 PHP 中将 VueJS 输出从 String 转换为 Int
- r - 当我进行面板回归时,虚拟变量丢失了。如何显示虚拟变量?
- db2 - 如何在 DB2 中编写存储过程