请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

为什么ingress-nginx-controller的LoadBalancer 一直在 pending状态

[root@k8s-master-31 ~]# kubectl get all -n ingress-nginx

NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-d5jpj        0/1     Completed   0          62m
pod/ingress-nginx-admission-patch-6h7bb         0/1     Completed   0          62m
pod/ingress-nginx-controller-8668bd45fd-cbh4f   1/1     Running     0          62m

NAME                                         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             LoadBalancer   10.233.65.78   <pending>     80:30744/TCP,443:31237/TCP   62m
service/ingress-nginx-controller-admission   ClusterIP      10.233.7.203   <none>        443/TCP                      62m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           62m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-8668bd45fd   1         1         1       62m

NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           1s         62m
job.batch/ingress-nginx-admission-patch    1/1           2s         62m

现在的情况是 :ingress-nginx-controller 已经是 running 状态了,但为何 service/ingress-nginx-controller 的 LoadBalancer 一直是 pending 状态?
是不是由于:公有云环境除外,是没有LB能力的?经过找到资料 :https://blog.csdn.net/textdemo123/article/details/99400237
之前一直运行的 ingress-demo ,也一直因为 ingress 的问题不可访问,虽然是running 状态,配置文件为 :
[root@k8s-master-31 ~]# cat ingress-demo.yaml

#deploy
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-demo
spec:
  selector:
    matchLabels:
      app: tomcat-demo
  replicas: 1
  template:
    metadata:
      labels:
        app: tomcat-demo
    spec:
      containers:
      - name: tomcat-demo
        image: registry.cn-hangzhou.aliyuncs.com/liuyi01/tomcat:8.0.51-alpine
        ports:
        - containerPort: 8080
---
#service
apiVersion: v1
kind: Service
metadata:
  name: tomcat-demo
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: tomcat-demo

---
#ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tomcat-demo
spec:
  rules:
  - host: tomcat.mooc.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: tomcat-demo
            port:
              number: 80

[root@k8s-master-31 ~]# kubectl get svc -o wide

NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE    SELECTOR
kubernetes            ClusterIP   10.233.0.1       <none>        443/TCP   5d6h   <none>
springboot-web-demo   ClusterIP   10.233.161.134   <none>        80/TCP    2d     app=springboot-web-demo
tomcat-demo           ClusterIP   10.233.164.83    <none>        80/TCP    22m    app=tomcat-demo

在 ingress controller 启动后,再来 apply 这个 demo 文件的时候还会报错 :
[root@k8s-master-31 ~]# kubectl apply -f ingress-demo.yaml

deployment.apps/tomcat-demo unchanged
service/tomcat-demo unchanged
Error from server (InternalError): error when creating "ingress-demo.yaml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": dial tcp 10.233.7.203:443: connect: connection timed out

正在回答 回答被采纳积分+3

1回答

刘果国 2022-02-05 10:28:31

是的首先需要让ingress-nginx正常服务,才能使用它的服务发现能力。

你这里的svc类型是loadbalancer,如果是云环境需要购买它的lb服务。也可以修改svc为其他的类型,比如nodeport;也可以直接让pod的网络为host,把端口直接暴露在所在的节点上。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信