digitalocean kubernetes 负载均衡器
digitalocean kubernetes loadbalancer
我已经在 DigitalOcean 上有限可用的 Kubernetes 集群上部署了我的应用程序。
我有一个 spring 启动应用程序,其服务在端口 31744 上公开,供外部使用 nodeport 服务配置。
我根据 DO link 文档使用 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
谢谢
要使用 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集群外部访问服务。
我已经在 DigitalOcean 上有限可用的 Kubernetes 集群上部署了我的应用程序。 我有一个 spring 启动应用程序,其服务在端口 31744 上公开,供外部使用 nodeport 服务配置。
我根据 DO link 文档使用 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
谢谢
要使用 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集群外部访问服务。