kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.79k stars 2.91k forks source link

Kube proxy failed as "could not find the requested resource" #1231

Closed whalecold closed 1 year ago

whalecold commented 1 year ago

I want to send the traffic to my own service from kube proxy, like the code below:

    req := client.Interface.CoreV1().RESTClient().
        Get().
        Namespace("default").
        Resource("services").
        SubResource("proxy").
        Name("hello:8080").
        Suffix("hello").
                 RequestURI("?kind=serviceentry").
        SetHeader("Content-Type", "application/json").
        Timeout(constant.DefaultTimeout)

    fmt.Printf("------------start  req url %s\n",  req.URL().String())

I found it will failed if add the query to the request and the error is could not find the requested resource (get services hello:8080), the req url is https://10.233.20.51:6443/api/v1/namespaces/default/services/hello:8080/proxy/resources?kind=serviceentry&timeout=10s in fact. And after removing the query kind=serviceentry it will send successful.

I try to use kubectl proxy to transfer the request http://127.0.0.1:8001/api/v1/namespaces/default/services/hello:8080/proxy/resources\?kind\=serviceentry and it alse successful.

whalecold commented 1 year ago

should use Param() to add query.