To run kubectl behind a proxy, set HTTPS_PROXY (or the proxy-url field in the cluster entry of your kubeconfig), exclude the hosts that must not go through it with NO_PROXY, and confirm with kubectl get nodes. Most failures after that come from three places: a proxy that inspects TLS, a proxy that closes the connection to port 6443, or a command such as exec that needs a protocol upgrade the proxy cannot carry. This guide covers all three, and it separates two things people mix up: kubectl using a proxy, and the kubectl proxy command.
If your real obstacle is a cluster API that sits behind a bastion host, an SSH tunnel is often a cleaner answer than an HTTP proxy. Kubezilla Desktop supports SSH tunnels and keeps your kubeconfigs stored locally, so you do not have to maintain tunnel commands by hand.
TL;DR
- kubectl reads
HTTPS_PROXY,HTTP_PROXYandNO_PROXYfrom the environment. These affect every context you use. - To proxy one cluster only, set
proxy-urlin that cluster's entry in the kubeconfig. It applies only to that context. - Verify with
kubectl cluster-infoandkubectl get nodes. If you seeUnable to connect to the server: EOF, rule out the proxy by running kubectl with the proxy variables unset. kubectl proxyis a different tool: a local gateway to the API server, not a way to get kubectl through a corporate proxy.- For clusters reachable only through a bastion, use a SOCKS5 proxy over SSH, or let a desktop client manage the tunnel.
Table of Contents
- Two different things called "proxy"
- Setting the proxy for kubectl
- Excluding hosts with NOPROXY
- Verify the connection
- Troubleshooting, in the order that saves time
- Using kubectl proxy correctly
- When the API sits behind a bastion
- Perspective
- Kubezilla Desktop for clusters you reach through tunnels
- A quick checklist
- FAQ
- Sources
Two different things called "proxy"
Search results for this topic mix three unrelated components, so it helps to separate them first.
A network proxy in front of kubectl. Your company routes outbound traffic through an HTTP, HTTPS or SOCKS proxy. kubectl is the client, and the proxy sits between your laptop and the API server. This is what this article is about.
kubectl proxy. According to the Kubernetes documentation on proxies, this command runs on your desktop or in a pod, proxies from localhost to the API server, speaks HTTP from client to proxy and HTTPS to the API server, and adds authentication headers. It does not help kubectl cross a corporate proxy. It gives browsers and curl a safe way in.
kube-proxy. The same page explains that kube-proxy runs on each node, handles TCP, UDP and SCTP, does not understand HTTP, and load-balances Services. It is the cluster administrator's concern and plays no part in how your workstation reaches the API.
This division is useful when debugging. If the failure happens before the request reaches the API server, look at your proxy settings. If it happens after, look at the cluster.

