1. Answers
  2. Stateful Sets with Persistent Storage for Solr on Kubernetes

How do I implement stateful sets for persistent storage in Solr on Kubernetes?

In this guide, we will implement a stateful set for Apache Solr with persistent storage on a Kubernetes cluster using Pulumi. Stateful sets are essential for applications like Solr that require stable network identities and persistent storage.

Key Points:

  • We will create a Kubernetes StatefulSet for Solr.
  • We will define a PersistentVolumeClaim (PVC) to ensure persistent storage.
  • We will configure the StatefulSet to use the PVC for Solr data.
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";

// Define a PersistentVolumeClaim for Solr data
const solrPvc = new kubernetes.core.v1.PersistentVolumeClaim("solr-pvc", {
    metadata: {
        name: "solr-pvc",
    },
    spec: {
        accessModes: ["ReadWriteOnce"],
        resources: {
            requests: {
                storage: "10Gi",
            },
        },
    },
});

// Define the Solr StatefulSet
const solrStatefulSet = new kubernetes.apps.v1.StatefulSet("solr", {
    metadata: {
        name: "solr",
    },
    spec: {
        serviceName: "solr",
        replicas: 3,
        selector: {
            matchLabels: {
                app: "solr",
            },
        },
        template: {
            metadata: {
                labels: {
                    app: "solr",
                },
            },
            spec: {
                containers: [
                    {
                        name: "solr",
                        image: "solr:latest",
                        ports: [
                            {
                                containerPort: 8983,
                                name: "solr",
                            },
                        ],
                        volumeMounts: [
                            {
                                name: "solr-data",
                                mountPath: "/var/solr",
                            },
                        ],
                    },
                ],
            },
        },
        volumeClaimTemplates: [
            {
                metadata: {
                    name: "solr-data",
                },
                spec: {
                    accessModes: ["ReadWriteOnce"],
                    resources: {
                        requests: {
                            storage: "10Gi",
                        },
                    },
                },
            },
        ],
    },
});

// Export the name of the StatefulSet
export const statefulSetName = solrStatefulSet.metadata.name;

Summary

In this guide, we created a Kubernetes StatefulSet for Apache Solr with persistent storage using Pulumi. We defined a PersistentVolumeClaim to ensure that Solr’s data is stored persistently across pod restarts and failures. This setup is crucial for maintaining data integrity and consistency in stateful applications like Solr.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up