You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地部署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.2 is its default node IP), check its status:
    minikube status
    
    If it's stopped, start it back up with minikube start.
  • Check if your cluster node is in a Ready state:
    kubectl get nodes
    
    If the node says NotReady, inspect the kubelet service on your Ubuntu machine:
    sudo systemctl status kubelet
    
    If it's not running, restart it with sudo 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 CrashLoopBackOff or Error, pull the pod logs to find startup issues:
    kubectl logs <jenkins-pod-name> -n <your-namespace>
    
    Common problems here include failed image pulls (double-check your image name, e.g., 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 TYPE is NodePort (since you're using port 32000).
  • The PORT(s) column shows something like 8080: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 Endpoints field: 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:
    # 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}'
    
    If they don't match, update the service's selector to align with the pod's labels.

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:
    ping 192.168.49.2
    
    If ping fails, restart Minikube with minikube stop && minikube start.
  • Test if port 32000 is open:
    nc -zv 192.168.49.2 32000
    
    If it says "Connection refused", check Ubuntu's firewall:
    sudo ufw status
    
    If port 32000 isn't allowed, add it:
    sudo ufw allow 32000/tcp
    
  • Alternatively, use Minikube's built-in service access command to bypass potential port forwarding headaches:
    minikube service <jenkins-service-name> -n <your-namespace>
    
    This will either open your browser to the correct Jenkins URL or print a valid address you can use directly.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 12:12:39