# Volume

> The Listener Operator uses CSI PersistentVolumes to stabilize network addresses, inject pod metadata, and expose individual Pods with pinning.

The Listener Operator acts as a CSI PersistentVolume, which helps it to stabilize network addresses, inject pod metadata and expose individual Pods.

The listener volume represents a Pod being exposed by a [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md). The backing Listener can either be created [automatically by the Volume](https://docs.stackable.tech/home/stable/listener-operator/volume/index.md), or [manually by the operator](https://docs.stackable.tech/home/stable/listener-operator/volume/index.md).

## Stable addresses

Some [ListenerClass](https://docs.stackable.tech/home/stable/listener-operator/listenerclass/index.md) strategies, such as `NodePort`, tie the public address to the Kubernetes node that the Pod is running on. When this address must be configured statically in clients (such as for HDFS NameNodes), then Kubernetes' default "floating" scheduling either requires all clients to be reconfigured every time something moves, or for all clients to proxy their traffic through a single static node, which then becomes a single point of failure (along with the node that the workload is running on).

Mounting listeners into Pods as PersistentVolume allows the Listener Operator to pin these workloads to one node. Note that this only happens for [ListenerClass](https://docs.stackable.tech/home/stable/listener-operator/listenerclass/index.md)es that actually benefit from pinning.

## Downwards API

Some services (such as Kafka) need to know their external address, so that they can advertize it to their own replica discovery mechanism. [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md) volumes contain a file tree that exposes this information:

-   `default-address/`\- A symlink to `addresses/{primary address}`

-   `addresses/` - Contains information about all addresses associated with this [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md)

    -   `{address}/` - A folder is created for each address

        -   `address` - Contains the Pod’s address (IP address or hostname)

        -   `ports/` - Contains port numbers for each named port

            -   `{port name}` - Contains the public port number for this named port





## Individual pod exposure

Sometimes each replica must be exposed individually, for example because clients need to access data on a specific shard. PersistentVolumeClaim templates can be used to provision this automatically.

Listeners created by volumes share their volume’s lifetime; if the volume is deleted then so is the Listener.

### StatefulSet `volumeClaimTemplates`

The `volumeClaimTemplates` allow volumes to be provisioned for each StatefulSet replica. These volumes are _persistent_, and will not be deleted when the Pod or StatefulSet is. This makes them useful for provisioning addresses that must be hard-coded into client configuration.

### Pod-scoped ephemeral volumes

`Pod.spec.volumes[].ephemeral` allows volumes to be provisioned for each Pod. These volumes are tied to the lifetime of the Pod and will be deleted along with it. This makes them useful for provisioning temporary addresses that will be discovered out of band (such as for HDFS DataNodes).

## Shared exposure

Multiple replicas can reference the same [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md), by creating the Listener manually, and then setting the [`listeners.stackable.tech/listener-name`](https://docs.stackable.tech/home/stable/listener-operator/volume/index.md) annotation on the volume.

In this case, the injected Pod metadata _may_ still be specific to a particular Pod. For example, when binding [NodePort](https://docs.stackable.tech/home/stable/listener-operator/listenerclass/index.md) Listeners, the Pod will only contain metadata about the Node that it is actually running on.

[Pinning](https://docs.stackable.tech/home/stable/listener-operator/volume/index.md) (if applicable) is managed on the _volume_ scope, each replica binding a single Listener can be pinned to a different Node.

## Reference

All configuration must be specified as `annotations` on the PersistentVolumeClaim. The following attributes are currently supported:

### `listeners.stackable.tech/listener-name`

**Required**: If `listeners.stackable.tech/listener-class` is not specified

Provisions metadata about an existing [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md) that was created manually.

### `listeners.stackable.tech/listener-class`

**Required**: If `listeners.stackable.tech/listener-name` is not specified

Provisions a new [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md) using the specified [ListenerClass](https://docs.stackable.tech/home/stable/listener-operator/listenerclass/index.md). The created [Listener](https://docs.stackable.tech/home/stable/listener-operator/listener/index.md) will expose all of the Pod’s ports.
