Skip to content

Commit

Permalink
Add SQL Server Arbiter Node Guide
Browse files Browse the repository at this point in the history
Signed-off-by: Neaj Morshad <[email protected]>
  • Loading branch information
Neaj-Morshad-101 committed Feb 17, 2025
1 parent c8e8288 commit 134157a
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $ kubectl get pod -n demo sample-mariadb-0 -o json | jq '.spec.containers[].reso
}
```

You can see the Pod has the default resources which is assigned by Kubedb operator.
You can see the Pod has the default resources which is assigned by KubeDB operator.

We are now ready to apply the `MariaDBOpsRequest` CR to update the resources of this database.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mongodb/concepts/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ The `spec.podTemplate.spec.containers[].name` field used to specify the name of

Note that, KubeDB does not allow `MONGO_INITDB_ROOT_USERNAME` and `MONGO_INITDB_ROOT_PASSWORD` environment variables to set in `spec.podTemplate.spec.env`. If you want to use custom superuser and password, please use `spec.authSecret` instead described earlier.

If you try to set `MONGO_INITDB_ROOT_USERNAME` or `MONGO_INITDB_ROOT_PASSWORD` environment variable in MongoDB crd, Kubedb operator will reject the request with following error,
If you try to set `MONGO_INITDB_ROOT_USERNAME` or `MONGO_INITDB_ROOT_PASSWORD` environment variable in MongoDB crd, KubeDB operator will reject the request with following error,

```ini
Error from server (Forbidden): error when creating "./mongodb.yaml": admission webhook "mongodb.validators.kubedb.com" denied the request: environment variable MONGO_INITDB_ROOT_USERNAME is forbidden to use in MongoDB spec
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mongodb/scaling/vertical-scaling/replicaset.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ $ kubectl get pod -n demo mg-replicaset-0 -o json | jq '.spec.containers[].resou
}
```

You can see the Pod has the default resources which is assigned by Kubedb operator.
You can see the Pod has the default resources which is assigned by KubeDB operator.

We are now ready to apply the `MongoDBOpsRequest` CR to update the resources of this database.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mongodb/scaling/vertical-scaling/sharding.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $ kubectl get pod -n demo mg-sharding-shard0-0 -o json | jq '.spec.containers[].
}
```

You can see all the Pod of mongos, configserver and shard has default resources which is assigned by Kubedb operator.
You can see all the Pod of mongos, configserver and shard has default resources which is assigned by KubeDB operator.

