Skip to content

Commit 23e7d13

Browse files
committed
Update deploy, connect, manage
1 parent 2996660 commit 23e7d13

3 files changed

Lines changed: 112 additions & 97 deletions

File tree

Lines changed: 6 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: SQL Server Always On availability group Kubernetes failover job environment variables
2+
title: Connect to SQL Server Always On Availability Group on Kubernetes cluster
33
description: This article explains the environment variables for the SQL Server Kubernetes Always On availability group failover job
44
author: MikeRayMSFT
55
ms.author: mikeray
@@ -13,106 +13,15 @@ ms.custom: "sql-linux"
1313
ms.technology: linux
1414
monikerRange: ">=sql-server-ver15||>=sql-server-linux-ver15||=sqlallproducts-allversions"
1515
---
16-
# Fail over - SQL Server availability group on Kubernetes
1716

18-
To fail over an Always On availability group primary replica to a different node in Kubernetes, use a job. This article identifies the environment variables for this job.
17+
# Connect to SQL Server Availability Group on Kubernetes
1918

20-
## Create a manifest file to describe the job
19+
## Connect to primary replica
2120

22-
The following example of a manifest file describes a job to manually fail over job for an availability group on a Kubernetes replica. Copy the contents of the example into a new file called `manualFailover.yaml`.
23-
24-
```yaml
25-
---
26-
apiVersion: v1
27-
kind: ServiceAccount
28-
metadata:
29-
name: manual-failover
30-
31-
---
32-
apiVersion: rbac.authorization.k8s.io/v1
33-
kind: Role
34-
metadata:
35-
name: manual-failover
36-
rules:
37-
- resources: ["configmaps"]
38-
apiGroups: [""]
39-
verbs: ["get", "update"]
40-
resourceNames: ["ag1"]
41-
- resources: ["endpoints"]
42-
apiGroups: [""]
43-
verbs: ["get"]
44-
resourceNames: ["ag1"]
45-
- resources: ["pods"]
46-
apiGroups: [""]
47-
verbs: ["list"]
48-
49-
---
50-
apiVersion: rbac.authorization.k8s.io/v1
51-
kind: RoleBinding
52-
metadata:
53-
name: manual-failover
54-
namespace: default
55-
roleRef:
56-
name: manual-failover
57-
apiGroup: rbac.authorization.k8s.io
58-
kind: Role
59-
subjects:
60-
- name: manual-failover
61-
kind: ServiceAccount
62-
63-
---
64-
apiVersion: batch/v1
65-
kind: Job
66-
metadata:
67-
name: manual-failover
68-
spec:
69-
template:
70-
metadata:
71-
name: manual-failover
72-
spec:
73-
serviceAccount: manual-failover
74-
restartPolicy: Never
75-
containers:
76-
- name: manual-failover
77-
image: mssql-ha-supervisor:20.22
78-
command: ["/mssql-server-k8s-failover"]
79-
env:
80-
- name: MSSQL_K8S_AG_NAME
81-
value: ag1
82-
- name: MSSQL_K8S_NEW_PRIMARY
83-
value: sql-1-0
84-
- name: MSSQL_K8S_NAMESPACE
85-
valueFrom:
86-
fieldRef:
87-
fieldPath: metadata.namespace
88-
```
89-
90-
When you run the job, the supervisor will elect a new leader and move the primary replica to the SQL Server instance of the leader. To run the job, run the following command:
91-
92-
```azurecli
93-
kubectl apply -f manualFailover.yaml
94-
```
95-
96-
After you run the job, delete it. The job object in Kubernetes remains after completion so you can view its status. You have to manually delete old jobs after noting their status. Deleting the job also deletes the Kubernetes logs. If you do not delete the job, future failover jobs will fail unless you change the job name and the pod selector. For more information, see [Jobs - Run to Completion](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/).
97-
98-
## Failover job environment variables
99-
100-
* `MSSQL_K8S_AG_NAME`
101-
* Optional
102-
* **Description**: The availability group name.
103-
104-
* `MSSQL_K8S_NEW_PRIMARY`
105-
* Optional
106-
* **Description**: The target of the failover. Accepts the target SQL Server pod name, IP address, StatefulSet name, server name, or host name. Additionally the `!` prefix prevents failover to a specified target. Example `!sql-1`.
107-
108-
* `FORCE_FAILOVER_ALLOW_DATA_LOSS`
109-
* Optional
110-
* **Description**: Boolean to force the failover with potential data loss.
111-
112-
* `MSSQL_K8S_NAMESPACE`
113-
* Optional
114-
* **Description**: Kubernetes namespace of the availability group.
21+
## Connect to secondary replica
11522

11623
## Next steps
11724

25+
[Manage SQL Server availability group on Kubernetes cluster](sql-server-linux-kubernetes-manage.md)
26+
11827
[SQL Server availability group on Kubernetes cluster](sql-server-ag-kubernetes.md)

docs/linux/sql-server-linux-kubernetes-deploy.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ The following example describes a deployment for the `mssql-operator`.
4949

5050
## Next steps
5151

