org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes

## Class TcpDiscoveryKubernetesIpFinder

- java.lang.Object
- - org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter
  - - org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes.TcpDiscoveryKubernetesIpFinder

- All Implemented Interfaces:
    TcpDiscoveryIpFinder

      public class TcpDiscoveryKubernetesIpFinder
      extends TcpDiscoveryIpFinderAdapter

  IP finder for automatic lookup of Ignite nodes running in Kubernetes environment. All Ignite nodes have to deployed as Kubernetes pods in order to be discovered. An application that uses Ignite client nodes as a gateway to the cluster is required to be containerized as well. Applications and Ignite nodes running outside of Kubernetes will not be able to reach the containerized counterparts.

  The implementation is based on a distinct Kubernetes service that has to be created and should be deployed prior Ignite nodes startup. The service will maintain a list of all endpoints (internal IP addresses) of all containerized Ignite pods running so far. The name of the service must be equal to `setServiceName(String)` which is `ignite` by default.

  As for Ignite pods, it's recommended to label them in such a way that the service will use the label in its selector configuration excluding endpoints of irrelevant Kubernetes pods running in parallel.

  The IP finder, in its turn, will call this service to retrieve Ignite pods IP addresses. The port will be either the one that is set with `TcpDiscoverySpi.setLocalPort(int)` or `TcpDiscoverySpi.DFLT_PORT`. Make sure that all Ignite pods occupy a similar discovery port, otherwise they will not be able to discover each other using this IP finder.

  ## Optional configuration

  - The Kubernetes service name for IP addresses lookup (see `setServiceName(String)`)
  - The Kubernetes service namespace for IP addresses lookup (see `setNamespace(String)`
  - The host name of the Kubernetes API server (see `setMasterUrl(String)`)
  - Path to the service token (see `setAccountToken(String)`
  - To include not-ready pods (see `includeNotReadyAddresses(boolean)`

  Both `registerAddresses(Collection)` and `unregisterAddresses(Collection)` have no effect.

  Note, this IP finder is only workable when it used in Kubernetes environment. Choose another implementation of `TcpDiscoveryIpFinder` for local or home network tests.

- - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter

      `ignite`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TcpDiscoveryKubernetesIpFinder()` Creates an instance of Kubernetes IP finder.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<InetSocketAddress>` | `getRegisteredAddresses()` Gets all addresses registered in this finder.
    `void` | `includeNotReadyAddresses(boolean includeNotReadyAddresses)` Determines whether addresses of not-ready pods should be included.
    `void` | `registerAddresses(Collection<InetSocketAddress> addrs)` Registers new addresses.
    `void` | `setAccountToken(String accountToken)` Specifies the path to the service token file.
    `void` | `setMasterUrl(String master)` Sets the host name of the Kubernetes API server.
    `void` | `setNamespace(String namespace)` Sets the namespace the Kubernetes service belongs to.
    `void` | `setServiceName(String service)` Sets the name of Kubernetes service for Ignite pods' IP addresses lookup.
    `void` | `unregisterAddresses(Collection<InetSocketAddress> addrs)` Unregisters provided addresses.

    - ### Methods inherited from class org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter

      `close, discoveryClientMode, initializeLocalAddresses, isShared, onSpiContextDestroyed, onSpiContextInitialized, setShared, spiContext, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TcpDiscoveryKubernetesIpFinder

          public TcpDiscoveryKubernetesIpFinder()

      Creates an instance of Kubernetes IP finder.

  - ### Method Detail

    - #### getRegisteredAddresses

          public Collection<InetSocketAddress> getRegisteredAddresses()
                                                               throws IgniteSpiException

      Gets all addresses registered in this finder.
      Returns:
        All known addresses, potentially empty, but never `null`.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### registerAddresses

          public void registerAddresses(Collection<InetSocketAddress> addrs)
                                 throws IgniteSpiException

      Registers new addresses.

      Implementation should accept duplicates quietly, but should not register address if it is already registered.

      Parameters:
        `addrs` - Addresses to register. Not `null` and not empty.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### unregisterAddresses

          public void unregisterAddresses(Collection<InetSocketAddress> addrs)
                                   throws IgniteSpiException

      Unregisters provided addresses.

      Implementation should accept addresses that are currently not registered quietly (just no-op).

      Parameters:
        `addrs` - Addresses to unregister. Not `null` and not empty.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### setServiceName

          public void setServiceName(String service)

      Sets the name of Kubernetes service for Ignite pods' IP addresses lookup. The name of the service must be equal to the name set in service's Kubernetes configuration. If this parameter is not changed then the name of the service has to be set to 'ignite' in the corresponding Kubernetes configuration.
      Parameters:
        `service` - Kubernetes service name for IP addresses lookup. If it's not set then 'ignite' is used by default.

    - #### setNamespace

          public void setNamespace(String namespace)

      Sets the namespace the Kubernetes service belongs to. By default, it's supposed that the service is running under Kubernetes `default` namespace.
      Parameters:
        `namespace` - The Kubernetes service namespace for IP addresses lookup.

    - #### setMasterUrl

          public void setMasterUrl(String master)

      Sets the host name of the Kubernetes API server. By default the following host name is used: 'https://kubernetes.default.svc.cluster.local:443'.
      Parameters:
        `master` - The host name of the Kubernetes API server.

    - #### setAccountToken

          public void setAccountToken(String accountToken)

      Specifies the path to the service token file. By default the following account token is used: '/var/run/secrets/kubernetes.io/serviceaccount/token'.
      Parameters:
        `accountToken` - The path to the service token file.

    - #### includeNotReadyAddresses

          public void includeNotReadyAddresses(boolean includeNotReadyAddresses)

      Determines whether addresses of not-ready pods should be included. Default is false.
      Parameters:
        `includeNotReadyAddresses` - Flag to include not-ready pods.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020