如何为fabric8-cdi设置环境

时间:2017-01-05 21:34:01

标签: cdi kubernetes fabric8

我正在尝试使用此处所述的fabric8-cdihttps://fabric8.io/guide/cdi.html

我在开发时使用minikube,我启动了一个名为mev-rserve的rc和服务,这是运行的服务:

$kubectl get services
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
kubernetes   10.0.0.1     <none>        443/TCP          2d
mev-rserve   10.0.0.19    <pending>     6311:31744/TCP   49m

在我的webapp中,我有这个bean生产者:

@Produces
static RConnection r (@ServiceName ("mev-rserve") String endpoint) { /* ... */ }

如果我按照我链接的文档中所述声明MEV_RSERVE_SERVICE_HOSTMEV_RSERVE_SERVICE_PORT env变量,哪个工作正常,但我希望库从kube api中查找,但这并没有发生。这是我的配置:

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /Users/levkuznetsov/.minikube/ca.crt
    server: https://192.168.99.101:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /Users/levkuznetsov/.minikube/apiserver.crt
    client-key: /Users/levkuznetsov/.minikube/apiserver.key

从那时起,我按如下方式设置了环境:

KUBERNETES_MASTER="https://192.168.99.101:8443"
KUBERNETES_API_VERSION="v1"
KUBERNETES_CERTS_CA_FILE="/Users/levkuznetsov/.minikube/ca.crt"
KUBERNETES_CERTS_CLIENT_FILE="/Users/levkuznetsov/.minikube/apiserver.crt"
KUBERNETES_CERTS_CLIENT_KEY_FILE="/Users/levkuznetsov/.minikube/apiserver.key"

导致此异常:

Caused by: java.lang.IllegalArgumentException: No kubernetes service could be found for name: mev-rserve in namespace: null
at io.fabric8.kubernetes.api.KubernetesHelper.getServiceURL(KubernetesHelper.java:1347)
at io.fabric8.cdi.Services.toServiceUrl(Services.java:38)
at io.fabric8.cdi.producers.ServiceUrlProducer.produce(ServiceUrlProducer.java:47)
at io.fabric8.cdi.producers.ServiceUrlProducer.produce(ServiceUrlProducer.java:26)
at io.fabric8.cdi.bean.ProducerBean.create(ProducerBean.java:43)
...

提前致谢

1 个答案:

答案 0 :(得分:0)

如果其他人正在努力解决这个问题,我将其追溯到缺乏命名空间定义。我没有声明KubernetesClient bean,所以我没有设置默认的命名空间,结果是null。我不想在应用程序中声明一个,因为在生产中环境变量无论如何都会优先,这仅用于开发。我发现相应地设置环境更清洁。