Nginx Ingress无法提供服务:Ingress资源未分配IP求助
Let's break down the steps to fix your issue where the Ingress resource has no assigned IP and you can't access jenkins.xyz.com. Since you're working with a 3-node kubeadm cluster and the Nginx Ingress Controller, here's what to check and fix:
1. Verify the Nginx Ingress Controller Deployment & Service
The mandatory.yaml you applied deploys the controller components, but it might not set up a service that exposes the controller externally (especially in on-prem/non-cloud kubeadm clusters).
First, check if the controller pods are running:
kubectl get pods -n ingress-nginxAll pods should show a
Runningstatus. If any are stuck, check their logs withkubectl logs <pod-name> -n ingress-nginxfor errors.Next, check the controller's service type:
kubectl get svc -n ingress-nginxIf the service is of type
ClusterIP, that means the controller isn't exposed to the outside world—this is why your Ingress resource has no assigned IP. You have two options here:- Option 1: Switch to NodePort (quick fix for testing):
Edit the service to change its type:
Changekubectl edit svc ingress-nginx -n ingress-nginxtype: ClusterIPtotype: NodePort, save the changes. Now you'll see node ports assigned to port 80 and 443. You can access Jenkins viahttp://<any-node-ip>:<node-port-for-80>. - Option 2: Deploy MetalLB (for a proper LoadBalancer IP):
Since kubeadm clusters don't have a built-in LoadBalancer provider (unlike cloud clusters), MetalLB can assign a static IP range to your Ingress Controller. Once deployed, change the controller service type toLoadBalancer, and it will get an IP from your configured range—this IP will then show up in your Ingress resource'sADDRESSfield.
- Option 1: Switch to NodePort (quick fix for testing):
2. Validate Ingress API Version Compatibility
Your Ingress uses extensions/v1beta1, which is deprecated in Kubernetes 1.19 and later. While this might not be the immediate cause of the missing IP, it's best to update to the stable API version to avoid future issues. Modify your Ingress YAML to use networking.k8s.io/v1:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: jenkins-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - host: jenkins.xyz.com http: paths: - path: / pathType: Prefix backend: service: name: jenkins-svc port: number: 80
Apply the updated file with kubectl apply -f <ingress-file.yaml>.
3. Confirm Backend Services & Pods Are Healthy
Before blaming the Ingress, ensure your Jenkins deployment and service are working correctly:
- Check if Jenkins pods are running:
kubectl get pods -l component=web - Test accessing the service directly from within the cluster (or via port-forward):
Then openkubectl port-forward svc/jenkins-svc 8080:80http://localhost:8080in your browser—if Jenkins loads, the backend is working, and the issue is definitely with the Ingress/Controller setup.
4. Fix DNS Resolution
For jenkins.xyz.com to work, you need to ensure the domain resolves to the correct IP:
- If using NodePort: Point the domain to any of your cluster nodes' public/private IPs.
- If using MetalLB/LoadBalancer: Point the domain to the LoadBalancer IP assigned to the Ingress Controller service.
You can test this locally by adding an entry to your /etc/hosts file (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows):
<target-ip> jenkins.xyz.com
5. Check Ingress Controller Logs for Errors
If the above steps don't resolve the issue, dig into the Ingress Controller logs to see if it's failing to process your Ingress resource:
kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx
Look for lines mentioning jenkins-ingress—common issues include mislabeled selectors or invalid Ingress configuration.
内容的提问来源于stack exchange,提问作者pawarchinmay27

