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 createdKubernetesEndpointGroupBuilderwith the specified KubernetesConfig.builder(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) Returns a newly createdKubernetesEndpointGroupBuilderwith the specifiedKubernetesClient.builder(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, boolean autoClose) Returns a newly createdKubernetesEndpointGroupBuilderwith the specifiedKubernetesClient.protected voiddoCloseAsync(CompletableFuture<?> future) Override this method to release the resources held by thisEndpointGroupand complete the specifiedCompletableFuture.static KubernetesEndpointGroupReturns a newly createdKubernetesEndpointGroupwith the specifiedConfig,namespaceandserviceName.static KubernetesEndpointGroupof(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, String namespace, String serviceName) Returns a newly createdKubernetesEndpointGroupwith the specifiedKubernetesClient,namespaceandserviceName.static KubernetesEndpointGroupReturns a newly createdKubernetesEndpointGroupwith the specifiedserviceName.static KubernetesEndpointGroupMethods 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, whenReadyMethods inherited from class com.linecorp.armeria.common.util.AbstractListenable
addListener, addListener, notifyListeners, removeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 createdKubernetesEndpointGroupwith the specifiedKubernetesClient,namespaceandserviceName.Note that the
KubernetesClientwill not be automatically closed when theKubernetesEndpointGroupis closed. -
of
public static KubernetesEndpointGroup of(io.fabric8.kubernetes.client.Config config, String namespace, String serviceName) Returns a newly createdKubernetesEndpointGroupwith the specifiedConfig,namespaceandserviceName. -
of
Returns a newly createdKubernetesEndpointGroupwith the specifiedserviceName. The default configuration in the$HOME/.kube/configwill be used to create aKubernetesClient. -
of
Returns a newly createdKubernetesEndpointGroupwith the specifiednamespaceandserviceName. 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 createdKubernetesEndpointGroupBuilderwith the specifiedKubernetesClient.Note that the
KubernetesClientwill not be automatically closed when theKubernetesEndpointGroupis closed. -
builder
public static KubernetesEndpointGroupBuilder builder(io.fabric8.kubernetes.client.KubernetesClient kubernetesClient, boolean autoClose) Returns a newly createdKubernetesEndpointGroupBuilderwith the specifiedKubernetesClient.- Parameters:
autoClose- whether to close theKubernetesClientwhen theKubernetesEndpointGroupis closed.
-
builder
public static KubernetesEndpointGroupBuilder builder(io.fabric8.kubernetes.client.Config kubeConfig) Returns a newly createdKubernetesEndpointGroupBuilderwith the specified KubernetesConfig. -
doCloseAsync
Description copied from class:DynamicEndpointGroupOverride this method to release the resources held by thisEndpointGroupand complete the specifiedCompletableFuture.- Overrides:
doCloseAsyncin classDynamicEndpointGroup
-