You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Fail over - SQL Server availability group on Kubernetes
17
16
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
19
18
20
-
## Create a manifest file to describe the job
19
+
## Connect to primary replica
21
20
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
115
22
116
23
## Next steps
117
24
25
+
[Manage SQL Server availability group on Kubernetes cluster](sql-server-linux-kubernetes-manage.md)
26
+
118
27
[SQL Server availability group on Kubernetes cluster](sql-server-ag-kubernetes.md)
Copy file name to clipboardExpand all lines: docs/linux/sql-server-linux-kubernetes-manage.md
+102Lines changed: 102 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ To configure an Always On Availability Group on Kubernetes, create a specificati
19
19
20
20
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).
21
21
22
+
23
+
22
24
## Create a manifest file for the specification
23
25
24
26
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.
## 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
+
153
255
## Next steps
154
256
155
257
[SQL Server availability group on Kubernetes cluster](sql-server-ag-kubernetes.md)
0 commit comments