Class KubernetesSeedNodeProvider
- java.lang.Object
-
- io.hekate.cluster.seed.kubernetes.KubernetesSeedNodeProvider
-
- All Implemented Interfaces:
SeedNodeProvider
,ConfigReportSupport
public class KubernetesSeedNodeProvider extends Object implements SeedNodeProvider, ConfigReportSupport
Kubernetes-based implementation ofSeedNodeProvider
interface.Overview
This provider uses Kubernetes API server to search for all Pods that have a specially named port (Hekate cluster port). Name of that port can be specified via the
KubernetesSeedNodeProviderConfig.setContainerPortName(String)
configuration property (default value is defined byKubernetesSeedNodeProviderConfig.DEFAULT_CONTAINER_PORT_NAME
).Example of Pod definition:
--- apiVersion: v1 kind: Pod metadata: name: my-hekate-app spec: containers: - image: my-hekate-app:v1 name: my-hekate-app ports: - name: hekate # <--- This (Hekate cluster port) containerPort: 10012 - name: http # ...some other ports... containerPort: 8080
Note that Pods can have different containers of different types that run different applications, but if such applications must form a single Hekate cluster then all of them should use the same name of Hekate cluster port.
Configuration
Please see the documentation of
KubernetesSeedNodeProviderConfig
class for details about the available configuration options.Kubernetes Role-based Access Control (RBAC)
If Kubernetes cluster is running with Role-based Access Control enabled then it is important to make sure that Pod has permissions to read information about other Pods from Kubernetes API server. It can be done by creating an RBAC Role and binding it to the Pod's Service Account.
The following example provides a basic example of granting permissions for a Service Account to read information about other Pods:
--- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: read-pods rules: - apiGroups: - "" resources: - pods verbs: - list - get --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: hekate roleRef: kind: Role name: read-pods apiGroup: rbac.authorization.k8s.io subjects: - kind: ServiceAccount name: default # Notice! This overrides permissions of 'default' Service Account.
-
-
Constructor Summary
Constructors Constructor Description KubernetesSeedNodeProvider(KubernetesSeedNodeProviderConfig cfg)
Constructs new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
cleanupInterval()
Returns the time interval in milliseconds for the cluster service to perform the stale data cleaning.String
containerPortName()
Container port name.List<InetSocketAddress>
findSeedNodes(String namespace)
Returns the list of known seed node addresses.String
masterUrl()
Kubernetes master URL.String
namespace()
Kubernetes namespace.void
registerRemote(String namespace, InetSocketAddress node)
Registered the specified addresses within this provider.void
report(ConfigReporter report)
Report configuration.void
startDiscovery(String namespace, InetSocketAddress node)
Registers the local node address and starts this provider.void
stopDiscovery(String namespace, InetSocketAddress node)
Unregisters the local node address and stops this provider.void
suspendDiscovery()
Suspends discovery activities.String
toString()
Boolean
trustCertificates()
true
if Kubernetes API must have a trusted certificate.void
unregisterRemote(String namespace, InetSocketAddress node)
Unregisters the specified address from this provider.
-
-
-
Constructor Detail
-
KubernetesSeedNodeProvider
public KubernetesSeedNodeProvider(KubernetesSeedNodeProviderConfig cfg)
Constructs new instance.- Parameters:
cfg
- Configuration.
-
-
Method Detail
-
report
public void report(ConfigReporter report)
Description copied from interface:ConfigReportSupport
Report configuration.- Specified by:
report
in interfaceConfigReportSupport
- Parameters:
report
- Reporter.
-
containerPortName
public String containerPortName()
Container port name.- Returns:
- Container port name.
- See Also:
KubernetesSeedNodeProviderConfig.setContainerPortName(String)
-
masterUrl
public String masterUrl()
Kubernetes master URL.- Returns:
- Master URL.
- See Also:
KubernetesSeedNodeProviderConfig.setMasterUrl(String)
-
namespace
public String namespace()
Kubernetes namespace.- Returns:
- Kubernetes namespace.
- See Also:
KubernetesSeedNodeProviderConfig.setNamespace(String)
-
trustCertificates
public Boolean trustCertificates()
true
if Kubernetes API must have a trusted certificate.- Returns:
true
if Kubernetes API must have a trusted certificate.- See Also:
KubernetesSeedNodeProviderConfig.setTrustCertificates(Boolean)
-
findSeedNodes
public List<InetSocketAddress> findSeedNodes(String namespace) throws HekateException
Description copied from interface:SeedNodeProvider
Returns the list of known seed node addresses.- Specified by:
findSeedNodes
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).- Returns:
- List of known seed node addresses.
- Throws:
HekateException
- if failed to provide seed node addresses information due to the system failure.
-
startDiscovery
public void startDiscovery(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Registers the local node address and starts this provider.- Specified by:
startDiscovery
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Local node address.- Throws:
HekateException
- If failed to start discovery due to the system failure.
-
suspendDiscovery
public void suspendDiscovery() throws HekateException
Description copied from interface:SeedNodeProvider
Suspends discovery activities.- Specified by:
suspendDiscovery
in interfaceSeedNodeProvider
- Throws:
HekateException
- If failed to suspend discovery activities due to some system failure.
-
stopDiscovery
public void stopDiscovery(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Unregisters the local node address and stops this provider.- Specified by:
stopDiscovery
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Local node address.- Throws:
HekateException
- If failed to stop discovery due to the system failure.
-
cleanupInterval
public long cleanupInterval()
Description copied from interface:SeedNodeProvider
Returns the time interval in milliseconds for the cluster service to perform the stale data cleaning. If the returned value if less than or equals to zero then stale data cleaning will be disabled.- Specified by:
cleanupInterval
in interfaceSeedNodeProvider
- Returns:
- Time interval in milliseconds.
-
registerRemote
public void registerRemote(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Registered the specified addresses within this provider.This method is the part of a stale data cleanup activity and is performed by the cluster service if it detects that particular node is within its cluster topology but is not registered within this provider (i.e. not returned from
SeedNodeProvider.findSeedNodes(String)
method).- Specified by:
registerRemote
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Node address that should be registered.- Throws:
HekateException
- If node couldn't be registered due to the system failure.
-
unregisterRemote
public void unregisterRemote(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Unregisters the specified address from this provider.This method is the part of a stale data cleanup activity and is called by the cluster service if it detects that there is no cluster node running at the specified address while this address is still registered within this provider (i.e. is returned from
SeedNodeProvider.findSeedNodes(String)
method).- Specified by:
unregisterRemote
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Node address that should be unregistered.- Throws:
HekateException
- If node couldn't be unregistered due to the system failure.
-
-