Class KubernetesEndpointGroup
java.lang.Object
com.linecorp.armeria.common.util.AbstractListenable<List<Endpoint>>
com.linecorp.armeria.client.endpoint.DynamicEndpointGroup
com.linecorp.armeria.client.kubernetes.endpoints.KubernetesEndpointGroup
- All Implemented Interfaces:
EndpointGroup
,EndpointSelector
,AsyncCloseable
,Listenable<List<Endpoint>>
,ListenableAsyncCloseable
,AutoCloseable
A
DynamicEndpointGroup
that fetches a node IP and a node port for each Pod from Kubernetes.
Note that the Kubernetes service must have a type of NodePort or 'LoadBalancer' to expose a node port for client side load balancing.
KubernetesEndpointGroup
watches the nodes, services and pods in the Kubernetes cluster and updates
the endpoints, so the credentials in the Config
used to create KubernetesClient
should
have permission to watch services
, nodes
and pods
. Otherwise, the
KubernetesEndpointGroup
will not be able to fetch the endpoints.
For instance, the following RBAC configuration is required:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: my-cluster-role
rules:
- apiGroups: [""]
resources: ["pods", "services", "nodes"]
verbs: ["watch"]
Example:
// Create a KubernetesEndpointGroup that fetches the endpoints of the 'my-service' service in the 'default'
// namespace. The Kubernetes client will be created with the default configuration in the $HOME/.kube/config.
KubernetesClient kubernetesClient = new KubernetesClientBuilder().build();
KubernetesEndpointGroup
.builder(kubernetesClient)
.namespace("default")
.serviceName("my-service")
.build();
// If you want to use a custom configuration, you can create a KubernetesEndpointGroup as follows:
// The custom configuration would be useful when you want to access Kubernetes from outside the cluster.
Config config =
new ConfigBuilder()
.withMasterUrl("https://my-k8s-master")
.withOauthToken("my-token")
.build();
KubernetesEndpointGroup
.builder(config)
.namespace("my-namespace")
.serviceName("my-service")
.build();
-
Method Summary
Modifier and TypeMethodDescriptionbuilder
(io.fabric8.kubernetes.client.Config kubeConfig) Returns a newly createdKubernetesEndpointGroupBuilder
with the specified KubernetesConfig
.builder
(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) Returns a newly createdKubernetesEndpointGroupBuilder
with the specifiedKubernetesClient
.builder
(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, boolean autoClose) Returns a newly createdKubernetesEndpointGroupBuilder
with the specifiedKubernetesClient
.protected void
doCloseAsync
(CompletableFuture<?> future) Override this method to release the resources held by thisEndpointGroup
and complete the specifiedCompletableFuture
.static KubernetesEndpointGroup
Returns a newly createdKubernetesEndpointGroup
with the specifiedConfig
,namespace
andserviceName
.static KubernetesEndpointGroup
of
(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, String namespace, String serviceName) Returns a newly createdKubernetesEndpointGroup
with the specifiedKubernetesClient
,namespace
andserviceName
.static KubernetesEndpointGroup
Returns a newly createdKubernetesEndpointGroup
with the specifiedserviceName
.static KubernetesEndpointGroup
Methods inherited from class com.linecorp.armeria.client.endpoint.DynamicEndpointGroup
addEndpoint, allowsEmptyEndpoints, builder, close, closeAsync, endpoints, isClosed, isClosing, latestValue, removeEndpoint, select, select, selectionStrategy, selectionTimeoutMillis, selectNow, setEndpoints, toString, toString, whenClosed, whenReady
Methods inherited from class com.linecorp.armeria.common.util.AbstractListenable
addListener, addListener, notifyListeners, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.endpoint.EndpointGroup
addListener, addListener, orElse, removeListener
-
Method Details
-
of
public static KubernetesEndpointGroup of(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, String namespace, String serviceName) Returns a newly createdKubernetesEndpointGroup
with the specifiedKubernetesClient
,namespace
andserviceName
.Note that the
KubernetesClient
will not be automatically closed when theKubernetesEndpointGroup
is closed. -
of
public static KubernetesEndpointGroup of(io.fabric8.kubernetes.client.Config config, String namespace, String serviceName) Returns a newly createdKubernetesEndpointGroup
with the specifiedConfig
,namespace
andserviceName
. -
of
Returns a newly createdKubernetesEndpointGroup
with the specifiedserviceName
. The default configuration in the$HOME/.kube/config
will be used to create aKubernetesClient
. -
of
Returns a newly createdKubernetesEndpointGroup
with the specifiednamespace
andserviceName
. The default configuration in the $HOME/.kube/config will be used to create aKubernetesClient
. -
builder
public static KubernetesEndpointGroupBuilder builder(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) Returns a newly createdKubernetesEndpointGroupBuilder
with the specifiedKubernetesClient
.Note that the
KubernetesClient
will not be automatically closed when theKubernetesEndpointGroup
is closed. -
builder
public static KubernetesEndpointGroupBuilder builder(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, boolean autoClose) Returns a newly createdKubernetesEndpointGroupBuilder
with the specifiedKubernetesClient
.- Parameters:
autoClose
- whether to close theKubernetesClient
when theKubernetesEndpointGroup
is closed.
-
builder
public static KubernetesEndpointGroupBuilder builder(io.fabric8.kubernetes.client.Config kubeConfig) Returns a newly createdKubernetesEndpointGroupBuilder
with the specified KubernetesConfig
. -
doCloseAsync
Description copied from class:DynamicEndpointGroup
Override this method to release the resources held by thisEndpointGroup
and complete the specifiedCompletableFuture
.- Overrides:
doCloseAsync
in classDynamicEndpointGroup
-