可以从群集内访问clusterip服务,但不能使用kubectl代理

时间:2019-08-02 18:09:30

标签: kubernetes proxy kubernetes-service

我正在尝试访问clusterip服务(通过docker-for-mac在笔记本电脑上运行kubernetes)。

instructions here之后,我能够像这样成功ping服务:

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"

但是我不能使用服务名称而不是IP来使其工作。然后,我尝试使用kubectl代理as described here,但无法正常工作:

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

这会给我一个404错误,如下所示:

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

以及以上所有和/或带有服务名称的ip中将8000替换为http的所有组合。

我可以确认代理正在像http://127.0.0.1:8080/api/v1/namespaces/deploy-test/pods一样工作。

这是服务的描述。请注意,我专门尝试通过clusterip访问它,而不使用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>

关于如何通过kubectl proxy而不是使用radial/busyboxplus:curl旋转吊舱的任何建议?

1 个答案:

答案 0 :(得分:4)

通过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 oder LoadBalancer)

相关问题