Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To fix kubectl exec failing with “connection refused,” first identify the refused hostname or IP address and port. If ordinary Kubernetes API requests also fail, investigate the client-to-API-server connection. If API requests work but exec fails, focus on the API-server-to-kubelet connection for the node running the Pod. The same error text can point to different network hops, so the full error matters more than the command alone.

Start by finding which connection was refused

kubectl communicates with the Kubernetes API server. For operations that attach to a running Pod, including exec, the API server also communicates with the kubelet on the Pod’s node. These are separate connections, and the address and port in the error help distinguish them. Kubernetes describes the API-server-to-kubelet path in its communication between Nodes and the Control Plane documentation.

Save the complete command and error before changing configuration. A TCP refusal is not the same as a timeout, an authentication failure, or an authorization denial; each points to a different kind of problem. Do not assume that every refusal during exec originates from the container.

Check the client-to-API-server path first

  1. Confirm the active context and kubeconfig. Run kubectl config get-contexts and verify the active context and cluster endpoint. Check whether the KUBECONFIG environment variable points to the intended configuration file. A stale or incorrect context can send requests to an endpoint that is unavailable or not the cluster you intended. See the Kubernetes cluster troubleshooting guidance.
  2. Test ordinary API access. Try kubectl get --raw=/readyz if the cluster and your permissions allow it. Then try a simple read, such as kubectl get pods. If these requests fail with a refusal at the API endpoint, the issue is not specific to the container command.
  3. Check the endpoint and network path. Verify that the configured API-server hostname and port are the intended ones and that the client can reach them. Check relevant VPN, routing, and firewall rules, along with the health of the API server and any load balancer in front of it. Kubernetes’ troubleshooting guidance covers API-server reachability and related connectivity checks.

Five plausible causes of “connection refused”

These are diagnostic areas, not a ranking or a guarantee that every incident has exactly one cause. Use the refused address, results from ordinary API requests, and node logs to narrow the investigation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. kubectl is using a wrong or stale endpoint

An unexpected active context, kubeconfig file, or API-server address can make kubectl contact the wrong or unusable endpoint. Compare the active context with the intended cluster, check KUBECONFIG, and confirm the server address recorded in the selected configuration.

2. The API server or its load balancer is not accepting connections

If basic API requests fail at the configured endpoint, check whether the API server is healthy and whether a load balancer or other fronting endpoint is accepting connections. In kubeadm installations, control-plane components commonly run as static Pods; their health can be inspected on the control-plane node as part of a broader investigation. Kubernetes explains the kubeadm static-Pod setup in its kubelet integration documentation.

3. A network path or firewall blocks the relevant hop

For failures of ordinary API calls, investigate the client-to-API-server route, VPN, and firewall. When ordinary calls succeed but attaching to a Pod fails, check the distinct API-server-to-kubelet route to the target node. Do not troubleshoot one path as if it were the other.

4. The target node’s kubelet is unavailable or unreachable

The API server uses the kubelet endpoint for operations such as attaching to a running Pod. Check which node hosts the target Pod, which node address the control plane is using, whether that address is reachable from the API server, and whether the kubelet is healthy. A refusal from that node’s kubelet endpoint differs from a client-side refusal from the API-server endpoint.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. A node-local runtime or container command is the problem

If the kubelet cannot complete the container operation, inspect the affected node’s kubelet logs and container-runtime health. Kubernetes’ kubeadm troubleshooting guidance recommends examining failed or hanging control-plane containers and points to crictl for runtime-aware debugging where suitable.

Separate a network refusal from a missing-executable error. If the message says that a command such as sh was not found, the image may not include a shell. Use an executable that exists in the image or an appropriate debugging method; a missing binary is not evidence of a refused TCP connection. See Kubernetes’ guidance for debugging a running Pod.

Use the symptom to choose the next check

What you observe Connection to investigate Next checks
Many ordinary kubectl API commands fail Client to API server Active context and kubeconfig; API endpoint; VPN, routing, and firewall; API-server and load-balancer health.
API requests work, but attaching to a Pod fails API server to the target node’s kubelet Pod’s node; node address and reachability; kubelet health; API-server-to-node routing and firewall.
The error names a missing command or executable Container command, not necessarily a network connection Check which binaries the image contains and choose an available command or suitable debugging method.

These checks follow the documented connection paths; cluster addressing and network policy vary, so confirm the actual endpoint in your environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

For kubeadm, inspect control-plane components on the node

In a kubeadm cluster, the API server, controller manager, scheduler, and local etcd commonly run as static Pods supervised by the kubelet. The kubelet watches manifests under /etc/kubernetes/manifests. If the API endpoint itself is unavailable, inspect the control-plane node and those components rather than treating a failed exec as a container-only problem. Use the cluster’s runtime-aware tools, including crictl where appropriate, to examine failed or hanging containers. These kubeadm details do not apply uniformly to every Kubernetes distribution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the error alone cannot tell you

The title and error phrase do not identify a root cause by themselves. To narrow it down, you need the complete error and refused host and port, whether other API requests succeed, the target Pod’s node, the cluster setup, and relevant API-server, kubelet, or runtime logs. The documented troubleshooting paths help you choose where to look; they do not establish that any one cause explains every occurrence.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.