Reference Guide: Optimizing Backup Strategies for Red Hat OpenShift Virtualization

Kubernetes operators are extensions that automate application management in Kubernetes clusters. They handle application-specific tasks beyond the basic capabilities of Kubernetes, focusing on complex operations and lifecycle management.

Operators offer significant advantages by simplifying  upgrades, backups, and scaling. They’re particularly effective for applications with intricate requirements, including many stateful services. By putting operational knowledge into code, operators minimize errors, simplify maintenance, and allow you to manage applications efficiently at scale.

You might have seen these tools broadly adopted across cloud-native architectures. Typical uses include overseeing distributed databases (like PostgreSQL or Cassandra), setting up monitoring systems (such as Prometheus or Grafana), managing service meshes (e.g., Istio), backups and DR (eg., Trilio) and orchestrating cloud resources. These applications show how operators extend Kubernetes to meet the needs of diverse, sophisticated applications in production settings.

In this article, we help you understand the core concepts behind Kubernetes operators, their development and deployment, performance considerations, security implications, and future trends in operator development.

Summary of key concepts

Concept

Summary

Core concepts and anatomy of Kubernetes operators

Operators use custom resource definitions to extend Kubernetes functionality. They employ control loops to maintain the desired state of resources. The Operator SDK provides tools and libraries for building operators efficiently.

Developing and deploying Kubernetes operators

Different programming languages offer various tradeoffs for operator development. The Operator Lifecycle Manager automates operator installation, upgrades, and lifecycle management in a cluster. Versioning is essential for managing operator updates and compatibility.

Performance and scalability considerations

Operators can significantly impact cluster resources. Efficient handling of custom resources is key to operator scalability. Multi-tenancy in operator design requires careful planning and implementation.

Security implications of operators

Proper RBAC configuration is critical for operator security. Operators must implement secure communication patterns, especially when handling sensitive data. Protecting confidential information managed by operators requires specific security measures.

Future trends in operator development

Operator workflows are increasingly integrating with GitOps practices. Some operators are incorporating AI/ML for more intelligent automation. Cross-cluster and hybrid cloud operator capabilities are expanding to meet complex deployment needs.

Core concepts and anatomy of Kubernetes operators

Kubernetes operators are controllers that extend Kubernetes to automate the management of applications, whether stateful or stateless. They work continuously to reconcile an application’s actual state with its desired state by defining custom resource definitions (CRDs). 

Operators use control loop mechanisms, watching for changes to specific resources and taking action to move the current state toward the desired state. This allows for the automation of complex, application-specific management tasks—such as deployments, scaling, failovers, and updates—while integrating seamlessly with Kubernetes control and management features.

High-level design and usability of operators

Operators follow a consistent design pattern that leverages Kubernetes’ extensibility:

  1. Define custom resource definitions that specify custom resources (CRs).
  2. Implement a controller that watches these CRs and related Kubernetes objects.
  3. Use Kubernetes APIs to reconcile the current state with the desired state.

Kubernetes operators follow a specific workflow to deploy and manage applications, as shown in the figure below.

Visual representation of the operator workflow

Visual representation of the operator workflow

With this process, the operator constantly monitors for changes and reconciles the state as needed.

Automated Kubernetes Data Protection & Intelligent Recovery

Perform secure application-centric backups of containers, VMs, helm & operators

Use pre-staged snapshots to instantly test, transform, and restore during recovery

Scale with fully automated policy-driven backup-and-restore workflows

Custom resource definitions (CRDs)

CRDs extend the Kubernetes API, allowing you to define application-specific resources. This extensibility is crucial for operators, enabling them to introduce custom concepts to the Kubernetes standard feature set.

CRDs are commonly defined as YAML manifests, and the structure and validation rules for custom resources are specified. A typical CRD includes the following:

  • API version and kind
  • Metadata, including the name of the CRD
  • Spec section, defining:
    • Group and versions of the custom resource
    • Scope (namespaced or cluster-wide)
    • Names (plural, singular, kind, and short names)
    • Schema, using the OpenAPI v3 schema definition

For example, a simple CRD for a database might look like this:

    
     apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: databases.example.com
