我在Kubernetes上运行Spring Boot Microservices时遇到了问题,安装Minikube后,我启动了它并打开了它的 Jmeter 板。
以下是打开 Jmeter 板的命令。
接下来,我通过此命令运行所有服务。
kubectl apply -f k8s
在等待了一定的时间后,我得到了下面显示的这个问题。
15:22:37.395 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.cloud.config.client.ConfigClientFailFastException: Could not locate PropertySource and the resource is not optional, failing
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:197)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:102)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:61)
at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:107)
at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:128)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:116)
at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:311)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:232)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:344)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.microservice.orderservice.OrderServiceApplication.main(OrderServiceApplication.java:15)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://config-server-svc:9296/ORDER-SERVICE/default": connect timed out; nested exception is java.net.SocketTimeoutException: connect timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.getRemoteEnvironment(ConfigServerConfigDataLoader.java:303)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:118)
... 35 common frames omitted
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:508)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603)
at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:276)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:375)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:396)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1253)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1015)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
... 39 common frames omitted
下面是我的部署. yaml文件。
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-service-app
spec:
selector:
matchLabels:
app: auth-service-app
template:
metadata:
labels:
app: auth-service-app
spec:
containers:
- name: auth-service-app
image: noyandocker/authservice
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7777
env:
- name: CONFIG_SERVER_URL
valueFrom:
configMapKeyRef:
name: config-cm
key: config_url
- name: EUREKA_SERVER_ADDRESS
valueFrom:
configMapKeyRef:
name: eureka-cm
key: eureka_service_address
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: mysql-cm
key: hostname
---
apiVersion: v1
kind: Service
metadata:
name: auth-service-svc
spec:
selector:
app: auth-service-app
ports:
- port: 80
targetPort: 7777
下面是配置Mapyaml文件
apiVersion: v1
kind: ConfigMap
metadata:
name: config-cm
data:
config_url: "config-server-svc"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: eureka-cm
data:
eureka_service_address: "http://eureka-0.eureka:8761/eureka"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-cm
data:
hostname: "mysql-0.mysql"
下面是配置服务器部署. yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: config-server-app
spec:
selector:
matchLabels:
app: config-server-app
template:
metadata:
labels:
app: config-server-app
spec:
containers:
- name: config-server-app
image: noyandocker/configserver
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9296
readinessProbe:
httpGet:
path: /actuator/health
port: 9296
initialDelaySeconds: 20
timeoutSeconds: 10
periodSeconds: 3
failureThreshold: 2
livenessProbe:
httpGet:
path: /actuator/health
port: 9296
initialDelaySeconds: 30
timeoutSeconds: 2
periodSeconds: 8
failureThreshold: 1
env:
- name: EUREKA_SERVER_ADDRESS
valueFrom:
configMapKeyRef:
name: eureka-cm
key: eureka_service_address
---
apiVersion: v1
kind: Service
metadata:
name: config-server-svc
spec:
selector:
app: config-server-app
ports:
- port: 80
targetPort: 9296
我认为所有服务都将同时启动。配置服务器是所有其他服务(如身份验证服务)的依赖服务,在配置服务器服务启动并运行之前,不应启动此身份验证服务。
我该怎么做呢?
下面是我的回购:Link
下面是我的Docker集线器:Link
下面是git后端系统:Link
1条答案
按热度按时间kknvjkwl1#
当在微服务架构中工作时,你不能依赖于服务之间的依赖关系。如果一个服务由于硬件问题而关闭了怎么办?所有的平台都将不可用?
其实每个微服务都要做好不可用服务的准备,可以用Circuit Breaker来做,据我所知Kubernetes不支持这种依赖。
尽管如此,我发现了一些可以在这里使用的黑客:https://www.alibabacloud.com/blog/kubernetes-demystified-solving-service-dependencies_594110
在您的情况下,如果服务配置服务器在启动其他服务时不可用,您可以向服务添加一些重试机制。这样,它们将在5次或5次尝试后尝试访问服务配置服务器。请查看此处,https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.1.4.RELEASE/multi/multi__spring_cloud_config_client.html#config-client-retry