KubeDB SQL Server Operator

A Kubernetes operator that runs production-grade Microsoft SQL Server clusters — Standalone, Availability Group and Distributed Availability Group — with automated failover, backup, scaling and upgrades.

Organisation
AppsCode Inc.
Period
Aug 2023 – May 2026
Areas
Kubernetes Operators · Databases · Distributed Systems

Problem & context

KubeDB is AppsCode’s Kubernetes-native database management platform: users declare a database as a custom resource and operators handle provisioning and day-2 operations across public and private clouds.

Microsoft SQL Server high availability depends on Availability Groups — a primary replica and one or more secondaries that must agree on who is primary. Kubernetes reschedules pods freely, so the operator has to keep the SQL Server cluster topology consistent with what Kubernetes is doing, without losing data.

Architecture

  • Kubernetes CRDs describe the desired SQL Server deployment (Standalone, Availability Group, or Distributed Availability Group across clusters), and Go custom controllers reconcile it.
  • Each replica pod carries a role label (kubedb.com/role=primary / secondary). A cluster coordinator uses the Raft consensus algorithm for leader election and drives SQL Server failover so that the Raft leader and the AG primary stay aligned.
  • TLS certificates (via an Issuer / ClusterIssuer) secure communication between primary and secondary replicas.
  • Ops requests (CRDs) drive day-2 operations — reconfigure, update version, reconfigure TLS, horizontal/vertical scaling, volume expansion and restart — validated by webhooks.
  • Backups and restores integrate with KubeStash; monitoring ships with a Prometheus exporter and Grafana dashboards.

Engineering challenges

  • Keeping a stateful, consensus-dependent database cluster consistent while Kubernetes kills, reschedules and restarts pods.
  • Failing over quickly and safely when the primary pod, its SQL Server process or its network fails — without data loss.
  • Supporting multiple topologies (Standalone, AG, Distributed AG, arbiter nodes, active/passive secondaries) behind one declarative API.

Implementation

  • Added the SQL Server APIs to kubedb/apimachinery — core types, TLS APIs and defaults, monitoring APIs, ops-request APIs (including reconfigure TLS), arbiter APIs, Distributed AG APIs, and SecondaryAccess for active vs. passive secondaries.
  • Built the SQL Server DB client in kubedb/db-client-go, including TLS configuration.
  • Packaged the operator in kubedb/installer: RBAC, autoscaler, ops webhooks, metrics configuration, Grafana dashboards and new SQL Server versions (2022 CU14, CU16, CU19 and later).
  • Added initialisation of databases via scripts, and a kubectl-dba CLI command for Distributed AG configuration.
  • Wrote the user documentation: quickstart, concepts & provisioning, custom configuration, TLS/SSL, scaling, volume expansion, autoscaling, monitoring, restart, reconfigure, update version, arbiter node guide, Distributed AG, and init scripts.
  • Co-developed a Prometheus metrics exporter (kubedb/mssqlserver_exporter) and Grafana dashboards for SQL Server pods and databases; added alerts and remedies.
  • Implemented end-to-end CI/CD with GitHub Actions — automated builds, testing and Docker image creation.
  • Validated resilience with Chaos Mesh experiments: killing the primary pod, OOM-killing it under load, killing the sqlservr process, network latency and partitions, and I/O faults.

Technical decisions

  • Raft for leader election, instead of relying only on Kubernetes primitives, so that failover decisions come from a consensus protocol rather than from whichever pod happens to be scheduled first.
  • A “Critical” database state — the primary is up and serving reads and writes while one or more replicas are offline — so that uptime isn’t compromised by replica failures.
  • Ops requests as first-class CRDs, so that day-2 changes are declarative, auditable and GitOps-friendly.

My contribution

  • Designed and implemented the operator for SQL Server Standalone and Availability Group clusters, and later the Distributed Availability Group support.
  • Developed the Availability Group cluster coordinator using Raft for leader election and automatic failover.
  • Implemented provisioning, health checks, backup & restore, monitoring, e2e tests, version upgrades, horizontal & vertical scaling, volume expansion, TLS and auto-scaling.
  • Authored the documentation, a chaos-engineering blog post, and webinars demonstrating the operator.

Outcomes & impact

  • Automated orchestration of SQL Server Standalone, Availability Group and Distributed Availability Group clusters on Kubernetes, achieving 99.999% high availability in Kubernetes environments (as reported in my CV).
  • Auto-scaling, self-healing and fully automated failover, reducing manual failover interventions by about 90% and targeting 99.99999% data safety (as reported in my CV).
  • In the published chaos tests a failover typically took ~5 seconds with no data loss; a 7-minute high-concurrency load test performed 45,877 operations with zero errors and all 508,600 rows intact.
  • Prometheus/Grafana observability for SQL Server, credited in my CV with a ~99% reduction in production outages.

Technologies

  • Go
  • Kubernetes
  • CRDs
  • Custom controllers
  • Raft
  • SQL Server
  • T-SQL
  • Prometheus
  • Grafana
  • GitHub Actions
  • KubeStash
  • Chaos Mesh
  • TLS