我使用fabric8io编写服务函数,相关代码如下
KubernetesClient fabricClient = new DefaultKubernetesClient();
fabricClient.pods().inNamespace("xxxnamespace").withLabel("somekey", somevalue).list().getItems()
当我进行单元测试时,它运行良好。但当我部署整个应用程序并触发服务功能时,它抛出了一个错误,如下所示
java.lang.RuntimeException: Error processing bean
at org.springframework.statemachine.processor.MethodInvokingStateMachineRuntimeProcessor.process(MethodInvokingStateMachineRuntimeProcessor.java:70) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineHandler.handle(StateMachineHandler.java:135) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineHandlerCallHelper.getStateMachineHandlerResults(StateMachineHandlerCallHelper.java:438) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineHandlerCallHelper.callOnTransition(StateMachineHandlerCallHelper.java:237) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.StateMachineObjectSupport.notifyTransition(StateMachineObjectSupport.java:225) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.AbstractStateMachine$3.transit(AbstractStateMachine.java:329) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.handleTriggerTrans(DefaultStateMachineExecutor.java:287) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.handleTriggerTrans(DefaultStateMachineExecutor.java:210) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.processTriggerQueue(DefaultStateMachineExecutor.java:450) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.access$200(DefaultStateMachineExecutor.java:64) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor$1.run(DefaultStateMachineExecutor.java:330) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.scheduleEventQueueProcessing(DefaultStateMachineExecutor.java:353) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor.access$500(DefaultStateMachineExecutor.java:64) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.support.DefaultStateMachineExecutor$2.triggered(DefaultStateMachineExecutor.java:540) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.trigger.CompositeTriggerListener.triggered(CompositeTriggerListener.java:34) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.trigger.TimerTrigger.notifyTriggered(TimerTrigger.java:123) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.trigger.TimerTrigger.access$000(TimerTrigger.java:33) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.trigger.TimerTrigger$1.run(TimerTrigger.java:117) [spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_181]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_181]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_181]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Caused by: java.lang.RuntimeException: io.fabric8.kubernetes.client.KubernetesClientException: Operation: [list] for kind: [Pod] with name: [null] in namespace: [biztech-bos] failed.
at com.xxxx.saveBuildLog(BosBuildLogAop.java:56) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at com.xxxx.BosBuildLogAop.logAround(BosBuildLogAop.java:39) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at sun.reflect.GeneratedMethodAccessor689.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at com.xxxx.statemachine.TransitionActionConfig$$EnhancerBySpringCGLIB$$165e28b8.checkingIncrementDtsDeploy(<generated>) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at sun.reflect.GeneratedMethodAccessor823.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:130) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:111) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:54) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:390) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:116) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:365) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.statemachine.support.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineMethodInvokerHelper.processInternal(StateMachineMethodInvokerHelper.java:243) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineMethodInvokerHelper.process(StateMachineMethodInvokerHelper.java:119) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.MethodInvokingStateMachineRuntimeProcessor.process(MethodInvokingStateMachineRuntimeProcessor.java:68) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
... 27 more
Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Operation: [list] for kind: [Pod] with name: [null] in namespace: [biztech-bos] failed.
at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:64) ~[kubernetes-client-5.2.1.jar:?]
at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:72) ~[kubernetes-client-5.2.1.jar:?]
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.listRequestHelper(BaseOperation.java:168) ~[kubernetes-client-5.2.1.jar:?]
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:664) ~[kubernetes-client-5.2.1.jar:?]
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:86) ~[kubernetes-client-5.2.1.jar:?]
at com.xxxx.service.impl.DTSServiceImpl.checkDeployIncrementDts(DTSServiceImpl.java:217) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at com.xxxx.configuration.statemachine.TransitionActionConfig.checkingIncrementDtsDeploy(TransitionActionConfig.java:96) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at com.xxxx.configuration.statemachine.TransitionActionConfig$$FastClassBySpringCGLIB$$f83ad12a.invoke(<generated>) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at com.xxxx.server.aop.BosBuildLogAop.saveBuildLog(BosBuildLogAop.java:52) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at com.xxxx.server.aop.BosBuildLogAop.logAround(BosBuildLogAop.java:39) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at sun.reflect.GeneratedMethodAccessor689.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at com.xxxx.server.configuration.statemachine.TransitionActionConfig$$EnhancerBySpringCGLIB$$165e28b8.checkingIncrementDtsDeploy(<generated>) ~[bos-coordinator-server-1.30.0-SNAPSHOT.jar:?]
at sun.reflect.GeneratedMethodAccessor823.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181]
at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:130) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:111) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:54) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:390) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:116) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:365) ~[spring-expression-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.statemachine.support.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineMethodInvokerHelper.processInternal(StateMachineMethodInvokerHelper.java:243) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.StateMachineMethodInvokerHelper.process(StateMachineMethodInvokerHelper.java:119) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.statemachine.processor.MethodInvokingStateMachineRuntimeProcessor.process(MethodInvokingStateMachineRuntimeProcessor.java:68) ~[spring-statemachine-core-2.2.0.RELEASE.jar:2.2.0.RELEASE]
... 27 more
Caused by: java.net.UnknownHostException: kubernetes.default.svc
at java.net.InetAddress.getAllByName0(InetAddress.java:1280) ~[?:1.8.0_181]
at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_181]
at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_181]
...
其中CCD_ 1是我的服务实现类
在部署机器上,我把kubeconfig文件放在~/.kube/config上,kubectl
命令行运行良好
我不知道如何处理这个问题。知道我该如何找出异常原因吗
提前感谢!
Fabric8使用Kubernetes REST API来执行它们的操作,默认情况下,它们的HTTP客户端假设它在Kubernetes集群内运行,这就是它试图访问kubernetes.default.svc
的原因
由于您在集群外调用它,因此必须告诉Fabric8集群的地址,这可以通过在创建客户端期间指定主机来完成
new DefaultKubernetesClient("https://my-cluster");
如果您能够通过SSH连接到运行应用程序的服务器并ping集群地址,那么fabric8很可能会工作。
多亏了@Yayotron和我的同事,我为kubeconfig
系统属性设置了错误的路径
根据这个问题,我将kubeconfig
系统属性设置为某个特定路径,以便fabric8客户端可以从该路径获取kubeconfig文件,并获取集群信息/身份验证令牌等。
因此,如果将来有人遇到此异常,您可以考虑客户端配置是否配置正确。