52+
[Connect to SQL Server availability group on Kubernetes cluster](sql-server-linux-kubernetes-connect.md)
53+
54+
[Manage SQL Server availability group on Kubernetes cluster](sql-server-linux-kubernetes-manage.md)
55+
5256
[SQL Server availability group on Kubernetes cluster](sql-server-ag-kubernetes.md)

docs/linux/sql-server-linux-kubernetes-manage.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ To configure an Always On Availability Group on Kubernetes, create a specificati
1919

2020
This article shows how to create the specification, and explains the parameters the parameters. See an example of the of the end-to-end deployment in [this tutorial](tutorial-sql-server-ag-kubernetes.md).
2121

22+
23+
2224
## Create a manifest file for the specification
2325

2426
The following example of a manifest file describes a Kubernetes specification for SQL Server. Copy the contents of the example into a new file named `sqlserver.yaml` to create the SQL Server availability group StatefulSet in Kubernetes.
@@ -150,6 +152,106 @@ kubectl apply -f sqlserver.yaml
150152
availabilityMode: <synchronousCommit | asynchronousCommit | configurationOnly>
151153
```
152154

155+
## Fail over - SQL Server availability group on Kubernetes
156+
157+
To fail over an Always On availability group primary replica to a different node in Kubernetes, use a job. This article identifies the environment variables for this job.
158+
159+
## Create a manifest file to describe the job
160+
161+
The following example of a manifest file describes a job to manually fail over job for an availability group on a Kubernetes replica. Copy the contents of the example into a new file called `manualFailover.yaml`.
162+
163+
```yaml
164+
---
165+
apiVersion: v1
166+
kind: ServiceAccount
167+
metadata:
168+
name: manual-failover
169+
170+
---
171+
apiVersion: rbac.authorization.k8s.io/v1
172+
kind: Role
173+
metadata:
174+
name: manual-failover
175+
rules:
176+
- resources: ["configmaps"]
177+
apiGroups: [""]
178+
verbs: ["get", "update"]
179+
resourceNames: ["ag1"]
180+
- resources: ["endpoints"]
181+
apiGroups: [""]
182+
verbs: ["get"]
183+
resourceNames: ["ag1"]
184+
- resources: ["pods"]
185+
apiGroups: [""]
186+
verbs: ["list"]
187+
188+
---
189+
apiVersion: rbac.authorization.k8s.io/v1
190+
kind: RoleBinding
191+
metadata:
192+
name: manual-failover
193+
namespace: default
194+
roleRef:
195+
name: manual-failover
196+
apiGroup: rbac.authorization.k8s.io
197+
kind: Role
198+
subjects:
199+
- name: manual-failover
200+
kind: ServiceAccount
201+
202+
---
203+
apiVersion: batch/v1
204+
kind: Job
205+
metadata:
206+
name: manual-failover
207+
spec:
208+
template:
209+
metadata:
210+
name: manual-failover
211+
spec:
212+
serviceAccount: manual-failover
213+
restartPolicy: Never
214+
containers:
215+
- name: manual-failover
216+
image: mssql-ha-supervisor:20.22
217+
command: ["/mssql-server-k8s-failover"]
218+
env:
219+
- name: MSSQL_K8S_AG_NAME
220+
value: ag1
221+
- name: MSSQL_K8S_NEW_PRIMARY
222+
value: sql-1-0
223+
- name: MSSQL_K8S_NAMESPACE
224+
valueFrom:
225+
fieldRef:
226+
fieldPath: metadata.namespace
227+
```
228+
229+
When you run the job, the supervisor will elect a new leader and move the primary replica to the SQL Server instance of the leader. To run the job, run the following command:
230+
231+
```azurecli
232+
kubectl apply -f manualFailover.yaml
233+
```
234+
235+
After you run the job, delete it. The job object in Kubernetes remains after completion so you can view its status. You have to manually delete old jobs after noting their status. Deleting the job also deletes the Kubernetes logs. If you do not delete the job, future failover jobs will fail unless you change the job name and the pod selector. For more information, see [Jobs - Run to Completion](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/).
236+
237+
## Failover job environment variables
238+
239+
* `MSSQL_K8S_AG_NAME`
240+
* Optional
241+
* **Description**: The availability group name.
242+
243+
* `MSSQL_K8S_NEW_PRIMARY`
244+
* Optional
245+
* **Description**: The target of the failover. Accepts the target SQL Server pod name, IP address, StatefulSet name, server name, or host name. Additionally the `!` prefix prevents failover to a specified target. Example `!sql-1`.
246+
247+
* `FORCE_FAILOVER_ALLOW_DATA_LOSS`
248+
* Optional
249+
* **Description**: Boolean to force the failover with potential data loss.
250+
251+
* `MSSQL_K8S_NAMESPACE`
252+
* Optional
253+
* **Description**: Kubernetes namespace of the availability group.
254+
153255
## Next steps
154256

155257
[SQL Server availability group on Kubernetes cluster](sql-server-ag-kubernetes.md)

0 commit comments

Comments
 (0)