我已经在DigitalOcean上有限可用的Kubernetes集群上部署了我的应用程序。我有一个spring引导应用程序,它在端口31744上公开了一个服务,用于使用nodeport配置进行外部操作。
我使用yaml配置/ DO链接文档: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谢谢
发布于 2019-01-01 04:30:07
要使用LoadBalancer而不是NodePort公开您的服务,您需要以LoadBalancer的形式在服务中提供type。因此,您的新服务配置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,该IP可用于从kubernetes集群外部访问服务。
https://stackoverflow.com/questions/53983478
复制相似问题