Verifying Your kubectl Setup
After installing kubectl, you should verify that everything is working correctly. This lesson covers the key verification commands and how to troubleshoot common issues.
Check the Client Version
The first thing to run after installation is the version command:
kubectl version --client
You should see output like:
Client Version: v1.31.0
Kustomize Version: v5.4.2
If you get a "command not found" error, kubectl is not in your system PATH. Check your installation and make sure the binary location is included in your PATH environment variable.
Check Cluster Connectivity
Once you have a cluster configured, verify the connection:
kubectl cluster-info
Successful output looks like:
Kubernetes control plane is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Troubleshooting Common Issues
Connection refused or timeout: The cluster is not running or not reachable. If you are using Docker Desktop, make sure Kubernetes is enabled. For remote clusters, check your network connection.
# Check your current context and cluster configuration
kubectl config current-context
kubectl config view --minify
Unauthorized or forbidden errors: Your credentials may be expired or misconfigured. Check that your kubeconfig file has valid authentication details.
# See where your kubeconfig is located
echo $KUBECONFIG
# Default location if KUBECONFIG is not set
ls ~/.kube/config
Version mismatch warning: kubectl supports clusters within one minor version difference. If your client is v1.31 and the server is v1.29, that is fine. A larger gap may cause unexpected behavior.
# Show both client and server versions
kubectl version
Key Takeaways
- Always run
kubectl version --clientafter installation to confirm it works - Use
kubectl cluster-infoto verify cluster connectivity - Connection errors usually mean the cluster is not running or the kubeconfig is wrong
- Check
kubectl config current-contextwhen working with multiple clusters - Keep kubectl within one minor version of your cluster