Setting the proxy for kubectl
Environment variables
The quickest setup is three exports in your shell:
export HTTPS_PROXY=http://proxy.example.com:8080
export HTTP_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1,.cluster.local,.svc
kubectl accepts both the uppercase and lowercase forms, as the Kubernetes SOCKS5 proxy guide notes. The API server is almost always HTTPS, so HTTPS_PROXY is the one that matters. Put it in your shell profile if you want it permanent, or in a wrapper script if you only need it for one environment.
The catch is scope: environment variables affect every context. If you work with five clusters and only one needs the proxy, the other four will be pushed through it too, and some of those may become unreachable.
proxy-url in the kubeconfig
The same guide explains that proxy-url set in a cluster entry applies only to that kubectl context. That makes it the better choice when clusters live in different network zones:
clusters:
- cluster:
server: https://10.50.0.10:6443
proxy-url: http://proxy.example.com:8080
name: prod-behind-proxy
You can set it with kubectl config set-cluster prod-behind-proxy --proxy-url=http://proxy.example.com:8080; the flag is listed in the kubectl config reference. Per-cluster settings also mean a colleague who copies your kubeconfig inherits the right path for each environment. If you keep several kubeconfig files, our guide to the KUBECONFIG environment variable shows how to merge and debug them.
SOCKS5 proxies
kubectl also supports SOCKS5. Per the Kubernetes SOCKS5 guide, you can export HTTPS_PROXY=socks5://localhost:1080 or set proxy-url to the same value in the cluster entry. Use the socks5h scheme when the proxy server, such as an SSH bastion, should resolve the API server hostname. That prevents DNS leakage and is what you want when the hostname only resolves inside the private network.
Which setting wins
A short rule: if proxy-url is set in the kubeconfig, that cluster uses it. Without it, kubectl falls back to the environment variables. Without those, it connects directly. When something behaves oddly, print your variables with env | grep -i proxy and check the cluster entry with kubectl config view --minify.
Excluding hosts with NO_PROXY
NO_PROXY is a comma-separated list of hosts and domains that must be reached directly. Two cases make it important.
- The API server is internal. If the API server address is reachable from your network without the proxy, add its hostname or IP, or its CIDR range, to
NO_PROXY. Otherwise the proxy may try to reach a private address it cannot see. - Local and cluster-internal names. Include
localhost,127.0.0.1,.svcand.cluster.localso that local tools and in-cluster DNS names do not leave the machine.
Be conservative with broad ranges such as 10.0.0.0/8. Support for CIDR notation in NO_PROXY varies between clients, so for kubectl itself it is safer to list the exact API host. Keep this list short and specific, and document it for your team.
Verify the connection
Once configured, run two commands:
kubectl cluster-info
kubectl get nodes
cluster-info confirms kubectl can reach the control plane and prints the proxy URLs of cluster services. get nodes proves authentication and authorization work too. If both succeed, the proxy path is fine. If you need more detail, add -v=6 to see which URL kubectl contacts and the HTTP status that comes back.
Troubleshooting, in the order that saves time
Step 1: Rule the proxy in or out
The DevOps AI Toolkit error guide identifies a corporate proxy or VPN as one cause of Unable to connect to the server: EOF: an intercepting proxy or VPN can accept the connection and then close it on port 6443. Its test is to run kubectl with the proxy variables removed:
env -u HTTPS_PROXY -u https_proxy kubectl get pods
If that works, the proxy is the problem. Add the API host to NO_PROXY, or set proxy-url correctly for that cluster only.
The same guide recommends a fixed order for connection failures: first confirm the server endpoint in the kubeconfig is correct, then that the load balancer has healthy backends forwarding TCP 6443, then that protocol, port and client credentials in the kubeconfig match, and only then the proxy or VPN. Walking down that list avoids blaming the proxy for a stale endpoint. For a deeper version of this approach, see our layer-by-layer connectivity troubleshooting guide.

Step 2: Check TLS
A proxy that inspects HTTPS re-signs traffic with its own certificate, and kubectl will reject it because it validates the server certificate against the CA in your kubeconfig. The kubeconfig fields involved, listed in the kubectl config reference, are --certificate-authority, --client-certificate, --client-key, --tls-server-name and --insecure-skip-tls-verify. In order of preference:
- Ask your network team to exempt the API server hostname from TLS inspection.
- Use
--tls-server-namewhen you connect through an address that differs from the name on the certificate. - Treat
--insecure-skip-tls-verifyas a last resort for a throwaway test. The Kubernetes documentation on accessing the API warns that ignoring certificate checks leaves access open to man-in-the-middle attacks.
Our API access hardening guide goes through why you should keep verification on.
Step 3: Logs time out but get works
This one confuses people. kubectl get pods works, yet kubectl logs hangs. Platform9's knowledge base documents a case where the API server's own connection to the kubelet on a worker node was routed through the HTTP proxy, which dropped the request. The fix was to set NO_PROXY on the control plane nodes to include the CIDR of all cluster hosts. The lesson: proxy variables on the control plane matter too, not only on your laptop.
Step 4: exec, attach and port-forward fail
These commands upgrade the connection to a streaming protocol. Through a SOCKS proxy, the Kubernetes SOCKS5 guide says most commands worked before kubectl 1.24 except kubectl exec, so check your kubectl version if you are on an older client.
If you are using kubectl proxy and see unable to upgrade connection: Unauthorized, that is deliberate. The kubectl proxy reference says by default it rejects paths matching pod exec and attach. The --disable-filter flag lifts that, as discussed in the Kubernetes issue tracker, but the reference warns it is dangerous and can expose you to XSRF attacks when the port is reachable. Do not use it on a shared machine. For interactive access, a direct kubectl connection or a tunnel is the safer route; our pod shell guide covers it, and multi-port forwarding has its own pitfalls.
Step 5: OIDC logins through the proxy
If you authenticate through an identity provider, the login helper also needs to reach it, possibly through the same proxy. That is a separate path from the API server. See kubeconfig OIDC authentication for how to set it up and what breaks.
Using kubectl proxy correctly
Since many readers land here looking for kubectl proxy, here is the short version. Start it with the port you want:
kubectl proxy --port=8080
curl http://localhost:8080/api/
The Kubernetes guide to HTTP proxy access uses exactly this flow, and the Accessing Clusters page recommends it because it uses the stored API server location, verifies the server's identity with its certificate and authenticates for you.
The defaults in the reference are sensible: port 8001, address 127.0.0.1, and an accept-hosts pattern that allows only localhost. Leave them alone unless you have a reason. Binding to 0.0.0.0 hands your cluster credentials' reach to anyone on the network.
To reach a service through it, use the URL pattern /api/v1/namespaces/<namespace>/services/<service>[:port_name]/proxy, documented on the Access Services page. That page also notes it works only for HTTP and HTTPS and may break some web applications.
When the API sits behind a bastion
Many teams do not have an HTTP proxy at all. They have a private API endpoint reachable only from a jump host. The Kubernetes SOCKS5 guide shows the manual approach:
ssh -D 1080 -q -N username@kubernetes-remote-server.example
-D 1080 opens a SOCKS proxy on local port 1080, -q suppresses warnings and -N runs no remote command. You then point kubectl at socks5h://localhost:1080. It works, but you must keep the terminal session alive, remember which cluster needs which port, and avoid colliding with another tunnel. Add certificate name mismatches on top of it, and it becomes a recurring chore. Our article on SSH tunnels for Kubernetes covers the certificate errors in detail.
Perspective
Most proxy trouble we see described comes down to scope. One environment variable in a shell profile quietly changes how every cluster is reached, and nobody remembers it three months later.
That is why we built Kubezilla Desktop around the idea that each cluster has its own connection settings, kept locally, with SSH tunneling as part of the app rather than a terminal you must babysit. Your kubeconfigs stay on your machine, with no cloud sync and no telemetry.
Native speed matters here too. The app is written in Rust, so it starts quickly and stays light on memory while you hold connections to several clusters, stream logs and watch metrics.
If you spend your day moving between clusters that sit behind different network barriers, the tool should carry that complexity, not your shell history.
Margus
Kubezilla Desktop for clusters you reach through tunnels
Kubezilla Desktop is a native app for Linux, macOS and Windows that gives you one interface for multiple clusters: SSH tunneling, live log streaming, metrics, pod terminals, YAML editing, workload scaling, Helm and Argo CD operations, and PVC file browsing. Kubeconfigs are stored securely on your device. It costs €5 per month.

