本地部署Jenkins+Docker+Kubernetes后无法访问Jenkins的调试命令及解决方法求助
Hey there! Let's walk through debugging this "Refused to connect" issue step by step. Since you're new to Docker and Kubernetes, I'll keep things clear and actionable with specific commands and fixes for each check.
1. Verify your Kubernetes cluster is healthy
First, let's confirm the core cluster services are up and running—this is the foundation of everything:
kubectl cluster-info
You should see valid URLs for the Kubernetes control plane, etcd, and other core services. If any are missing or marked unhealthy:
- If you're using Minikube (since
192.168.49.2is its default node IP), check its status:
If it's stopped, start it back up withminikube statusminikube start. - Check if your cluster node is in a
Readystate:
If the node sayskubectl get nodesNotReady, inspect the kubelet service on your Ubuntu machine:
If it's not running, restart it withsudo systemctl status kubeletsudo systemctl restart kubelet.
2. Check if the Jenkins Pod is running correctly
Next, let's make sure the Jenkins container itself is functioning. List all pods in your target namespace (use default if you didn't specify one):
kubectl get pods -n <your-namespace>
Look at the Jenkins pod's status:
- If it shows
CrashLoopBackOfforError, pull the pod logs to find startup issues:
Common problems here include failed image pulls (double-check your image name, e.g.,kubectl logs <jenkins-pod-name> -n <your-namespace>jenkins/jenkins:lts) or missing filesystem permissions. - If it's
ImagePullBackOff, test pulling the image locally on your Ubuntu machine to confirm it's accessible:docker pull jenkins/jenkins:lts
3. Validate the Jenkins Service configuration
The Service is what exposes Jenkins to your network. Let's check its setup:
kubectl get services -n <your-namespace>
Find the Jenkins service and confirm:
- The
TYPEisNodePort(since you're using port 32000). - The
PORT(s)column shows something like8080:32000/TCP(8080 is Jenkins' default container port, 32000 is the NodePort you're trying to access).
If the service looks off, dig deeper with:
kubectl describe service <jenkins-service-name> -n <your-namespace>
- Check the
Endpointsfield: it should list the IP of your running Jenkins pod. If it's empty, the service isn't matching the pod's labels. Compare the pod's labels and the service's selector:
If they don't match, update the service's selector to align with the pod's labels.# Get pod labels kubectl get pods <jenkins-pod-name> -n <your-namespace> -o jsonpath='{.metadata.labels}' # Get service selector kubectl get service <jenkins-service-name> -n <your-namespace> -o jsonpath='{.spec.selector}'
4. Test connectivity inside the cluster
Let's rule out issues with the pod itself by testing access from within the cluster. Spin up a temporary test pod:
kubectl run -it --rm busybox --image=busybox:1.28 -- sh
Inside the busybox shell:
- Ping the Jenkins pod's IP (get it from
kubectl get pods -o wide):ping <jenkins-pod-ip> - Try accessing Jenkins' internal port:
wget -qO- <jenkins-pod-ip>:8080
If you get HTML output as a response, the pod is working fine—your problem lies with external access. If not, circle back to checking pod logs and configuration.
5. Check external access and firewall settings
Now let's make sure your Ubuntu machine can reach the NodePort:
- First, confirm you can ping the Minikube node IP:
If ping fails, restart Minikube withping 192.168.49.2minikube stop && minikube start. - Test if port 32000 is open:
If it says "Connection refused", check Ubuntu's firewall:nc -zv 192.168.49.2 32000
If port 32000 isn't allowed, add it:sudo ufw statussudo ufw allow 32000/tcp - Alternatively, use Minikube's built-in service access command to bypass potential port forwarding headaches:
This will either open your browser to the correct Jenkins URL or print a valid address you can use directly.minikube service <jenkins-service-name> -n <your-namespace>
6. Bonus: Check Ingress (if you're using it)
If you set up an Ingress resource to expose Jenkins, verify the Ingress Controller is running:
kubectl get pods -n kube-system | grep ingress
Then check your Ingress configuration:
kubectl get ingress -n <your-namespace>
Ensure the host and backend service match your intended setup.
Take it one step at a time—start with cluster health, then move to the pod, service, and finally external access. You'll track down the root cause soon!
内容的提问来源于stack exchange,提问作者Leandro Lima

