Kubernetes LoadBalancer一直Pending,为何视频中正常而我的不行?
Pending (And How to Fix It) Hey Chris! Let’s break down why your WordPress LoadBalancer service is stuck showing <pending> for the external IP, while the one in your tutorial works smoothly.
The Root Cause
Docker Desktop for Mac’s built-in Kubernetes cluster doesn’t include a native LoadBalancer implementation out of the box. Unlike cloud providers (like AWS or GCP) that automatically provision a load balancer when you create a LoadBalancer type service, the local Docker Desktop cluster has no way to assign a real external IP unless you add a third-party tool to handle this.
The tutorial you’re following likely had this tool pre-configured, or used an older version of Docker Desktop where this functionality was handled differently. That’s why their LoadBalancer got an external IP without extra steps.
Fixing It (Based on the Docker for Mac Issue #2445)
The author of that issue got it working by using MetalLB—a tool designed to provide LoadBalancer capabilities for local Kubernetes clusters. Here’s how to set it up:
Verify your Kubernetes cluster is running
First, confirm your Docker Desktop Kubernetes cluster is up and accessible:kubectl cluster-infoYou should see output pointing to your local Kubernetes control plane.
Install MetalLB
MetalLB needs a dedicated namespace and core resources to run:- Create the namespace:
kubectl create namespace metallb-system - Apply MetalLB’s core deployment manifest (you can get this from MetalLB’s official release files, save it as
metallb.yamlfirst):kubectl apply -f metallb.yaml
- Create the namespace:
Configure an IP Address Pool
MetalLB needs a range of IP addresses it can assign to your LoadBalancer services. These should be within the subnet that Docker Desktop uses for its virtual machine.- Create a file named
metallb-config.yamlwith this content (adjust the IP range to match your Docker Desktop subnet—common ranges are192.168.64.0/24or192.168.1.0/24):apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | address-pools: - name: default protocol: layer2 addresses: - 192.168.64.100-192.168.64.150 - Apply the config:
kubectl apply -f metallb-config.yaml
- Create a file named
Check Your WordPress Service
After setting up MetalLB, wait a minute or two, then check your service again:kubectl get service wordpressYou should now see an external IP assigned from the range you configured instead of
<pending>.
Why the Tutorial Worked
Chances are the tutorial either:
- Used an older version of Docker Desktop that had a built-in LoadBalancer simulator,
- Pre-configured MetalLB behind the scenes,
- Or actually used a
NodePortservice (which exposes ports directly on the cluster nodes) but referred to it as a LoadBalancer for simplicity.
Give these steps a try, and your LoadBalancer should get an external IP in no time!
内容的提问来源于stack exchange,提问作者Chris G.

