|
| 1 | +--- |
| 2 | +title: SQL Server availability group on Kubernetes cluster |
| 3 | +description: This article introduces availability groups on SQL Server containers |
| 4 | +author: MikeRayMSFT |
| 5 | +ms.author: mikeray |
| 6 | +manager: craigg |
| 7 | +ms.date: 6/10/2018 |
| 8 | +ms.topic: article |
| 9 | +ms.prod: sql |
| 10 | +ms.component: "" |
| 11 | +ms.suite: "sql" |
| 12 | +ms.custom: "sql-linux" |
| 13 | +ms.technology: linux |
| 14 | +--- |
| 15 | + |
| 16 | +# Containerized SQL Server availability group |
| 17 | + |
| 18 | +SQL Server vNext supports availability groups on containers in a Kubernetes. For availability groups, deploy the SQL Server [Kubernetes operator](http://coreos.com/blog/introducing-operators.html) to your Kubernetes cluster. The operator helps package, deploy, and manage the availability group in a cluster. |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +In the image above, a four-node kubernetes clusters host an availability group with three replicas. The solution includes the following components: |
| 23 | + |
| 24 | +* A Kubernetes [*deployment*](http://kubernetes.io/docs/concepts/workloads/controllers/deployment/). The deployment includes the operator and a configuration map. These provide the container image, software, and instructions required to deploy SQL Server instances for the availability group. |
| 25 | + |
| 26 | +* Three nodes, each hosting a [*StatefulSet*](http://kubernetes.io/docs/concepts/workloads/controllers/statefulset/). The StatefulSet contains a [*pod*](http://kubernetes.io/docs/concepts/workloads/pods/pod-overview/). Each pod contains: |
| 27 | + * A SQL Server container running one instance of SQL Server. |
| 28 | + * An availability group agent. |
| 29 | + |
| 30 | +* Two [*ConfigMaps*](http://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) related to the availability group. The ConfigMaps provide information about: |
| 31 | + * The deployment for the operator. |
| 32 | + * The availability group. |
| 33 | + |
| 34 | + * [*Persistent volumes*](http://kubernetes.io/docs/concepts/storage/persistent-volumes/) are pieces of storage. A *persistent volume claim* (PVC) is a request for storage by a user. Each container is affiliated with a PVC for the data and log storage. In Azure Kubernetes Service (AKS), you [create a persistent volume claim](http://docs.microsoft.com/azure/aks/azure-disks-dynamic-pv) to automatically provision storage based on a storage class. |
| 35 | + |
| 36 | + |
| 37 | +In addition, the cluster stores [*secrets*](http://kubernetes.io/docs/concepts/configuration/secret/) for the passwords, certificates, keys, and other sensitive information. |
| 38 | + |
| 39 | +## Deploy the availability group in Kubernetes |
| 40 | + |
| 41 | +To deploy an availability group in Kubernetes: |
| 42 | + |
| 43 | +1. Create the Kubernetes cluster |
| 44 | + |
| 45 | + For an availability group, create at least three nodes for SQL Server plus a node for the operator. |
| 46 | + |
| 47 | +1. Deploy the operator |
| 48 | + |
| 49 | +1. Configure the storage |
| 50 | + |
| 51 | +1. Deploy the StatefulSet |
| 52 | + |
| 53 | + The operator listens for instructions to deploy the StatefulSet. It automatically creates the instances of SQL Server on three separate nodes and configures the availability group with an external cluster manager. |
| 54 | + |
| 55 | +1. Create the databases and attach them to the availability group |
| 56 | + |
| 57 | +For detailed steps, see [Configure a SQL Server Always On availability group in Kubernetes for high availability](tutorial-sql-server-ag-kubernetes.md). |
| 58 | + |
| 59 | +## SQL Server Kubernetes operator |
| 60 | + |
| 61 | +After you deploy the operator, it registers a custom SQL Server resource. Use the operator to deploy this resource. Each resource corresponds to an instance of SQL Server and includes specific properties like `sapassword` and `monitoring policy`. The operator parses the resource and deploys a Kubernetes StatefulSet. |
| 62 | + |
| 63 | +The StatfulSet contains: |
| 64 | + |
| 65 | +* mssql-server container |
| 66 | + |
| 67 | +* AG Agent container |
| 68 | + |
| 69 | +The code for the operator, AG agent, and SQL Server is packaged in a Docker image called `mssql-server-k8s-agents`. This image contains following binaries: |
| 70 | + |
| 71 | +* `mssql-server-k8s-operator` |
| 72 | + |
| 73 | + This process is deployed as a separate Kubernetes deployment. It registers the custom Kubernetes [custom resource](http://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) called `SqlServer` (sqlservers.mssql.microsoft.com). Then it listens for such resources being created or updated in the Kubernetes cluster. For every such event, it creates or updates the Kubernetes resources for the corresponding instance (for example the StatefulSet, or `mssql-server-k8s-init-sql` job). |
| 74 | + |
| 75 | +* `mssql-server-k8s-sqlhealth-agent` |
| 76 | + |
| 77 | + This web server serves Kubernetes [liveness probes](http://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/) to determine the health of a SQL Server instance. Monitors the health of the local SQL Server instance by calling `sp_server_diagnostics` and comparing the results with your monitor policy. |
| 78 | + |
| 79 | +* `mssql-server-k8s-ag-agent-supervisor` |
| 80 | + |
| 81 | + This process spawns `mssql-server-k8s-ag-agent` processes as child processes and terminates them as necessary, based on which AGs the local SQL Server instance is meant to be part of. |
| 82 | + |
| 83 | +* `mssql-server-k8s-ag-agent` |
| 84 | + |
| 85 | + This process monitors the health of an AG replica on a single SQL Server instance and performs failovers. |
| 86 | + |
| 87 | +* `mssql-server-k8s-init-sql` |
| 88 | + |
| 89 | + This Kubernetes [job](http://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) applies a desired state configuration to a SQL Server instance. The job is created by the operator every time a SqlServer resource is created or updated. It ensures that the target SQL Server instance corresponding to the custom resource has the desired configuration described in the resource. |
| 90 | + |
| 91 | + For example, if any of the following settings are required, it completes them: |
| 92 | + * Update the SA password |
| 93 | + * Creates the SQL login for the agents |
| 94 | + * Creates the DBM endpoint |
| 95 | + |
| 96 | +* `mssql-server-k8s-rotate-creds` |
| 97 | + |
| 98 | + This Kubernetes job implements the rotate credentials task. Create this job to request updates to the SA password, agent SQL login password, DBM cert, etc. The SA password is specified as the job parameters. The others are auto-generated. |
| 99 | + |
| 100 | + *`mssql-server-k8s-failover` |
| 101 | + |
| 102 | + A Kubernetes job that implements the manual failover workflow. |
| 103 | + |
| 104 | +### Notes |
| 105 | + |
| 106 | +To deploy an AG in Kubernetes, define a SqlServer resource with the names of one or more AGs that the instance should be a part of. |
| 107 | + |
| 108 | +Regardless of the AG configuration, The operator will always deploy the AG monitor. If the SqlServer resource does not list any AG, the operator will still deploy these containers. |
| 109 | + |
| 110 | +The version for the operator image is identical to the version for the SQL Server image. |
0 commit comments