CongThanh Mai
CongThanh Mai

Reputation: 51

How to Inject Kubernetes Service to my java class?

I have created and deployed successfully one service in kubernetes named rest_api_service.

I have another project which needs to call a resource from rest_api_service. So, in order to get out the IP of my service, I tried to inject:

@Inject
@ServiceName("luz-person-service")
String serivceUrl;

But my Eclipse shows me this warn message:

> No bean is eligible for injection to the injection point [JSR-346
> §5.2.2]

Therefore I can not build it in wildfly.

Currently, I am working only on pure Java EE 7 and I'm using the following dependency:

<dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>fabric8-cdi</artifactId>
    <version>2.1.11</version>
</dependency> 

Do you guys have any idea?

Upvotes: 1

Views: 206

Answers (1)

Paul Morie
Paul Morie

Reputation: 15778

Pods are automatically injected with environment variables containing information about services in their namespace. As an example, say your pod is in a namespace that also contains a service named 'foo'. The containers in your pod will be injected with:

FOO_SERVICE_HOST=<host service foo is reachable at>
FOO_SERVICE_PORT=<port service foo is reachable at>

as well as docker-links style environment variables. Check out the docs here.

Upvotes: 1

Related Questions