opensearch

by apecloud

Helm chartv1.2.0-alpha.0App 2.7.0Verified publisher

Open source distributed and RESTful search engine.

About this chart

OpenSearch

OpenSearch is a scalable, flexible, and extensible open-source software suite for search, analytics, and observability applications licensed under Apache 2.0.

Features In KubeBlocks

Lifecycle Management

HorizontalscalingVertical scalingExpandvolumeRestartStop/StartConfigureExposeSwitchover
YesYesYesYesYesNoYesNo

Versions

Versions
2.7.0

Prerequisites

  • Kubernetes cluster >= v1.21

  • kubectl installed, refer to K8s Install Tools

  • Helm, refer to Installing Helm

  • KubeBlocks installed and running, refer to Install Kubeblocks

  • OpenSearch Addon Enabled, refer to Install Addons

  • Create K8s Namespace demo, to keep resources created in this tutorial isolated:

    kubectl create ns demo
    

Examples

Create

Create a opensearch cluster with three replicas:

# cat examples/opensearch/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: opensearch-cluster
  namespace: demo
spec:
  # Specifies the behavior when a Cluster is deleted.
  # Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies a list of ClusterComponentSpec objects used to define the
  # individual Components that make up a Cluster.
  # This field allows for detailed configuration of each Component within the Cluster
  componentSpecs:
    - name: opensearch
      componentDef: opensearch-core
      # ServiceVersion specifies the version of the Service expected to be
      # provisioned by this Component.
      # Valid options are: [2.7.0]
      serviceVersion: "2.7.0"
      replicas: 3
      resources:
        limits:
          cpu: "1"
          memory: 1Gi
        requests:
          cpu: "1"
          memory: 1Gi
      volumeClaimTemplates:
        - name: data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 20Gi
    - name: dashboard
      componentDef: opensearch-dashboard
      # ServiceVersion specifies the version of the Service expected to be
      # provisioned by this Component.
      # Valid options are: [2.7.0]
      replicas: 1
      resources:
        limits:
          cpu: "1"
          memory: 1Gi
        requests:
          cpu: "1"
          memory: 1Gi

kubectl apply -f examples/opensearch/cluster.yaml

To access the OpenSearch cluster, you can use the following command to get the service URL:

kubectl port-forward svc/opensearch-cluster-opensearch 9200:9200

Then you can check the cluster status with the following command:

curl -u admin:admin -X GET https:/127.0.0.1:9200/_cluster/health?pretty --insecure

Ensure the status field is green before proceeding with the next steps.

To check the roles of nodes in the cluster, you can use the following command:

curl -u admin:admin -X GET https:/127.0.0.1:9200/_nodes?pretty --insecure

For more information of OpenSearch APIs, please refer to OpenSearch APIs

To access OpenSearch Dashboard, you can use the following command to get the service URL:

kubectl port-forward svc/opensearch-cluster-dashboard 5601:5601

Then you can access the OpenSearch Dashboard with the following URL:

http://localhost:5601/app/home#/

And you can login with the default username and password:

username: admin
password: admin

Horizontal scaling

Scale-out

Horizontal scaling out cluster by adding ONE more OpenSearch replica:

# cat examples/opensearch/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-scale-out
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
  - componentName: opensearch
    # Specifies the replica changes for scaling out components
    scaleOut:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1

kubectl apply -f examples/opensearch/scale-out.yaml

And you can check the progress of the scaling operation with following command:

Scale-in

Horizontal scaling in cluster by deleting ONE replica:

# cat examples/opensearch/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-scale-in
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
  - componentName: opensearch
    # Specifies the replica changes for scaling out components
    scaleIn:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1

kubectl apply -f examples/opensearch/scale-in.yaml

Scale-in/out using Cluster API

Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  terminationPolicy: Delete
  componentSpecs:
    - name: opensearch
      componentDef: opensearch-core
      serviceVersion: "2.7.0"
      replicas: 3 # update replicas to your need (but not zero)

Vertical scaling

Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster

# cat examples/opensearch/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-verticalscaling
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: VerticalScaling
  # Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
  verticalScaling:
    # - opensearch
    # - dashboard
  - componentName: opensearch
    # VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
    requests:
      cpu: '1.5'
      memory: 1.5Gi
    limits:
      cpu: '1.5'
      memory: 1.5Gi

kubectl apply -f examples/opensearch/verticalscale.yaml

Expand volume

Increase size of volume storage with the specified components in the cluster

# cat examples/opensearch/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-volumeexpansion
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: VolumeExpansion
  # Lists VolumeExpansion objects, each specifying a component and its corresponding volumeClaimTemplates that requires storage expansion.
  volumeExpansion:
    # Specifies the name of the Component.
  - componentName: opensearch
    # volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
    volumeClaimTemplates:
    - name: data
      storage: 30Gi

kubectl apply -f examples/opensearch/volumeexpand.yaml

Restart

Restart the specified components in the cluster

# cat examples/opensearch/restart.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-restart
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: Restart
  # Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
  restart:
    # Specifies the name of the Component.
    # - opensearch
    # - dashboard
  - componentName: opensearch

kubectl apply -f examples/opensearch/restart.yaml

Stop

Stop the cluster and release all the pods of the cluster, but the storage will be reserved

# cat examples/opensearch/stop.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-stop
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: Stop

kubectl apply -f examples/opensearch/stop.yaml

Start

Start the stopped cluster

# cat examples/opensearch/start.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: opensearch-start
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: opensearch-cluster
  type: Start

kubectl apply -f examples/opensearch/start.yaml

Delete

If you want to delete the cluster and all its resource, you can modify the termination policy and then delete the cluster

kubectl patch cluster -n demo opensearch-cluster -p '{"spec":{"terminationPolicy":"WipeOut"}}' --type="merge"

kubectl delete cluster -n demo opensearch-cluster

Deploy opensearch with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has opensearch on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartopensearch is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply