Using kubernetes ceph.rook.io with postgres-operator.crunchydata.com
TypeScriptWhen integrating Ceph storage into a Kubernetes cluster managed by Rook and using it with a PostgreSQL database managed by the Crunchy Data PostgreSQL Operator, you are typically looking to achieve persistent, scalable, and reliable storage for your database instances. Rook provides the management of storage clusters and the interface for your Kubernetes cluster to interact with the storage, for example, to provision volumes. The PostgreSQL Operator facilitates the deployment and management of PostgreSQL clusters in Kubernetes.
The following Pulumi program demonstrates how to create a Kubernetes cluster, install Rook with Ceph as the storage provider, and deploy the Crunchy Data PostgreSQL Operator. Afterwards, it creates a PostgreSQL cluster with storage backed by Ceph.
Here's how the program is structured:
-
Create a Kubernetes Cluster: This is a necessary prerequisite. Usually, you'd use a cloud-specific provider like EKS for AWS, AKS for Azure, or GKE for Google Cloud. For simplicity and to focus on Rook and Crunchy Data, we'll assume you already have a configured Kubernetes cluster that Pulumi can access.
-
Namespace Creation: We create Kubernetes namespaces for Rook and Crunchy Data to have separate environments for these services.
-
Install Rook and Ceph: We use Helm to install the Rook operator and then create a CephCluster custom resource to set up the Ceph storage cluster.
-
Install Crunchy Data PostgreSQL Operator: Again, we utilize Helm to install the PostgreSQL operator provided by Crunchy Data.
-
Create a PostgreSQL Cluster: Once the storage class is available (from the Ceph installation), we create a PostgreSQL cluster that uses Ceph as its storage.
Please note that deploying a Kubernetes cluster and complex setups like Rook or the Crunchy Data PostgreSQL operator can take a while, and this program will require these tools to be installed and configured:
- Pulumi CLI
- Helm CLI
- Access to a Kubernetes Cluster
Let's get started with the Pulumi TypeScript program:
import * as k8s from '@pulumi/kubernetes'; import * as pulumi from '@pulumi/pulumi'; // Step 1: Use the configured Kubernetes cluster // Export KUBECONFIG or have a valid `~/.kube/config` to access your cluster. // Step 2: Creating the required namespaces const rookNamespace = new k8s.core.v1.Namespace('rook-ceph', { metadata: { name: 'rook-ceph' }, }); const pgNamespace = new k8s.core.v1.Namespace('postgres', { metadata: { name: 'postgres' }, }); // Step 3: Install Rook and Ceph const rookChart = new k8s.helm.v3.Chart('rook-ceph', { chart: 'rook-ceph', fetchOpts: { repo: 'https://charts.rook.io/release', }, namespace: rookNamespace.metadata.name, version: '1.7.3', // Use a specific chart version that is compatible with your cluster }); const cephCluster = new k8s.yaml.ConfigFile('ceph-cluster', { file: 'https://raw.githubusercontent.com/rook/rook/release-1.7/cluster/examples/kubernetes/ceph/cluster.yaml', namespace: rookNamespace.metadata.name, }); // Waiting for the Rook resources to be ready before installing the PostgreSQL operator. const k8sProvider = new k8s.Provider('k8s-provider', { kubeconfig: pulumi.output(rookChart.resources).apply(r => r['v1/ServiceAccount:rook-ceph:rook-ceph'].metadata.namespace + '/cluster.kubeconfig'), }); // Step 4: Installing the Crunchy Data PostgreSQL Operator const pgOperatorChart = new k8s.helm.v3.Chart('postgres-operator', { chart: 'postgres-operator', fetchOpts: { repo: 'https://charts.crunchydata.com/charts', }, namespace: pgNamespace.metadata.name, version: '4.7.3', // Use a version compatible with the PostgreSQL version you intend to use // Adjust the values to configure the PostgreSQL operator for your specific needs values: { /* Fill in desired configuration values */ }, }, { provider: k8sProvider }); // Step 5: Create a PostgreSQL cluster // For the PostgreSQL cluster to be created, ensure that the Rook Ceph storage class is available // and specified correctly according to your Ceph setup in the values for the `pgCluster` resource. // Assuming we have a StorageClass named 'rook-ceph-block' const pgCluster = new k8s.yaml.ConfigFile('postgres-cluster', { file: 'https://raw.githubusercontent.com/CrunchyData/postgres-operator/v4.7.3/installers/kubectl/postgres.yaml', namespace: pgNamespace.metadata.name, resourcePrefix: 'my-pg-cluster', // change this to something unique values: { /* Desired PostgreSQL configuration and reference to the StorageClass created by Ceph */ metadata: { name: 'my-postgres-cluster', }, spec: { storageclass: 'rook-ceph-block', // replace with your storage class name /* further configurations */ }, }, }, { provider: k8sProvider }); export const pgClusterName = pgCluster.getResource('v1/Service', 'my-postgres-cluster'); // Important notes: // - Save the Helm chart versions and file URLs in a configuration file or as Pulumi config values for production use // - Ensure proper cleanup of resources to avoid unnecessary costs in a cloud-based Kubernetes cluster
This program represents a basic outline, and real-world usage may require more configurations, error handling, and security settings. Also, make sure Rook and the PostgreSQL operator versions are compatible with your Kubernetes version. Adjust the versions in the program accordingly.
Remember, resources on the cloud can incur costs; always monitor and manage resources appropriately.
-