<p>The Kubernetes remote API allows HTTP access to arbitrary pod ports using the proxy verb, that is, using an API path of <code>/api/v1/namespaces/{namespace}/pods/{name}/proxy</code>.</p>

<p>The Python client offers <code>corev1.connect_get_namespaced_pod_proxy_with_path()</code> to invoke the above proxy verb.</p>

<p>Despite reading, browsing, and searching the Kubernetes client-go for some time, I'm still lost how to do the same with the goclient what I'm able to do with the python client. My other impression is that I may need to dive down into the rest client of the client changeset, if there's no ready-made API corev1 call available?</p>

<p>How do I correctly construct the GET call using the rest client and the path mentioned above?</p>

<p>As it turned out after an involved dive into the Kubernetes client sources, accessing the proxy verb is only possible when going down to the level of the <code>RESTClient</code> and then building the GET/... request by hand. The following code shows this in form of a fully working example:</p>

<pre class="lang-golang prettyprint-override"><code>package main

import (
    "fmt"

    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/tools/clientcmd"
)

func main() {
    clcfg, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
    if err != nil {
        panic(err.Error())
    }
    restcfg, err := clientcmd.NewNonInteractiveClientConfig(
        *clcfg, "", &amp;clientcmd.ConfigOverrides{}, nil).ClientConfig()
    if err != nil {
        panic(err.Error())
    }
    clientset, err := kubernetes.NewForConfig(restcfg)
    res := clientset.CoreV1().RESTClient().Get().
        Namespace("default").
        Resource("pods").
        Name("hello-world:8000").
        SubResource("proxy").
        // The server URL path, without leading "/" goes here...
        Suffix("index.html").
        Do()
    if err != nil {
        panic(err.Error())
    }
    rawbody, err := res.Raw()
    if err != nil {
        panic(err.Error())
    }
    fmt.Print(string(rawbody))
}
</code></pre>

<p>You can test this, for instance, on a local <a href="https://github.com/kubernetes-sigs/kind" rel="noreferrer">kind</a> cluster (Kubernetes in Docker). The following commands spin up a kind cluster, prime the only node with the required hello-world webserver, and then tell Kubernetes to start the pod with said hello-world webserver.</p>

<pre class="lang-sh prettyprint-override"><code>kind create cluster
docker pull crccheck/hello-world
docker tag crccheck/hello-world crccheck/hello-world:current
kind load docker-image crccheck/hello-world:current
kubectl run hello-world --image=crccheck/hello-world:current --port=8000 --restart=Never --image-pull-policy=Never
</code></pre>

<p>Now run the example:</p>

<pre class="lang-sh prettyprint-override"><code>export KUBECONFIG=~/.kube/kind-config-kind; go run .
</code></pre>

<p>It then should show this ASCII art:</p>

<pre><code>&lt;xmp&gt;
Hello World


                                       ##         .
                                 ## ## ##        ==
                              ## ## ## ## ##    ===
                           /""""""""""""""""\___/ ===
                      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
                           \______ o          _,/
                            \      \       _,'
                             `'--.._\..--''
&lt;/xmp&gt;
</code></pre>
