开发者社区> 问答> 正文

digitalocean kubernetes负载均衡器

我已经在DigitalOcean上有限的可用Kubernetes集群上部署了我的应用程序。我有一个Spring Boot应用程序,在端口31744上公开了一个服务,用于外部使用nodeport服务配置。

我使用每个DO链接文件的yaml配置创建了一个Loadbalancer: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 8080:31744/TCP 2d18h
kubernetes ClusterIP 10.245.0.1 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

展开
收起
k8s小能手 2019-01-11 14:25:23 2161 0
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可用于从kubernetes集群外部访问服务的外部IP 。
    2019-07-17 23:25:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《应用型负载均衡ALB产品解读》 立即下载
阿里云网络-SLB负载均衡产品介绍 立即下载
负载均衡SLB热点问题解答 立即下载

相关镜像