如何使用kubernetes-config扩展加载ConfigMap

问题描述

我一直遵循https://quarkus.io/guides/kubernetes-config来创建configMap并将Quarkus服务测试到我的CDK v3.5.0-1中,然后再将其推送到OpenShift 3.11,但KubernetesConfigSourceProvider并不满意:

使用:

  • Quarkus 1.8.1.Final
  • Java 11
  • CDK 3.5

这是我要转换为configMap的yaml文件:oc create configmap quarkus-service-configmap --from-file=application.yml

jaeger_endpoint: http://192.168.56.100:14268/api/traces
jaeger_sampler_manager_host_port: 192.168.56.100:14250
sql_debug: false
quarkus:
    datasource:
        db-kind: h2
        jdbc:
            detect-statement-leaks: true
            driver: io.opentracing.contrib.jdbc.TracingDriver
            enable-metrics: true
            url: jdbc:tracing:h2:./db;AUTO_SERVER=TRUE
        max-size: 13
        metrics:
            enabled: false
        password: sa
        username: sa
    flyway:
        locations: db/prod/migration
        migrate-at-start: true
    hibernate-orm:
        database:
            charset: UTF-8
            generation: none
        dialect: org.hibernate.dialect.H2Dialect
    http:
        port: 6280
    jaeger:
        enabled: true
        endpoint: ${jaeger_endpoint}
        sampler-manager-host-port: ${jaeger_sampler_manager_host_port}
        sampler-param: 1
        sampler-type: const
    resteasy:
        gzip:
            enabled: true
            max-input: 10M
    smallrye-health:
        ui:
            always-include: true
    swagger-ui:
        always-include: true

这是生成的configMap:

apiVersion: v1
data:
  application.yml: |
    jaeger_endpoint: http://192.168.56.100:14268/api/traces
    jaeger_sampler_manager_host_port: 192.168.56.100:14250
    sql_debug: false
    quarkus:
        datasource:
            db-kind: h2
            jdbc:
                detect-statement-leaks: true
                driver: io.opentracing.contrib.jdbc.TracingDriver
                enable-metrics: true
                url: jdbc:tracing:h2:./db;AUTO_SERVER=TRUE
            max-size: 13
            metrics:
                enabled: false
            password: sa
            username: sa
        flyway:
            locations: db/prod/migration
            migrate-at-start: true
        hibernate-orm:
            database:
                charset: UTF-8
                generation: none
            dialect: org.hibernate.dialect.H2Dialect
        http:
            port: 6280
        jaeger:
            enabled: true
            endpoint: ${jaeger_endpoint}
            sampler-manager-host-port: ${jaeger_sampler_manager_host_port}
            sampler-param: 1
            sampler-type: const
        resteasy:
            gzip:
                enabled: true
                max-input: 10M
        smallrye-health:
            ui:
                always-include: true
        swagger-ui:
            always-include: true
kind: ConfigMap
metadata:
  creationTimestamp: '2020-09-21T17:56:40Z'
  name: quarkus-service-configmap
  namespace: dci
  resourceVersion: '9572968'
  selfLink: >-
    /api/v1/namespaces/dci/configmaps/quarkus-service-configmap
  uid: cd4570ff-fc33-11ea-bff0-080027af1c97

这是我的quarkus-service / src / main / resources / application.yml:


quarkus:
    application:
        name: quarkus-service
    kubernetes-config: # https://quarkus.io/guides/kubernetes-config
        enabled: true
        fail-on-missing-config: true
        config-maps: quarkus-service-configmap
        # secrets: quarkus-service-secrets
    jaeger:
        service-name: ${quarkus.application.name}
    http:
        port: 6280
    log:
        category:
            "io.quarkus.kubernetes.client":
                level: DEBUG
            "io.fabric8.kubernetes.client":
                level: DEBUG
        console:
            format: '%d{HH:mm:ss} %-5p traceId=%X{traceId},spanId=%X{spanId},sampled=%X{sampled} [%c{2.}] (%t) %s%e%n'
    native:
        additional-build-args: -H:ReflectionConfigurationFiles=reflection-config.json

'%minishift':
    quarkus:
        kubernetes: # https://quarkus.io/guides/deploying-to-openshift / https://quarkus.io/guides/kubernetes
            container-image:
                group: dci
                registry: image-registry.openshift-image-registry.svc:5000
            deploy: true
            expose: true

我运行的命令:mvn clean package -Dquarkus.profile=minishift

我得到的结果:

WARN: Unrecognized configuration key "%s" was provided; it will be ignored; verify that the dependency extension for this configuration is set or you did not make a typo
Sep 21,2020 6:36:15 PM io.quarkus.config
WARN: Unrecognized configuration key "%s" was provided; it will be ignored; verify that the dependency extension for this configuration is set or you did not make a typo
Sep 21,2020 6:36:15 PM org.hibernate.validator.internal.util.Version
INFO: HV000001: Hibernate Validator %s
Sep 21,2020 6:36:27 PM io.quarkus.application
ERROR: Failed to start application (with profile minishift)
java.lang.RuntimeException: Unable to obtain configuration for ConfigMap objects from Kubernetes API Server at: https://172.30.0.1:443/ 
    at io.quarkus.kubernetes.client.runtime.KubernetesConfigSourceProvider.getConfigMapConfigSources(KubernetesConfigSourceProvider.java:85)
    at io.quarkus.kubernetes.client.runtime.KubernetesConfigSourceProvider.getConfigSources(KubernetesConfigSourceProvider.java:45)
    at io.quarkus.runtime.configuration.ConfigUtils.addSourceProvider(ConfigUtils.java:107)
    at io.quarkus.runtime.configuration.ConfigUtils.addSourceProviders(ConfigUtils.java:121)
    at io.quarkus.runtime.generated.Config.readConfig(Config.zig:2060)
    at io.quarkus.deployment.steps.RuntimeConfigSetup.deploy(RuntimeConfigSetup.zig:60)
    at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:509)
    at io.quarkus.runtime.Application.start(Application.java:90)
    at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:91)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:61)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
    at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Operation: [get]  for kind: [ConfigMap]  with name: [quarkus-service-configmap]  in namespace: [dci]  failed.
    at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:64)
    at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:72)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.getMandatory(BaseOperation.java:244)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.get(BaseOperation.java:187)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.get(BaseOperation.java:79)
    at io.quarkus.kubernetes.client.runtime.KubernetesConfigSourceProvider.getConfigMapConfigSources(KubernetesConfigSourceProvider.java:69)
    ... 12 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.base/java.net.SocketInputStream.socketRead0(Native Method)
    at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:467)
    at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:461)
    at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:160)
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:110)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1403)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1309)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:440)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:411)
    at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:336)
    at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:300)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:185)
    at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
    at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
    at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
    at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at io.fabric8.kubernetes.client.utils.BackwardsCompatibilityInterceptor.intercept(BackwardsCompatibilityInterceptor.java:134)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor.intercept(ImpersonatorInterceptor.java:68)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at io.fabric8.kubernetes.client.utils.HttpClientUtils.lambda$createHttpClient$3(HttpClientUtils.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
    at okhttp3.RealCall.execute(RealCall.java:81)
    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:490)
    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:451)
    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleGet(OperationSupport.java:416)
    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleGet(OperationSupport.java:397)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.handleGet(BaseOperation.java:890)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.getMandatory(BaseOperation.java:233)
    ... 15 more

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...