spec:
  group: example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                engine:
                  type: string
                version:
                  type: string
                storageSize:
                  type: string
  scope: Namespaced
  names:
    plural: databases
    singular: database
    kind: Database
    shortNames:
    - db
    
   

Control loops and reconciliation

Control loops are the core mechanism of Kubernetes operators that implement the reconciliation process:

  • Observe: Watch for changes in CRs and cluster state.
  • Analyze: Compare the current state with the desired state.
  • Act: Take actions to reconcile differences.
  • Update: Modify CR status to reflect the current state.

This process runs continuously, ensuring the application remains in the desired state despite external changes or failures.

Controller structure and custom resources

The controller is the core component of an operator and is responsible for maintaining the desired state of custom resources. Its structure typically includes several key components working together to manage the lifecycle of the resources it’s responsible for:

  • Informers/watchers: These components monitor Kubernetes resources for changes, using the Kubernetes API server’s watch feature to efficiently track updates to relevant objects. For example, a database operator might watch for changes to database custom resources and related secrets or configmaps.
  • Work queue: This is a thread-safe storage mechanism for processing tasks. When the informer detects a change, an item is added to the work queue. This decouples the monitoring of resources from processing changes, allowing for better performance and error handling.
  • Reconciler: This component implements the business logic to align the actual state with the desired state. It’s typically structured as a loop that processes items from the work queue. For each item, it retrieves the current state, compares it with the desired state, and takes necessary actions.
  • Client: This component interacts with the Kubernetes API to read and write resources. The reconciler uses it to fetch current states and apply changes.

Watch this 1-min video to see how easily you can recover K8s, VMs, and containers

Developing and deploying Kubernetes operators

Developing and deploying Kubernetes operators involves several key considerations, including selecting the appropriate programming language and managing the operator’s lifecycle. This section explores the technical aspects of building operators using the Operator SDK and the Operator Lifecycle Manager for deployment and management.

Choosing the programming language

The ideal choice of programming language for developing Kubernetes operators depends on several factors:

  • Performance and resource efficiency: The language’s execution speed and memory usage are important, especially for operators managing large-scale or resource-intensive applications in Kubernetes clusters.
  • Kubernetes API compatibility: Effective operator development requires the availability of mature, well-maintained client libraries that interact with the Kubernetes API.
  • Development speed and ease of use: The language should facilitate rapid development and prototyping, allowing teams to implement and iterate on operator logic quickly.
  • Concurrency handling: Efficient management of concurrent operations is essential for operators that need to handle multiple resources simultaneously.

Here are some of the most commonly used languages for operators:

  • Go is an often preferred choice for its performance and native Kubernetes client libraries; in fact, it’s the language used by Kubernetes itself. Go provides strong typing and concurrency support to build robust operators that can handle complex reconciliation loops efficiently.
  • Python offers rapid development and a rich ecosystem of libraries. It’s suitable for operators that don’t require high performance, particularly data processing or machine-learning-focused operators.
  • Java provides strong typing and extensive enterprise-grade libraries. It is helpful for complex operators in Java-centric environments. Its mature ecosystem and tools can be advantageous for large-scale operator projects.

A use case based approach to choosing a programing language

A use case based approach to choosing a programing language

Learn about the features that power Trilio’s intelligent backup and restore

Operator SDK usage and best practices

Various frameworks have been created to streamline the development of operators. The Operator SDK, one of the most widely used, is a framework for building Kubernetes applications, providing APIs for everyday tasks, extensions for Kubernetes controllers, and testing utilities.

Popular frameworks include:

These frameworks offer various features and tradeoffs in terms of development speed, flexibility, and runtime performance, catering to various programming languages and development preferences.

