Customizing Resources
The Solr Operator creates a number of Kubernetes resources to run a SolrCloud (StatefulSet, Services, ConfigMap, etc.).
Most aspects of these resources can be customized through SolrCloud.spec.customSolrKubeOptions, which exposes per-resource option objects such as podOptions, statefulSetOptions, commonServiceOptions, and others.
This allows you to add labels, annotations, environment variables, affinity rules, resource requests, extra containers, and more, without the operator needing explicit support for every option.
Mounting Additional Volumes
Arbitrary additional volumes can be mounted into the Solr pods (and their init/sidecar containers) via SolrCloud.spec.customSolrKubeOptions.podOptions.volumes.
This is separate from the data storage used for Solr’s index data.
Some example scenarios where this is useful:
-
Custom Solr plugins that rely on certain data being present on disk.
-
Bootstrapping additional configuration for Solr via a
ConfigMap. -
A dedicated volume to support backups.
Each entry under volumes has the following fields:
-
name- The name of the volume, used to reference it from containervolumeMounts. -
source- A standard Kubernetes volume source (e.g.configMap,persistentVolumeClaim,secret,emptyDir). The required fields depend on the source type chosen (for example, aconfigMapsource requiresname, while apersistentVolumeClaimsource requiresclaimName). -
defaultContainerMount- An optionalvolumeMountdescribing where the volume should be mounted in the main Solr container. Init containers and sidecar containers can mount the same volume by referencing it bynamein their ownvolumeMounts.
The following example mounts a ConfigMap into the Solr container and a sidecar container:
spec:
customSolrKubeOptions:
podOptions:
volumes:
- source:
configMap:
name: configset
defaultMode: 0777
name: configset
defaultContainerMount:
mountPath: /configset
name: configset
sidecarContainers:
- name: config-loader
image: alpine/curl:latest
command:
- "sh"
- "-c"
- "ls -la /configset"
volumeMounts:
- name: configset
mountPath: /configset
A complete, runnable example (including the backing ConfigMap) is available in example/test_solrcloud_additional_volume.yaml.
Environment Variables
Additional environment variables can be added to the Solr container in two ways, both under SolrCloud.spec.customSolrKubeOptions.podOptions:
-
envVars- A list of individual environment variables, each either a literalvalueor avalueFromreference to a single key. -
envFrom- A list ofenvFromsources, each loading every key of aConfigMap(configMapRef) orSecret(secretRef) as an environment variable. An optionalprefixis prepended to each variable name, andoptional: truelets the pod start even if the referenced resource does not exist.
Variables set by the operator and by envVars take precedence over those loaded via envFrom, since Kubernetes gives env priority over envFrom when the same name is defined in both.
This means envFrom cannot be used to override the environment variables the operator sets, such as SOLR_JAVA_MEM or ZK_HOST.
Kubernetes only reads the referenced ConfigMaps and Secrets when a container starts.
Changing their contents does not restart the Solr pods, so the new values are only picked up once the pods are restarted for another reason.
The following example sets a single variable directly, and loads all keys of a ConfigMap, and all keys of a Secret with a SOLR_ prefix, into the Solr container:
spec:
customSolrKubeOptions:
podOptions:
envVars:
- name: SOLR_LOG_LEVEL
value: WARN
envFrom:
- configMapRef:
name: solr-env-config
- prefix: SOLR_
secretRef:
name: solr-env-secrets
optional: true
Service Session Affinity
The Services that the operator creates for a SolrCloud (commonServiceOptions, headlessServiceOptions, and nodeServiceOptions) can be configured with session affinity.
This is useful when clients connect to Solr through the common Service and you want requests from a given client IP to be routed to the same Solr pod.
For headlessServiceOptions and nodeServiceOptions, this option provides no value because each service endpoint maps to a single pod.
Each service option object exposes two fields:
-
sessionAffinity- EitherNone(the default) orClientIP. When set toClientIP, connections from the same client IP are directed to the same backing pod. -
sessionAffinityConfig- Optional session affinity configuration, only used whensessionAffinityisClientIP. Most commonly this sets theclientIP.timeoutSecondssticky-session timeout (defaults to10800, i.e. 3 hours).
The following example enables client-IP session affinity on the common Service with a one hour timeout:
spec:
customSolrKubeOptions:
commonServiceOptions:
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 3600