How to fix The connection to the server was refused in Kubernetes
Your kubectl cannot connect to the Kubernetes API server. This prevents any cluster management operations.
Quick fix
Fixes The connection to the server was refused
kubectl config view- Verify the API server endpoint in kubeconfig
- Test connectivity to the API server
- Check if the API server is running
- Restart the API server if needed
kubectl config viewThe connection to the server was refused
What this error means
When kubectl cannot establish a TCP connection to your Kubernetes API server, it returns a connection refused error. This typically means the API server is not listening on the specified address, is unreachable due to network issues, or the server process has crashed. The kubeconfig file may also point to an incorrect server address or port.
Typical symptoms
- kubectl commands fail immediately with connection refused
- Unable to deploy, delete, or query any resources
- Cluster management completely unavailable
- CI/CD pipelines fail on kubectl operations
- Error occurs even for simple commands like kubectl version
- No logs or partial output before disconnection
Common causes
- Kubernetes API server is not running or crashed
- Wrong API server address or port in kubeconfig
- Network connectivity issue between client and server
- API server process killed or restarted
- Firewall blocking port 6443 (default HTTPS port)
- Load balancer or ingress in front of API server is down
How to fix "The connection to the server was refused"
Check your kubeconfig file:
kubectl config viewLook for the server: field. Typical format: https://10.0.0.1:6443 or https://kubernetes.default.svc.cluster.local
Try a direct connection:
curl -k https://YOUR_API_SERVER:6443If you get connection refused, the server is not listening.
On the control plane node:
kubectl get nodes
# Or on control plane:
sudo systemctl status kubelet
sudo systemctl status kube-apiserverIf using kubeadm, check pod status:
kubectl get pods -n kube-system | grep apiserverFor kubeadm clusters:
sudo systemctl restart kubeletFor managed services (EKS, GKE), use the cloud console to check and restart the cluster control plane.
If the address is wrong, update it:
kubectl config set-cluster kubernetes --server=https://CORRECT_IP:6443Or manually edit ~/.kube/config and change the server field.
Advanced notes
For managed Kubernetes (EKS, GKE, AKS), connection issues often indicate control plane health. Check cloud provider dashboards. For on-premises clusters, monitor etcd and API server logs. Ensure client certificates in kubeconfig are not expired (check with openssl x509 -in cert.crt -text -noout). In load-balanced setups, verify the load balancer is routing correctly to all control plane nodes.
Frequently asked questions
- What does "The connection to the server was refused" mean?
- When kubectl cannot establish a TCP connection to your Kubernetes API server, it returns a connection refused error. This typically means the API server is not listening on the specified address, is unreachable due to network issues, or the server process has crashed. The kubeconfig file may also point to an incorrect server address or port.
- How do I fix "The connection to the server was refused"?
- Your kubectl cannot connect to the Kubernetes API server. This prevents any cluster management operations.
- What causes "The connection to the server was refused"?
- Kubernetes API server is not running or crashed Wrong API server address or port in kubeconfig Network connectivity issue between client and server
- Is the "The connection to the server was refused" error serious?
- Yes. This is a critical-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Kubernetes Official Documentation
- ๐Kubernetes: Kubeconfig Configuration(Official Docs)
- ๐Kubernetes: Kubeadm Troubleshooting(Official Docs)
- ๐