首页 文章

为什么Google Cloud在使用ClusterIP时会出现错误

提问于
浏览
6

在我的gcloud控制台中,它显示了我定义的入口的以下错误:

同步期间出错:评估入口规范时出错:服务“monitoring / kube-prometheus”是“ClusterIP”类型,预期“NodePort”或“LoadBalancer”

我使用traefik作为反向代理(而不是nginx),因此我使用ClusterIP定义入口 . 据我了解这个过程,所有流量都通过traefik服务代理(其中定义了Loadbalancer入口),因此我的所有其他入口应该实际上有一个ClusterIP而不是NodePort或Loadbalancer?

Question:

那么为什么Google Cloud警告我它期望NodePort或LoadBalancer?

enter image description here

1 回答

  • 3

    我不知道为什么会发生这种错误,因为看起来(对我而言)是一个有效的配置 . 但要清除错误,您可以将服务切换到命名的NodePort . 然后切换入口以使用端口名称而不是数字 . 例如:

    服务:

    apiVersion: v1
    kind: Service
    metadata:
      name: testapp
    spec:
      ports:
      - name: testapp-http # ADD THIS
        port: 80
        protocol: TCP
        targetPort: 80
      selector:
        app: testapp
      type: NodePort
    

    入口:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: testapp
    spec:
      rules:
      - host: hostname.goes.here
        http:
          paths:
          - backend:
              serviceName: testapp
              # USE THE PORT NAME FROM THE SERVICE INSTEAD OF THE PORT NUMBER
              servicePort: testapp-http
            path: /
    

    更新:

    这是我从谷歌收到的解释 .

    由于默认服务是ClusterIP [1],因此可以从集群内部访问此类服务 . 当使用kube-proxy时,可以从外部访问它,并不意味着可以通过入口直接访问 .

    作为一个建议,我个人认为这篇文章[2]有助于理解这些类型服务之间的区别 .

    [1] https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

    [2] https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0

相关问题