faq,

Service Mesh - Kubernetes LoadBalancer Service External IP pending

中文阅读

Problem Description

If you are using a custom Kubernetes cluster (using minikube, kubeadm or the like). In this case, there is no LoadBalancer integrated (unlike cloud vendors such as AWS, Google Cloud, and Alibaba Cloud). With this default setup, you can only use NodePort or an Ingress Controller.

At this time, if you deploy LoadBalancer, the External-IP will always be in pending state.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$ cat <<EOF | kubectl apply -f -
kind: Service
apiVersion: v1
metadata:
  name: nginx-ils-service
spec:
  ports:
    - name: http
      port: 80
      nodePort: 30062
  selector:
    app: nginx
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
          - containerPort: 80
  selector:
    matchLabels:
      app: nginx
EOF
1
2
3
4
$ kubectl get service
NAME                TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes          ClusterIP      10.96.0.1      <none>        443/TCP        11m
nginx-ils-service   LoadBalancer   10.98.76.166   <pending>     80:30062/TCP   2m1s

Solution

minikube

If you are using minikube,the official provides the following convenient solution:

1
2
3
4
5
6
7
8
9
10
11
$ minikube tunnel
Status:
	machine: minikube
	pid: 22554
	route: 10.96.0.0/12 -> 192.168.64.3
	minikube: Running
	services: [nginx-ils-service]
    errors:
		minikube: no errors
		router: no errors
		loadbalancer emulator: no errors

After executing the above command, External-IP will appear soon, see https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-tunnel for details.

1
2
3
4
$ kubectl get service
NAME                TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
kubernetes          ClusterIP      10.96.0.1      <none>         443/TCP        13m
nginx-ils-service   LoadBalancer   10.98.76.166   10.98.76.166   80:30062/TCP   3m26s

Visit EXTERNAL-IP from a browser, verify it.

kubeadm

If you are using kubeadm,you can refer to Build Kubernetes & Istio environment with kubeadm and MetalLB and use MetalLB to solve this problem.

Reference


CatchZeng
Written by CatchZeng Follow
AI (Machine Learning) and DevOps enthusiast.