nginx-ingress 停止工作,尽管服务已就绪 + pod(“没有任何活动端点。”)

发布于 2025-01-11 15:35:40 字数 1864 浏览 0 评论 0原文

我已将 microk8s 设置转移到新服务器,发现曾经有效的入口设置我的试用设置停止工作。

我正在运行这个最小的 whoami-app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami
  namespace: default
  labels:
    app: whoami
spec:
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
      - name: whoami
        image: containous/whoami
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: whoami
  namespace: default
spec:
  selector:
    app: whoami
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami
  namespace: default
  annotations:
    kubernetes.io/ingress.class: public
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: whoami
            port:
              number: 80

Pod 已启动并正在运行,服务正确暴露了它,但入口不起作用:

kubectl get services whoami
NAME     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
whoami   ClusterIP   10.152.183.184   <none>        80/TCP    26m
curl 10.152.183.184
Hostname: whoami-567b85d54d-qbbd5
IP: 127.0.0.1
IP: ::1
IP: 10.1.76.7
IP: fe80::e850:aaff:fe72:91c4
RemoteAddr: 192.168.0.102:21910
GET / HTTP/1.1
Host: 10.152.183.184
User-Agent: curl/7.68.0
Accept: */*
kubectl get ingress whoami
NAME     CLASS    HOSTS   ADDRESS     PORTS   AGE
whoami   <none>   *       127.0.0.1   80      28m

nginx-ingress-controller 日志显示了这些条目:

controller.go:1076] Service "default/whoami" does not have any active Endpoint.

但同样,通过 clusterIP 进行访问是有效的,因此两个Pod 和 Service 正在做他们的工作。

I have transferred my microk8s setup to a new server and found that the once-working ingress setup my trial setup stopped working.

I am running this minimal whoami-app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami
  namespace: default
  labels:
    app: whoami
spec:
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
      - name: whoami
        image: containous/whoami
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: whoami
  namespace: default
spec:
  selector:
    app: whoami
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami
  namespace: default
  annotations:
    kubernetes.io/ingress.class: public
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: whoami
            port:
              number: 80

Pod is up and running, service exposed it properly, but the ingress is not working:

kubectl get services whoami
NAME     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
whoami   ClusterIP   10.152.183.184   <none>        80/TCP    26m
curl 10.152.183.184
Hostname: whoami-567b85d54d-qbbd5
IP: 127.0.0.1
IP: ::1
IP: 10.1.76.7
IP: fe80::e850:aaff:fe72:91c4
RemoteAddr: 192.168.0.102:21910
GET / HTTP/1.1
Host: 10.152.183.184
User-Agent: curl/7.68.0
Accept: */*
kubectl get ingress whoami
NAME     CLASS    HOSTS   ADDRESS     PORTS   AGE
whoami   <none>   *       127.0.0.1   80      28m

The nginx-ingress-controller log shows these entries:

controller.go:1076] Service "default/whoami" does not have any active Endpoint.

But again, accessing through the clusterIP works, so both the Pod and the Service are doing their job.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柳絮泡泡 2025-01-18 15:35:40

我真的不知道这是怎么发生的,但端点与 Pod IP 不匹配。
我使用 kubectl delete endpoints whoami 手动删除了端点,它使用现在正确的 IP 重新创建,现在 ingress 似乎可以工作。

I don't really know how it happened, but the endpoint was not matching the pod IP.
I deleted the endpoint manually usind kubectl delete endpoints whoami, it got recreated with the now correct IP, now ingress seems to work.

⒈起吃苦の倖褔 2025-01-18 15:35:40

我很高兴听到你成功了。

我试图找到这种行为的原因,但不幸的是我还没有找到。 此链接有一些类似警告的解决方案。也许它会对某人有所帮助。

第一种情况是入口控制器的入口类与用于服务的入口资源清单中的入口类不匹配。

Nginx 安装命令,简短示例:

helm install stable/nginx-ingress \   
--名称 ${INGRESS_RELEASE_NAME} \   
--命名空间 ${K8S_NAMESPACE} \   
--setcontroller.scope.enabled=true\   
--setcontroller.scope.namespace=${K8S_NAMESPACE} \   
--setcontroller.ingressClass=${NGINX_INGRESS_CLASS}

入口资源规范。 ,摘录:

api版本:extensions/v1beta1 
种类:入口元数据:  
标签:
   注释:
    # 以下行对于 K8s 或 Helm 无效, 
    # 但反映的值必须相同
    kubernetes.io/ingress.class:${NGINX_INGRESS_CLASS} 

第二个解决方案是在服务选择器中包含 id 指令:

  selector:
    app: whoami
    id: "0"

另请参阅 StackOverflow 上的这些问题:

  1. K8 Ingress 没有端点
  2. Kubernetes 服务没有活动端点
  3. Kubernetes - ingress-nginx“无活动端点”错误

I am glad to hear you managed it work.

I tried to find the reason of that behavior but unfortunately I haven't found it yet. At this link there are some solutions to similar warning. Maybe it will help someone.

First one is situation when ingress class of the ingress controller mismatch ingress class in the ingress resource manifest used for services.

Nginx installation command, short example:

helm install stable/nginx-ingress \   
--name ${INGRESS_RELEASE_NAME} \   
--namespace ${K8S_NAMESPACE} \   
--set controller.scope.enabled=true \   
--set controller.scope.namespace=${K8S_NAMESPACE} \   
--set controller.ingressClass=${NGINX_INGRESS_CLASS}

ingress resource spec. , excerpt:

apiVersion: extensions/v1beta1 
kind: Ingress metadata:  
labels:
   annotations:
    # folowing line is not valid for K8s or Helm, 
    # but reflects the values must be the same
    kubernetes.io/ingress.class: ${NGINX_INGRESS_CLASS} 

In second solution is including id directive in service selector:

  selector:
    app: whoami
    id: "0"

See also these questions on StackOverflow:

  1. K8 Ingress does not have an endpoint
  2. Kubernetes Service does not have active Endpoint
  3. Kubernetes - ingress-nginx "no active endpoint" error
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文