If your day involves jumping between private clusters, see the Kubezilla Desktop Kubernetes client, or follow the tutorial on connecting to a cluster to see the setup end to end.
A quick checklist
- Decide the scope: environment variables for everything,
proxy-urlfor one cluster. - Set
NO_PROXYfor localhost,.svc,.cluster.localand any internal API host. - Run
kubectl cluster-infoandkubectl get nodes. - On
EOF, retry with the proxy variables unset. - On TLS errors, keep verification on and fix the CA or the server name.
- On log timeouts, check
NO_PROXYon the control plane nodes. - For
exec, check your kubectl version and avoid--disable-filter.
FAQ
Does kubectl use the HTTP_PROXY environment variable?
Yes. kubectl honors HTTPS_PROXY and HTTP_PROXY, in upper or lower case, and NO_PROXY for exclusions. Because the API server is normally HTTPS, HTTPS_PROXY is the one that decides the route. These variables affect every context you use.
Is kubectl proxy the same as setting a proxy for kubectl?
No. kubectl proxy starts a local gateway to the API server on your machine, by default at 127.0.0.1:8001. Setting a proxy for kubectl tells the client how to reach the API server through your network's proxy. The two solve different problems.
Can I use a proxy for only one cluster?
Yes. Set proxy-url in that cluster's entry in the kubeconfig. It applies only to the relevant context, while environment variables apply to all contexts.
Why does kubectl exec fail through a proxy?
Exec needs a streaming connection upgrade. With kubectl proxy, exec and attach paths are rejected by default. Through a SOCKS proxy, clients older than 1.24 did not support exec. Updating kubectl or connecting through a tunnel avoids both.
Sources
- Proxies in Kubernetes
- Use a SOCKS5 Proxy to Access the Kubernetes API
- kubectl config reference
- kubectl proxy reference
- Kubernetes issue: kubectl exec does not work through kubectl proxy
- Kubernetes Error Guide: Unable to connect to the server: EOF
- Platform9: Issues retrieving pod and container logs via kubectl
- Access Clusters Using the Kubernetes API
- Use an HTTP Proxy to Access the Kubernetes API
- Accessing Clusters
- Access Services Running on Clusters
