TyKO (Typesense Kubernetes Operator)
website·Indexed 31 days ago
https://akyriako.github.io/typesense-operator-docsThe Typesense Kubernetes Operator (TyKO) manages the deployment and lifecycle of Typesense clusters on Kubernetes. It provides self-healing capabilities, manages TypesenseCluster Custom Resource Definitions (CRDs), and handles quorum reconciliation and reconfiguration. Documentation covers installation via Helm, configuration for S3-compliant storage, and compatibility with Typesense 30.x+.
What's inside TyKO
- TyKO is a Kubernetes operator built with the Operator SDK designed to manage Typesense clusters. It provides automated lifecycle management including self-healing (automated failover, quorum recovery, and raft re-evaluation), zero-downtime rolling updates for upgrades or resizing, and native integration with Kubernetes resources like StatefulSets, ConfigMaps, Secrets, and Services. It supports S3-compatible object storage (e.g., AWS S3, OBS, RustFS) for data persistence and exposes node health and metrics for Prometheus monitoring. It also integrates with Kubernetes Ingress and the Gateway API for secure exposure and TLS termination.
Overview of Typesense Kubernetes Operator (TyKO)
The Typesense Kubernetes Operator (TyKO) is a tool developed in Go using the Operator SDK Framework. It is designed to automate the deployment and lifecycle management of Typesense clusters within Kubernetes environments, providing a scalable and automated way to manage these native applications.Understand Typesense Operator Networking and Deployment
The operator manages the following Kubernetes resources to deploy a Typesense cluster:
- Headless Service: Used by the StatefulSet for internal node communication.
- ClusterIP Service: Used to expose REST/API endpoints to external systems.
- StatefulSet: Provisions the Typesense pods and mounts the
NodesListConfigMapfor quorum management. - Ingress (Optional): Provisions an nginx workload (default
nginx:alpine) to expose the API to specific referers. - DocSearch Scrapers (Optional): Deploys
CronJobsto periodically scrape target URLs and store results in Typesense.
Understand Typesense cluster quorum and Raft consensus
Typesense uses the Raft consensus algorithm to manage clusters. Nodes exist in three states: follower, candidate, or leader. A cluster ofNnodes can tolerate a failure of at most(N-1)/2nodes. If the number of available nodes falls below this threshold, the cluster loses quorum, meaning no leader can be elected and no log entries can be processed. To prevent split-brain issues, Typesense will stop accepting reads and writes until manual intervention occurs.Monitor Typesense nodes using Prometheus
The Typesense operator deploys each node as a Kubernetes Pod containing three containers: the Typesense server, a metrics exporter sidecar (based on typesense-prometheus-exporter), and a cluster healthcheck sidecar. The metrics exporter collects data from the Typesense/metrics.jsonand/stats.jsonendpoints and exposes them in Prometheus format at the/metricsendpoint. The operator automatically creates aPodMonitorresource to enable Prometheus discovery and scraping.apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: name: ts-podmonitor namespace: default labels: release: { RELEASE_NAME } spec: selector: matchLabels: { LABEL_OF_THE_STATEFULSET_PODS } namespaceSelector: matchNames: - default endpoints: - port: metrics path: /metrics interval: 15s scheme: httpAccess the Typesense healthcheck Web UI
Thetypesense-healthchecksidecar includes a built-in Vue.js monitoring dashboard that provides a real-time overview of the Typesense StatefulSet. It displays node states (leader/follower/candidate), committed indices, and queued writes, with auto-refresh every 3 seconds and color-coded health indicators.# Access the UI via browser http://<POD_IP_ADDRESS_OR_FQDN>:<HEALTHCHECK_PORT>/Understand the Typesense Operator Quorum Reconciliation Loop
The Typesense Operator implements a Quorum Reconciliation Loop to prevent clusters from entering a 'hot loop' where no leader can be elected due to conflicting majorities during configuration changes. The controller automates the recovery process—which would normally require manual scaling of the StatefulSet—by detecting quorum loss and forcing a downgrade to a single-node cluster to establish a healthy quorum, then gradually scaling back up. This automation works as long as the issue is not caused by memory or disk capacity limits.Deploy a High-Availability Typesense cluster using TyKO
To deploy a highly-available (HA) Typesense cluster on Kubernetes using the TyKO operator, follow these three steps:
- Install the Operator: Deploy TyKO into the Kubernetes cluster using a Helm command.
- Declare a cluster: Create a
TypesenseClustercustom resource (CR) that defines the cluster size, storage requirements, and exposure settings. - Management: The operator automatically handles quorum, failover, upgrades, and scaling.
Upgrade Typesense and DocSearch Scraper for version 30.x+
When upgrading to Typesense version 30.0 or higher, you must upgrade the DocSearch Scraper simultaneously. Typesense 30.0 introduced breaking API changes for transferring synonyms and curation sets that are incompatible with DocSearch Scraper versions prior to 0.12.0.rc14.Typesense DocSearch Scraper 29.x 0.11.0 30.x+ 0.12.0.rc14+ Install or update CRDs in a Kubernetes cluster
After modifying the CRD schema and generating the manifests, you must install or update the new schema in your target Kubernetes cluster to make the changes effective.make installSet up JuiceFS CSI Driver and Redis for S3 storage
To use S3-compliant object storage as persistent volumes (supporting
ReadWriteOnceandReadWriteManyas of v0.3.6), you must install the JuiceFS CSI Driver and a Redis cluster to serve as the metadata store.Caveats:
- T Cloud Public users can skip this if using the
everest-csi-provisioner. - Amazon S3 users do not require Redis as S3 provides its own metadata endpoints.
# Install JuiceFS CSI Storage Driver kubectl apply -f https://raw.githubusercontent.com/juicedata/juicefs-csi-driver/master/deploy/k8s.yaml # Install Redis Cluster kubectl create namespace redis kubectl apply -f redis.yaml -n redis- T Cloud Public users can skip this if using the
Migrate from IngressSpec to HttpRoute
As of v0.4.0-rc.1,IngressSpecis deprecated in favor of the Kubernetes Gateway API (HttpRoute). WhileIngressresources are still supported to avoid breaking changes, they will receive no new features or maintenance updates. New deployments should useHttpRoute.