When using the SDK, you should focus on these key areas:

  • Project structure: When building an operator, you can use the SDK’s scaffolding feature to generate a standardized project structure. This layout ensures compatibility with SDK tools and facilitates collaboration among team members. This structure ensures compatibility with SDK tools and eases collaboration among team members.
  • Controller logic: With the project structure in place, focus on defining custom resource definitions using the SDK’s API. Craft clear validation rules and defaulting logic within your CRDs. This approach prevents the creation of invalid resources and simplifies your operator’s reconciliation logic, reducing complexity in your codebase.
  • Finalizers: Add finalizers to custom resources to handle cleanup operations when resources are deleted. This prevents orphaned resources and ensures proper tear-down of managed components.
  • Status updates: Using the SDK’s status update mechanisms, you can keep your custom resource status fields up to date. These updates provide users with real-time information about the managed application’s state, enhancing observability and the user experience.
  • Metrics: Leverage the SDK’s built-in metrics support to expose operational data. Configure custom metrics that provide insights into the operator’s performance and the managed application’s health.

An application-centric approach can be efficient when developing operators for data protection and backup solutions. For example, Trilio’s Kubernetes operator implements this strategy, allowing for precise, granular backups of specific applications or workloads within a Kubernetes environment. This approach demonstrates how operators can be designed to handle complex, application-specific tasks while maintaining consistency with Kubernetes principles.

Popular Kubernetes Operators

You can find various operators developed by open source communities for a wide range of applications and services. 

Here are some examples.

Database Operators:

Monitoring and Observability:

Service Mesh:

Storage:

  • Rook: Automates deployment and management of various storage solutions including Ceph

CI/CD:

Operator Lifecycle Manager (OLM)

The Operator Lifecycle Manager extends Kubernetes to provide a declarative way to install, manage, and upgrade operators on a cluster. 

Key features of OLM include:

  • Catalog management: OLM uses catalogs to discover and manage available operators.
  • Automatic dependency resolution: It handles operator dependencies automatically.
  • Upgrade management: OLM can perform automatic or manual upgrades for operators.
  • RBAC integration: It integrates with Kubernetes RBAC for secure operator management.

Comparing standard and OLM operators

Standard operators are typically deployed directly using kubectl and Kubernetes manifests, requiring manual lifecycle management. In contrast, OLM operators leverage OLM’s subscription model for deployment, enabling more sophisticated versioning and upgrade paths. The details are shown in the table below.

 

Aspect

Standard operators

OLM oOperators

Framework and architecture

Standalone controllers without standardized metadata structure

Part of the OLM ecosystem, using cluster service versions (CSVs) and subscriptions for standardized metadata and capabilities description

Installation process

Manual installation, often requiring multiple kubectl commands

Consistent installation process across different operators through OLM’s CSV and subscription resources

Discovery and installation

Manual discovery and installation

Discoverable through OLM catalogs, simplifying installation for cluster administrators

Updates and dependency management

Manual updates and dependency management

Automated updates and dependency resolution handled by OLM

 

Performance and scalability considerations

Performance and scalability factors significantly impact the efficiency and reliability of Kubernetes operators in production environments. These considerations affect how operators function at scale and in multi-tenant scenarios. This section explores key focus areas for optimizing operator performance, managing large-scale deployments, and ensuring proper resource isolation in shared environments.

Resource consumption and optimization

The resource usage of operators varies based on complexity and the number of managed resources. The following are some common optimization strategies:

  • Efficient reconciliation loops to reduce API calls. For example, implement a caching mechanism that stores the last known state of resources and only triggers reconciliation when actual changes occur.
  • Caching mechanisms to decrease Kubernetes API server load. To reduce the number of direct API calls, implement an informer cache for frequently accessed resources, such as configmaps or secrets.
  • Appropriate resource requests and limits for operator deployment. You can set specific CPU and memory limits based on observed usage patterns.
  • Backoff mechanisms for retries during error scenarios. Implement exponential backoffs, for example, starting with a 1 second delay and doubling it for each retry, up to a maximum of 5 minutes.

Handling large numbers of custom resources

As the number of managed resources grows, operators must maintain performance and responsiveness. Scalability approaches include the following:

  • Pagination when listing resources to reduce memory usage and API server load. Based on the number of resources managed, implement list operations with limited items per page, using continue tokens for subsequent pages.
  • Efficient indexing for quick lookups of related resources. Create custom indexers for frequently queried fields, such as looking up pods by their associated deployment names.
  • Server-side apply for updates to reduce conflicts and improve performance. Use server-side apply for updating complex resources like deployments, specifying only the fields that the operator manages.