We are now ready to apply the `MongoDBOpsRequest` CR to update the resources of mongos, configserver and shard nodes of this database.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mongodb/scaling/vertical-scaling/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $ kubectl get pod -n demo mg-standalone-0 -o json | jq '.spec.containers[].resou
}
```

You can see the Pod has default resources which is assigned by the Kubedb operator.
You can see the Pod has default resources which is assigned by the KubeDB operator.

We are now ready to apply the `MongoDBOpsRequest` CR to update the resources of this database.

Expand Down
146 changes: 146 additions & 0 deletions docs/guides/mssqlserver/clustering/arbiter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
title: Arbiter Node for MS SQL Server Cluster with Even Nodes
menu:
docs_{{ .version }}:
identifier: arbiter-guides
name: Arbiter Node for AG Cluster
parent: ms-arbiter
weight: 15
menu_name: docs_{{ .version }}
section_menu_id: guides
---

> New to KubeDB? Please start [here](/docs/README.md).
# Arbiter Node for Microsoft SQL Server Cluster with Even Nodes

Here we will show how to use KubeDB to provision a SQL Server even-sized Availability Group Cluster with Arbiter Node.

## Before You Begin

- You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/).

- Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps [here](/docs/setup/README.md). Make sure install with helm command including `--set global.featureGates.MSSQLServer=true` to ensure MSSQLServer CRD installation.

- To configure TLS/SSL in `MSSQLServer`, `KubeDB` uses `cert-manager` to issue certificates. So first you have to make sure that the cluster has `cert-manager` installed. To install `cert-manager` in your cluster following steps [here](https://cert-manager.io/docs/installation/kubernetes/).


## Concepts
We use [Raft Consensus Algorithm](https://raft.github.io/) to determine the leader of SQL Server Availability Group cluster. With each `mssql` container,
we run a sidecar container named `mssql-coordinator` which determines the leader of the cluster both on bootstrap and in fail over scenarios.
This works very well with the clusters having odd number of nodes. Clusters with even number of nodes still have a chance of split brain problem(Two primary node in the cluster at the same time). To avoid this split brain issue,
we introduced an extra node named `{{db}}-arbiter`. The job of the
arbiter node is to participate solely in leader election.
It doesn't store any data related to mssqlserver database. However, it needs
a bare minimum of 1Gi~2Gi Storage for storing WAL and Snapshots that
are generated by RAFT. But the generation of WAL are not very frequent.
So storage space of 2Gi is more than enough for most of the clusters.

## Demo

To keep things isolated, this tutorial uses a separate namespace called `demo` throughout this tutorial.

```bash
$ kubectl create ns demo
namespace/demo created
```

Let's apply the following yaml.

```yaml
apiVersion: kubedb.com/v1alpha2
kind: MSSQLServer
metadata:
name: ms-even-cluster
namespace: demo
spec:
version: "2022-cu16"
replicas: 2
topology:
mode: AvailabilityGroup
availabilityGroup:
databases:
- agdb1
- agdb2
tls:
issuerRef:
name: mssqlserver-ca-issuer
kind: Issuer
apiGroup: "cert-manager.io"
clientTLS: false
podTemplate:
spec:
containers:
- name: mssql
env:
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_PID
value: Evaluation
storageType: Durable
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
deletionPolicy: WipeOut
```
A petset with the name `{{ dbName }}-arbiter` should be created once you apply this yaml.

```bash
kubectl get petset -n demo
NAME AGE
ms-even-cluster 72s
ms-even-cluster-arbiter 55s
```

Following a pod having name `{{ dbName }}-arbiter-0` will be created.

```bash
kubectl get pods -n demo
NAME READY STATUS RESTARTS AGE
ms-even-cluster-0 2/2 Running 0 84s
ms-even-cluster-1 2/2 Running 0 78s
ms-even-cluster-arbiter-0 1/1 Running 0 68s
```
Get the pvc,

```bash
kubectl get pvc -n demo
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-ms-even-cluster-0 Bound pvc-8653958e-091c-4c15-8151-4d207c976ad1 1Gi RWO standard 2m50s
data-ms-even-cluster-1 Bound pvc-afd698cf-22d5-4a66-996e-a8d53198a95f 1Gi RWO standard 2m44s
data-ms-even-cluster-arbiter-0 Bound pvc-25c413c9-4cb0-4a5c-89f6-9d2208841b07 2Gi RWO standard 2m34s
```
> Note: Your pvc size for data nodes might be 1000Gi, but for most of the cases you will never need more than 2Gi storage for arbiter node.


You can check arbiter pod has only one container by getting the pod yaml.
```bash
kubectl get pods -n demo ms-even-cluster-arbiter-0 -oyaml
```

## Why do we need arbiter node?

Few of our users don't want to run 3 node cluster as this was quite
expensive for them, instead they wanted to use 2 node cluster,
1 primary and 1 replica. But due to raft implementation, there was chance of split brain. So we introduced this arbiter node so that they can still have
1 primary and 1 replica cluster and not have faced split brain problem.


## Cleaning up

```bash
kubectl delete pg -n demo ms-even-cluster
kubectl delete ns demo
```

## Next Steps
- Learn more about [Raft implementation](https://github.com/etcd-io/etcd/blob/main/contrib/raftexample/README.md)
- Learn about [backup and restore](/docs/guides/mssqlserver/backup/overview/index.md) Microsoft SQL Server database using Stash.
- Want to set up Microsoft SQL Server cluster? Check how to [configure Highly Available Microsoft SQL Server Cluster](/docs/guides/mssqlserver/clustering/ag_cluster.md)
- Monitor your Microsoft SQL Server database with KubeDB using [Prometheus operator](/docs/guides/mssqlserver/monitoring/using-prometheus-operator.md).
- Detail concepts of [Postgres object](/docs/guides/mssqlserver/concepts/mssqlserver.md).
- Want to hack on KubeDB? Check our [contribution guidelines](/docs/CONTRIBUTING.md).
2 changes: 1 addition & 1 deletion docs/guides/mssqlserver/scaling/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Scaling Microsoft SQL Server
menu:
docs_{{ .version }}:
identifier: ms-scaling
name: Scaling Microsoft SQL Server
name: Scaling SQL Server
parent: guides-mssqlserver
weight: 55
menu_name: docs_{{ .version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $ kubectl get pod -n demo sample-pxc-0 -o json | jq '.spec.containers[].resource
}
```

You can see the Pod has the default resources which is assigned by Kubedb operator.
You can see the Pod has the default resources which is assigned by KubeDB operator.

We are now ready to apply the `PerconaXtraDBOpsRequest` CR to update the resources of this database.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/postgres/arbiter/arbiter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ section_menu_id: guides

> New to KubeDB? Please start [here](/docs/README.md).
# Kubedb PostgreSQL - Arbiter node for PostgreSQL cluster with even nodes
# KubeDB PostgreSQL - Arbiter node for PostgreSQL cluster with even nodes

Here we will show how to use KubeDB to provision a PostgreSQL DB with Arbiter Node.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ $ kubectl get pod -n demo proxy-server-0 -o json | jq '.spec.containers[].resour
}
```

You can see the Pod has the default resources which is assigned by Kubedb operator.
You can see the Pod has the default resources which is assigned by KubeDB operator.

We are now ready to apply the `ProxySQLOpsRequest` CR to update the resources of this server.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $ kubectl get pod -n demo rm-standalone-0 -o json | jq '.spec.containers[].resou
}
```

You can see the Pod has default resources which is assigned by the Kubedb operator.
You can see the Pod has default resources which is assigned by the KubeDB operator.

We are now ready to apply the `RabbitMQOpsRequest` CR to update the resources of this database.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/redis/backup/stash/standalone/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Here, we have to use the service `sample-redis` and secret `sample-redis-auth` t

### Insert Sample Data

Now, we are going to exec into the database pod and create some sample data. Kubedb has created a secret with access credentials. Let's find out the credentials from the Secret,
Now, we are going to exec into the database pod and create some sample data. KubeDB has created a secret with access credentials. Let's find out the credentials from the Secret,

```yaml
❯ kubectl get secret -n demo sample-redis-auth -o yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $ kubectl get pod -n demo zk-quickstart-0 -o json | jq '.spec.containers[].resou
}
```

You can see the Pod has default resources which is assigned by the Kubedb operator.
You can see the Pod has default resources which is assigned by the KubeDB operator.

We are now ready to apply the `ZooKeeperOpsRequest` CR to update the resources of this database.

Expand Down

0 comments on commit 134157a

Please sign in to comment.