【问题标题】:digitalocean kubernetes loadbalancerdigitalocean Kubernetes 负载均衡器
【发布时间】:2019-05-27 18:02:26
【问题描述】:

我已将我的应用部署在 DigitalOcean 上有限的可用 Kubernetes 集群上。 我有一个 Spring Boot 应用程序,其服务暴露在端口 31744 上,用于使用 nodeport 服务配置进行外部访问。

我使用每个 DO 链接文档的 yaml 配置创建了一个负载均衡器:https://www.digitalocean.com/docs/kubernetes/how-to/add-load-balancer/

但是,我无法连接到我的服务。你能告诉我如何做到这一点,以便我可以从负载均衡器访问我的服务吗?

以下是我的应用服务的“kubectl get svc”输出:

NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
my-springboot          NodePort       10.245.6.216    <none>           8080:31744/TCP   2d18h
kubernetes             ClusterIP      10.245.0.1      <none>           443/TCP          3d20h
sample-load-balancer   LoadBalancer   10.245.53.168   58.183.251.550   80:30495/TCP     2m6s

以下是我的loadbalancer.yaml:

apiVersion: v1
kind: Service
metadata:
  name: sample-load-balancer
spec:
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 31744
      name: http

我的 service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: my-springboot
  labels:
    app: my-springboot
    tier: backend
spec:
  type: NodePort
  ports:
    # the port that this service should serve on
  - port: 8080
  selector:
    app: my-springboot
    tier: backend

谢谢

【问题讨论】:

  • 那么当您点击服务命令中显示的外部 IP 时会发生什么?
  • @Sonam,你能分享一下服务配置吗?
  • 该外部ip根本没有内容输出。

标签: kubernetes digital-ocean


【解决方案1】:

要使用LoadBalancer 而不是NodePort 公开您的服务,您需要在服务中提供type 作为LoadBalancer。所以你的新服务配置 yaml 将是:

apiVersion: v1
kind: Service
metadata:
  name: my-springboot
  labels:
    app: my-springboot
    tier: backend
spec:
  type: LoadBalancer
  ports:
    # the port that this service should serve on
  - port: 8080
  selector:
    app: my-springboot
    tier: backend

应用上述服务yaml文件后,您将获得kubectl get svc中的外部IP,可用于从kubernetes集群外部访问服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-23
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 2021-12-07
    • 1970-01-01
    相关资源
    最近更新 更多