【发布时间】:2018-08-29 20:49:57
【问题描述】:
我正在尝试在 Kubernetes (Minikube) 上部署一个“Hello world”Spring Boot 应用程序。 该应用程序非常简单,只有一种方法,它映射到 GET 资源上。我什至没有指定端口。
我现在正在尝试在 Minikube 上部署应用程序,并使用服务使其可用:
kind: Service
apiVersion: v1
metadata:
name: server
spec:
selector:
app: server
ports:
- protocol: TCP
port: 8080
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: server
spec:
selector:
matchLabels:
app: server
replicas: 3
template:
metadata:
labels:
app: server
spec:
containers:
- name: server
image: kubernetes-server:latest
imagePullPolicy: Never
ports:
- name: http
containerPort: 8080
如果我使用此配置启动部署(即先启动服务,然后启动部署),则 pod 在启动期间会失败。 在日志中,我可以找到以下消息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target
org.springframework.boot.autoconfigure.web.ServerProperties@42f93a98 failed:
Property: server.port
Value: tcp://10.98.151.181:8080
Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'port'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.lang.Integer]
注意:10.98.151.181 是 Service 的集群 IP,可以在 Minikube 仪表板中看到。
如果我首先触发实际的Deployment,应用程序启动成功,然后我可以启动Service。 不过官方文档建议先启动服务,然后部署:https://kubernetes.io/docs/concepts/configuration/overview/#services
对我来说,看起来 Service 设置了一个属性 server.port 作为环境变量,而在 Service 之后启动的 Spring Boot 应用程序意外地将其解释为 Spring server .port.
有什么办法解决这个问题吗?
【问题讨论】:
标签: spring-boot kubernetes minikube