Can access clusterip service from within cluster but not by using kubectl proxy

8/2/2019

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?

-- Dan
kubernetes
kubernetes-service
proxy

1 Answer

8/2/2019

The general format to access http services through the kubectl proxy is the following:

http://api.host/api/v1/namespaces/NAMESPACE/services/SERVICE_NAME:SERVICE_PORT/proxy/

In your case you added the cluster ip which is not necessary. Try:

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

Note that this will probably not work with grpc, only for http. (Use a NodePort oder LoadBalancer instead in that case)

-- Thomas
Source: StackOverflow