Using kubernetes autoscaling.k8s.io with ceph.rook.io
TypeScriptTo use Kubernetes' autoscaling with Rook Ceph storage, you need to understand two main components: the
HorizontalPodAutoscaler
from theautoscaling.k8s.io
group that manages the scaling of a deployment or replicaset, and theCephCluster
fromceph.rook.io
which manages a Ceph storage cluster on Kubernetes.The
HorizontalPodAutoscaler
(HPA) automatically scales the number of pods in a replication controller, deployment, or replicaset based on observed CPU utilization or with custom metrics support. Kubernetes communicates with Rook's Ceph cluster to use its storage capabilities, leveraging persistent volumes that dynamically provision storage as needed.Below is an example TypeScript program using Pulumi to create a Kubernetes
HorizontalPodAutoscaler
and aCephCluster
with Rook.import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create a Kubernetes Horizontal Pod Autoscaler const podAutoscaler = new k8s.autoscaling.v1.HorizontalPodAutoscaler("podAutoscaler", { metadata: { name: "ceph-autoscaler" }, spec: { scaleTargetRef: { kind: "Deployment", name: "my-ceph-deployment", apiVersion: "apps/v1", }, minReplicas: 1, maxReplicas: 4, targetCPUUtilizationPercentage: 60, }, }, { provider: k8sProvider }); // For a complete configuration of CephCluster, refer to the Rook documentation. // This is a simplified example to illustrate. const cephCluster = new k8s.apiextensions.CustomResource("cephCluster", { apiVersion: "ceph.rook.io/v1", kind: "CephCluster", metadata: { name: "my-rook-ceph-cluster" }, spec: { // Rook Ceph cluster specifications go here. // For example, the version of Ceph, the storage configuration, etc. }, }, { provider: k8sProvider }); // Export the name of the HPA export const horizontalPodAutoscalerName = podAutoscaler.metadata.name; // Export the name of Rook Ceph cluster export const cephClusterName = cephCluster.metadata.name;
In the program above, we import the necessary modules from Pulumi to work with Kubernetes. We then define two resources:
HorizontalPodAutoscaler
andCephCluster
.The
HorizontalPodAutoscaler
is set to target a deployment namedmy-ceph-deployment
. This HPA will increase or decrease the number of pod replicas in this deployment to maintain an average CPU utilization across all pods of 60%. The number of replicas will be between 1 and 4.The
CephCluster
is a custom resource defined by Rook, which you'll use to manage your Ceph storage cluster on Kubernetes. The spec provided within this CustomResource should contain the actual configuration for your Ceph cluster, such as the version of Ceph to use, storage configurations, etc. The actual spec will vary based on your particular requirements and should be crafted by referring to the Rook documentation.Finally, we export the names of both the HPA and the CephCluster so that they can be accessed easily if needed, for example, when further operations need to be performed on these resources using Pulumi.
Please note that this program assumes you already have a deployment named
my-ceph-deployment
that you intend to autoscale based on CPU usage. Also, the CephCluster resource will need to be fully defined based on your actual Rook Ceph cluster configuration. For more detailed requirements and configurations for Rook Ceph, refer to the Rook documentation.Make sure you have Pulumi installed and configured with the necessary cloud credentials before running the program. Also, ensure that you have the Kubernetes cluster running where you intend to deploy these resources.