OpenSearch Kubernetes Operator Documentation

repository·main·Indexed 20 days ago

https://github.com/opensearch-project/opensearch-k8s-operator

The OpenSearch Kubernetes Operator automates the deployment, provisioning, management, and orchestration of OpenSearch clusters and OpenSearch Dashboards on Kubernetes. It provides capabilities for cluster management with multiple node pools, rolling version upgrades, online volume expansion, TLS hot reloading, and multi-namespace management. The operator is deployable via Helm charts and supports the opensearch.org/v1 API group.

Tokens
55.7K
Snippets
114
Records
192
Agent score
64%

What's inside OpenSearch Kubernetes Operator

  1. OpenSearch Kubernetes Operator Features

    main

    The operator provides the following capabilities for managing OpenSearch environments:

    • Cluster Management: Deploy and manage clusters with multiple node pools and configure all node roles (e.g., cluster_manager, data, ingest, coordinating).
    • Scaling & Upgrades: Scale cluster resources manually per node pool, perform rolling version upgrades with quorum-safe restarts, and perform online volume expansion for disk scaling.
    • Dashboards: Deploy and configure OpenSearch Dashboards.
    • Security & Plugins: Manage certificates with TLS hot reloading and install plugins during the bootstrap phase.
    • Organization: Support for multi-namespace management across organizational boundaries.
  2. Overview of OpenSearch Operator Monitoring Architecture

    main

    The OpenSearch Kubernetes Operator provides a monitoring solution designed to observe both the OpenSearch clusters it manages and the Operator itself.

    Monitoring Components

    • OpenSearch Monitoring: Since OpenSearch does not natively support the Prometheus text format, the operator installs the opensearch-prometheus-exporter plugin. This plugin exposes per-node metrics, as well as cluster and index-level metrics on specific nodes.
    • Operator Monitoring: The Go-based controller exposes its own internal metrics using the Prometheus Text Based Exposition format.
    • Getting Started Solution: When using the provided Helm charts, the operator can deploy a full monitoring stack including:
      • Prometheus: A time-series database that pulls metrics from OpenSearch and the Operator.
      • Alert Manager: Handles metric deduplication and notifications.
      • Grafana: A UI for visualizing metrics with pre-installed dashboards.
      • Prometheus Operator: Manages the Prometheus deployment and uses ServiceMonitor CRDs to discover OpenSearch nodes.
  3. Overview of the Data Integrity Testing Framework

    main

    The Data Integrity Testing Framework is a set of reusable components designed to verify that OpenSearch data remains intact during various cluster operations. It is composed of three main pillars:

    1. TestDataManager: Manages the lifecycle of test data, including importing documents into indices and validating that they remain intact after operations.
    2. ClusterOperations: Executes and monitors cluster-level changes such as scaling node pools, upgrading versions, or adding/removing node pools.
    3. Test Scenarios: Pre-built suites that combine the above components to test specific workflows like upgrades or scaling.

    This framework is primarily used within the functionaltests directory to ensure the operator maintains cluster stability.

  4. Frequently Asked Questions about API migration

    main

    Core Migration Concepts

    • Cluster Impact: Existing OpenSearch clusters (pods, data, etc.) are not affected. Only the Kubernetes CustomResource objects are migrated.
    • Simultaneous Usage: You can use both API groups during the deprecation period. However, note that:
      • Old API group resources can only be updated for status changes.
      • New API group resources must be used for all spec changes.
      • Deleting an old resource requires the new resource to exist.
    • Consistency: Deleting a new resource will automatically delete its corresponding old resource to maintain consistency.
    • Manual Creation: You can create resources directly in the new opensearch.org API group. The migration controller only syncs from old to new, not vice-versa.

    Limitations

    • API Version Changes: You cannot manually change the apiVersion of an existing Kubernetes resource. The migration controller handles this by creating a new resource with the new version based on the old one.
    • Deprecation Timeline: The opensearch.opster.io group will be removed approximately 2-3 releases after the deprecation announcement.
  5. How cluster recovery works

    main

    The operator automates recovery from pod failures to maintain quorum and stability. It typically restarts crashed pods one-by-one.

    Parallel Recovery Mode

    If multiple pods in a nodepool are missing or crashed simultaneously, the operator enters an experimental parallel recovery mode. It starts all missing pods at once to allow the cluster to form a new quorum.

    • Requirement: This mode only works with PVC-backed storage (it uses the number of existing PVCs to determine the number of missing pods).
    • Mechanism: The operator temporarily sets the underlying StatefulSet's podManagementPolicy to Parallel.
    • Disabling: If you encounter issues, disable this mode by setting manager.parallelRecoveryEnabled: false in your Helm values.yaml.

    Recovery with emptyDir storage

    If all node pools use emptyDir (ephemeral storage), data is not recoverable. In these scenarios, the operator will delete and recreate the entire OpenSearch cluster:

    1. More than half of the master nodes are missing or crashed (quorum broken).
    2. All data nodes are missing or crashed (no data nodes available).
  6. Requirements for RBAC Custom Resources

    main

    All RBAC-related custom resources (OpensearchUser, OpensearchRole, and OpensearchUserRoleBinding) must include a reference to an OpenSearchCluster resource. This reference tells the operator which specific OpenSearch cluster to reconcile the settings against.

    Safety Mechanism: To prevent orphaned objects or unexpected behavior, the OpenSearch cluster reference is stored in the resource's status field during the first reconciliation. If the cluster reference in the spec is changed on a subsequent operation, the reconciler will raise an error and refuse to proceed.

  7. How rolling restarts are triggered by configuration changes

    main

    The operator detects configuration changes to trigger restarts using the following mechanisms:

    • Config Files: The operator calculates a SHA1 hash of the file content and adds it as an annotation to the pods. A change in the hash signals a change in configuration.
    • Environment Variables: Changes to the environment variable definitions trigger a restart.

    Restart Behavior by Node Type:

    • Non-data nodes: The Kubernetes StatefulSet controller handles the restart of these pods.
    • Data nodes: The operator's rolling restart reconciler detects pending changes and performs a graceful rolling restart to ensure cluster stability.
  8. Configure OpenSearch ISM (Index State Management) Policies

    main

    Index State Management (ISM) policies allow you to define a state machine for your indices. A policy consists of:

    • States: Each state has a name and a list of actions to execute upon entering that state.
    • Transitions: Defines how to move between states. Each transition includes conditions and the stateName of the target state. If no transitions exist, the policy is considered complete and stops managing the index.
  9. Configure OpenSearchCluster via ClusterSpec

    main

    The ClusterSpec object defines the desired state of an OpenSearchCluster. It is a top-level configuration object that aggregates several specialized configuration blocks:

    • general: General cluster configuration.
    • confMgmt: Configuration for additional services (e.g., auto-scaling).
    • bootstrap: Configuration for the initial cluster setup.
    • dashboards: Configuration for OpenSearch Dashboards.
    • security: Security settings.
    • nodePools: An array of NodePool objects defining different types of nodes.
    • initHelper: Configuration for initialization helpers.
    type ClusterSpec struct {
    	General     GeneralConfig
    	ConfMgmt    ConfMgmt
    	Bootstrap    BootstrapConfig
    	Dashboards   DashboardsConfig
    	Security     Security
    	NodePools    []NodePool
    	InitHelper   InitHelperConfig
    }
  10. How the OpenSearch upgrade reconciler works

    main

    The upgrade reconciler manages rolling upgrades for OpenSearch clusters by orchestrating node pool updates. It follows a specific logic flow to ensure cluster stability:

    1. Version Validation: It checks that the requested version is not a downgrade and does not jump more than one major version.
    2. Phase Management: It transitions the cluster phase to UPGRADING when a valid version change is detected and back to RUNNING once all node pools match the target version.
    3. Node Pool Sequencing: Node pools are upgraded one at a time in this order:
      • Node pools with the data role but NOT the master role.
      • Node pools with both data and master roles.
      • Node pools without the data role (e.g., coordinating nodes).
    4. Pod Lifecycle: For each node pool, the reconciler ensures pods are ready, removes deprecated cluster settings, checks cluster health, prepares the pod (draining if DrainDataNodes is enabled), and finally deletes the pod to trigger a restart with the new image.

    This process uses the Kubernetes OnDelete update strategy for StatefulSets to allow the operator to manually control the timing of pod deletions and pre-upgrade preparations.

  11. Upgrade constraints and validation rules

    main

    To prevent unsupported cluster states, the upgrade reconciler enforces the following validation rules before starting any upgrade:

    • No Downgrades: The target version must not be lower than the current version.
    • Major Version Limit: The target version cannot be more than one major version ahead of the current version.
    • Initialization Requirement: The cluster must be fully initialized before an upgrade can begin.

    If these conditions are not met, the reconciler emits an error event and aborts the upgrade.

  12. How the OpenSearch Operator works

    main

    The operator follows the standard Kubernetes operator model using Custom Resources (CR) and Custom Resource Definitions (CRD).

    Core Abstractions

    • OpenSearchCluster: The primary resource used to specify an OpenSearch cluster deployment.
    • OpensearchRole, OpensearchUser, and OpensearchUserRoleBinding: Resources for managing users and roles declaratively.

    Reconciliation Lifecycle

    1. Controller: Each CRD has a corresponding controller that watches the Kubernetes API for changes to its specific custom objects.
    2. Reconcile Loop: When a change is detected (or via regular requeueing), the controller triggers a Reconcile method.
    3. Orchestration: The main Reconcile method acts as an orchestrator, delegating specific tasks to various reconcilers (e.g., one reconciler manages Dashboards, another manages securityconfig).