Large-scale Kubernetes deployments require efficient data recovery and migration solutions. A practical example is Trilio’s Continuous Recovery & Restore solution, which demonstrates this capability with its continuous data protection and migration features that can manage numerous custom resources effectively. 

Trilio’s approach enables quick recovery and migration of stateful applications, a valuable feature in environments with many custom resources and substantial data volumes. This illustrates how operators can be designed to handle resource-intensive tasks while maintaining cluster performance.

Multi-tenant considerations

For operators in shared environments, proper multi-tenancy implementation ensures resource isolation and security. Key aspects and examples include:

  • Namespace-scoped resources for logical separation. Design custom resources to be namespace-scoped where possible, allowing for natural isolation between different teams or applications.
  • Kubernetes RBAC to restrict operator permissions. Create specific cluster roles and roles that grant only the necessary permissions, such as allowing an operator to manage only its custom resources and related core Kubernetes objects.
  • Resource quotas to prevent excessive resource consumption by a single tenant. Implement resource quotas that limit the number of custom resources a namespace can create, such as a maximum of 10 database instances per namespace.
  • Admission webhooks to enforce tenant-specific policies. Develop a validating webhook that ensures that custom resources adhere to organizational policies, such as enforcing specific labels or rejecting certain configurations.

Security implications of operators

Security can be a deciding factor for many teams when deploying and managing Kubernetes operators. Operators often have elevated privileges within a cluster and handle sensitive application data, so implementing robust security measures is critical. This section explores the key security implications of operators, focusing on role-based access control (RBAC), secure communication patterns, and the handling of sensitive information.

RBAC for operators

Role-based access control is crucial for limiting operator permissions and adhering to the principle of least privilege. Proper RBAC configuration ensures that operators have access only to the resources they need to function. 

Key strategies include the following:

  • Create specific service accounts for each operator. For example, create a mysql-operator service account that is used exclusively by the MySQL operator.
  • Define granular cluster roles or roles. Create a role that allows the operator to manage only its custom resources and related Kubernetes objects. For instance, a PostgreSQL operator might need permissions like these:
    
     rules:
- apiGroups: ["postgres.example.com"]
  resources: ["databases", "databases/status"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["apps"]
  resources: ["statefulsets"]
  verbs: ["get", "list", "watch", "create", "update", "delete"]
    
   
  • Use role bindings to associate the service account with the appropriate role. This limits the operator’s permissions to specific namespaces if needed.
  • Audit and review RBAC permissions regularly to ensure that they remain appropriate as the operator evolves. For example, schedule quarterly reviews of the operator’s RBAC configurations and compare them against their current functionality.

Secure communication patterns

Operators often communicate with various components within and outside the cluster. Implementing secure communication patterns is essential for this communication:

  • Use TLS for all internal cluster communication. For example, when an operator communicates with its operands, ensure that the communication is encrypted using TLS certificates provided by cert-manager or a similar solution.
  • Implement mutual TLS (mTLS) for external operations. If an operator needs to communicate with an external service for licensing validation, use mTLS to ensure that both parties authenticate each other.
  • Leverage service mesh technologies like Istio for advanced traffic encryption and access control between operator components. For instance, Istio can be configured to enforce TLS communication between the operator and its managed resources.
  • Use network policies to restrict communication paths. For example, create a network policy that only allows the operator to communicate with its managed resources and necessary API servers, blocking all other traffic.

Handling sensitive information

Operators often need to manage sensitive data such as passwords, API keys, or connection strings. Proper handling of this information is crucial:

  • Use external secret management systems for enhanced security. Integrate with tools like HashiCorp Vault or AWS Secrets Manager, having the operator retrieve sensitive information as needed rather than storing it long-term in the cluster.
  • Be cautious with logging and error messages. Review your logs regularly to ensure that sensitive information is never logged or exposed in error messages. Implement log redaction for any potentially sensitive data fields. For example, regular expressions can identify and mask patterns that look like passwords or API keys in log outputs.
  • Use envelope encryption for sensitive data. Utilize a system where the operator encrypts sensitive data with a data encryption key, which is itself encrypted with a master key stored in a secure key management system.
  • Implement the principle of least privilege for sensitive information access. If an operator manages multiple resources, be sure that each resource can only access its own sensitive information. For example, in a multi-tenant database operator, each instance should have unique credentials that are inaccessible to other instances.

Comprehensive security is critical for handling sensitive information in Kubernetes environments. Trilio’s approach to this challenge includes immutable backups and encryption. The solution uses object-locked S3 buckets for backups, preventing unauthorized alterations. Additionally, they implement 256-bit LUKS encryption based on user-defined secret keys. These strategies showcase how operators can incorporate advanced security measures to protect against data breaches.

Future trends in operator development

This section examines three key trends in operator development: GitOps integration, AI/ML-driven operations, and cross-cluster/hybrid cloud management. These advancements expand operators’ capabilities in automating complex tasks, making data-driven decisions, and managing applications across diverse environments.

GitOps integration

GitOps integration in operator development involves aligning with GitOps principles and ensuring that the entire lifecycle of the operator and the resources it manages are controlled through Git workflows. You can leverage GitOps in your operator projects by implementing a GitOps workflow for operator deployment. 

Use tools like ArgoCD or Flux to automatically deploy and update your operator based on changes in a Git repository. For example, structure your Operator project with a /deploy directory containing all Kubernetes manifests and configure ArgoCD to sync this directory with your cluster.

GitOps workflow

GitOps workflow

Design your operator to watch a Git repository for changes to custom resources. For instance, a database operator could monitor a /databases directory in a Git repo, automatically creating or updating database instances when schema files in this directory change.

AI/ML-driven operators

AI/ML integration allows your operators to move beyond simple, rule-based automation to more sophisticated, context-aware management of applications and infrastructure. 

You can incorporate AI/ML into your operators by implementing predictive scaling. Use historical metrics data to train a machine learning model that predicts resource usage. Integrate this model into your operator to proactively scale resources before they’re needed. For example, an ecommerce platform operator could scale up resources automatically before predicted high-traffic events. 

Another approach is to implement anomaly detection for managed applications. Develop an ML model to detect unusual patterns in application metrics. Integrate this into your operator to automatically investigate or mitigate potential issues. For instance, a database operator could detect unusual query patterns that might indicate a SQL injection attack and automatically apply defensive measures.

Cross-cluster and hybrid cloud operators

Cross-cluster and hybrid cloud operators manage resources across multiple Kubernetes clusters and cloud environments. 

Develop a multi-cluster reconciliation loop to implement your operators’ cross-cluster and hybrid cloud capabilities. Extend your operator’s reconciliation logic to handle resources across multiple clusters. This might involve maintaining separate Kubernetes clients for each cluster and implementing logic to decide which cluster should host which resources. 

Another important aspect is supporting heterogeneous environments. Design your operator to be aware of different cloud provider capabilities and limitations. For example, a storage operator might need to use different storage classes or provisioners depending on whether it’s running in AWS, Azure, or an on-premises cluster.

Learn about a lead telecom firm solved K8s backup and recovery with Trilio

Conclusion

The development and implementation of operators involve key considerations in language selection, tooling, performance optimization, and security. Tools like the Operator SDK and Operator Lifecycle Manager have simplified the process, allowing developers to focus on creating efficient, secure, and scalable solutions. 

As the field progresses, we see exciting developments ahead in GitOps integration, AI/ML-driven operations, and cross-cluster management. Solutions like Trilio demonstrate the practical application of operator technology, leveraging these principles to provide comprehensive data protection and management in Kubernetes environments. As you explore and implement operators in your environments, you will find that they offer powerful capabilities for automating and scaling your Kubernetes operations, opening up new possibilities for efficient, cloud-native application management.

If you are interested in exploring Trilio’s operator implementation further, the following resources provide detailed information:

  1. Trilio Custom Resource Definition Operator Guide
  2. TrilioVault Operator Helm Values
  3. Trilio Support for OpenShift Operators
Table Of Contents

Like This Article?

Subscribe to our LinkedIn Newsletter to receive more educational content

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.