Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit 7e444b5

Browse files
author
bcurrerb
committed
Added support and documentation for MYSQL Enterprise
1 parent 194e751 commit 7e444b5

File tree

6 files changed

+366
-4
lines changed

6 files changed

+366
-4
lines changed

docs/enterprise-edition-example.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Enterprise edition tutorial
2+
This tutorial will explain how to create a mysqlcluster that runs the enterprise version of mysql.
3+
4+
## Prerequisites
5+
- A Kubernetes Cluster running on Kubernetes 1.7.0+.
6+
- The mysql-operator repository checked out locally.
7+
- Access to a Docker registry that contains the enterprise version of mysql.
8+
9+
##Create the Operator
10+
This file bundles the creation of various resources:
11+
12+
1. Custom resources
13+
2. RBAC configuration <sup>*</sup>
14+
3. The Operator
15+
4. The Agent
16+
17+
Section 3 of the file pulls the sql enterprise image from the docker store: `store/oracle/mysql-enterprise-server`. If you wish to pull the image from somewhere else you will need to swap out this address.
18+
```
19+
kubectl apply -f examples/example-enterprise-deployment.yaml
20+
```
21+
22+
##Create a secret with registry credentials
23+
To be able to pull the mysql enterprise edition from docker it is necessary to provide credentials, these credentials must be supplied in the form of a Kubernetes secret.
24+
25+
- The name of the secret `myregistrykey` must match the name in the `imagepullsecrets` which is found in Section 3 of the `example-enterprise-deployment.yaml`.
26+
- The secret must be created in the same namespace as the mysqlcluster which we will make in the next step.
27+
- If you are pulling the mysql enterprise image from a different registry then the secret must contain the relevant credentials for that registry.
28+
29+
>For alternative ways to create Kubernetes secretes see their documentation on [creating secrets from docker configs](https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) or [creating secrets manually](https://kubernetes.io/docs/concepts/containers/images/#creating-a-secret-with-a-docker-config).
30+
31+
Enter your credentials into the following command and execute it to create a Kubernetes secret that will enable pulling images from the Docker store.
32+
```
33+
kubectl create secret docker-registry myregistrykey \
34+
--docker-server=https://index.docker.io/v1/ \
35+
--docker-username= \
36+
--docker-password= \
37+
--docker-email=
38+
```
39+
##Create your mysqlcluster
40+
Finally, create the mysqlcluster.
41+
42+
- The version to be used has been specified in the file. Without this a default version is used which is **not** guaranteed to match an available image of mysql enterprise.
43+
- The lowest version supported by the mysql operator is **8.0.11**
44+
- The namespace of the cluster must match the namespace of the secret we created in the previous step. This file omits namespace in the metadata so the cluster will be created in the default namespace.
45+
```
46+
kubectl apply -f examples/cluster/cluster-with-3-members-enterprise-version.yaml
47+
```
48+
You can now run the following command to see the newly created mysql cluster
49+
```
50+
kubectl describe mysqlcluster mysql
51+
```
52+
53+
## Clean up
54+
55+
To remove the mysqlcluster and each of the components created in this tutorial, execute the following:
56+
```
57+
kubectl delete -f examples/cluster/cluster-with-3-members-enterprise-version.yaml
58+
kubectl delete secret myregistrykey
59+
kubectl delete -f examples/example-enterprise-deployment.yaml
60+
```
61+
62+
><sup>*</sup>If you run into issues when creating RBAC roles see [Access controls](https://docs.cloud.oracle.com/iaas/Content/ContEng/Concepts/contengabouta]ccesscontrol.htm?) for more information.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: mysql.oracle.com/v1alpha1
2+
kind: Cluster
3+
metadata:
4+
name: mysql
5+
spec:
6+
members: 3
7+
version: "8.0.11"
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
# 01 - Custom resources
2+
---
3+
apiVersion: v1
4+
kind: Namespace
5+
metadata:
6+
name: mysql-operator
7+
---
8+
apiVersion: apiextensions.k8s.io/v1beta1
9+
kind: CustomResourceDefinition
10+
metadata:
11+
name: mysqlclusters.mysql.oracle.com
12+
spec:
13+
group: mysql.oracle.com
14+
version: v1alpha1
15+
scope: Namespaced
16+
names:
17+
kind: Cluster
18+
singular: mysqlcluster
19+
plural: mysqlclusters
20+
---
21+
apiVersion: apiextensions.k8s.io/v1beta1
22+
kind: CustomResourceDefinition
23+
metadata:
24+
name: mysqlbackups.mysql.oracle.com
25+
spec:
26+
group: mysql.oracle.com
27+
version: v1alpha1
28+
scope: Namespaced
29+
names:
30+
kind: Backup
31+
singular: mysqlbackup
32+
plural: mysqlbackups
33+
---
34+
apiVersion: apiextensions.k8s.io/v1beta1
35+
kind: CustomResourceDefinition
36+
metadata:
37+
name: mysqlrestores.mysql.oracle.com
38+
spec:
39+
group: mysql.oracle.com
40+
version: v1alpha1
41+
scope: Namespaced
42+
names:
43+
kind: Restore
44+
singular: mysqlrestore
45+
plural: mysqlrestores
46+
---
47+
apiVersion: apiextensions.k8s.io/v1beta1
48+
kind: CustomResourceDefinition
49+
metadata:
50+
name: mysqlbackupschedules.mysql.oracle.com
51+
spec:
52+
group: mysql.oracle.com
53+
version: v1alpha1
54+
scope: Namespaced
55+
names:
56+
kind: BackupSchedule
57+
singular: mysqlbackupschedule
58+
plural: mysqlbackupschedules
59+
#02
60+
---
61+
apiVersion: v1
62+
kind: ServiceAccount
63+
metadata:
64+
name: mysql-operator
65+
namespace: mysql-operator
66+
67+
---
68+
apiVersion: v1
69+
kind: ServiceAccount
70+
metadata:
71+
name: mysql-agent
72+
namespace: default
73+
74+
#RBAC
75+
---
76+
apiVersion: rbac.authorization.k8s.io/v1beta1
77+
kind: ClusterRole
78+
metadata:
79+
name: mysql-operator
80+
namespace: mysql-operator
81+
rules:
82+
- apiGroups: [""]
83+
resources: ["pods"]
84+
verbs:
85+
- get
86+
- list
87+
- patch
88+
- update
89+
- watch
90+
91+
- apiGroups: [""]
92+
resources: ["secrets"]
93+
verbs: ["create"]
94+
95+
- apiGroups: [""]
96+
resources: ["services"]
97+
verbs:
98+
- create
99+
- get
100+
- list
101+
- watch
102+
103+
- apiGroups: [""]
104+
resources: ["events"]
105+
verbs:
106+
- create
107+
- update
108+
- patch
109+
110+
- apiGroups: ["apps"]
111+
resources: ["statefulsets"]
112+
verbs:
113+
- create
114+
- get
115+
- list
116+
- patch
117+
- update
118+
- watch
119+
120+
- apiGroups: ["mysql.oracle.com"]
121+
resources:
122+
- mysqlbackups
123+
- mysqlbackupschedules
124+
- mysqlclusters
125+
- mysqlclusters/finalizers
126+
- mysqlrestores
127+
verbs:
128+
- get
129+
- list
130+
- patch
131+
- update
132+
- watch
133+
134+
- apiGroups: ["mysql.oracle.com"]
135+
resources: ["mysqlbackups"]
136+
verbs: ["create"]
137+
138+
---
139+
apiVersion: rbac.authorization.k8s.io/v1beta1
140+
kind: ClusterRole
141+
metadata:
142+
name: mysql-agent
143+
namespace: mysql-operator
144+
rules:
145+
- apiGroups: [""]
146+
resources: ["pods"]
147+
verbs:
148+
- get
149+
- list
150+
- patch
151+
- update
152+
- watch
153+
154+
- apiGroups: [""]
155+
resources: ["secrets"]
156+
verbs: ["get"]
157+
158+
- apiGroups: [""]
159+
resources: ["events"]
160+
verbs:
161+
- create
162+
- update
163+
- patch
164+
165+
- apiGroups: ["mysql.oracle.com"]
166+
resources:
167+
- mysqlbackups
168+
- mysqlbackupschedules
169+
- mysqlclusters
170+
- mysqlclusters/finalizers
171+
- mysqlrestores
172+
verbs:
173+
- get
174+
- list
175+
- patch
176+
- update
177+
- watch
178+
179+
---
180+
apiVersion: rbac.authorization.k8s.io/v1beta1
181+
kind: ClusterRoleBinding
182+
metadata:
183+
name: mysql-operator
184+
namespace: mysql-operator
185+
roleRef:
186+
apiGroup: rbac.authorization.k8s.io
187+
kind: ClusterRole
188+
name: mysql-operator
189+
subjects:
190+
- kind: ServiceAccount
191+
name: mysql-operator
192+
namespace: mysql-operator
193+
194+
---
195+
apiVersion: rbac.authorization.k8s.io/v1beta1
196+
kind: ClusterRoleBinding
197+
metadata:
198+
name: mysql-agent
199+
namespace: mysql-operator
200+
roleRef:
201+
apiGroup: rbac.authorization.k8s.io
202+
kind: ClusterRole
203+
name: mysql-agent
204+
subjects:
205+
- kind: ServiceAccount
206+
name: mysql-agent
207+
namespace: mysql-operator
208+
209+
#03 - The operator
210+
---
211+
apiVersion: v1
212+
kind: ConfigMap
213+
metadata:
214+
name: mysql-operator-config
215+
namespace: mysql-operator
216+
labels:
217+
app: mysql-operator
218+
data:
219+
mysql-operator-config.yaml: |
220+
images:
221+
mysqlServer: store/oracle/mysql-enterprise-server #Enterprise sql image
222+
mysqlAgent: iad.ocir.io/oracle/mysql-agent
223+
imagePullSecret:
224+
name: myregistrykey #Name of secret with docker credentials
225+
---
226+
apiVersion: apps/v1beta1
227+
kind: Deployment
228+
metadata:
229+
name: mysql-operator
230+
namespace: mysql-operator
231+
labels:
232+
app: mysql-operator
233+
spec:
234+
replicas: 1
235+
selector:
236+
matchLabels:
237+
app: mysql-operator
238+
template:
239+
metadata:
240+
labels:
241+
app: mysql-operator
242+
annotations:
243+
prometheus.io/scrape: "true"
244+
prometheus.io/port: "8080"
245+
spec:
246+
serviceAccountName: mysql-operator
247+
imagePullSecrets:
248+
- name: docker-secret
249+
volumes:
250+
- name: mysql-operator-config-volume
251+
configMap:
252+
name: mysql-operator-config
253+
containers:
254+
- name: mysql-operator-controller
255+
imagePullPolicy: Always
256+
image: iad.ocir.io/oracle/mysql-operator:0.2.0
257+
ports:
258+
- containerPort: 10254
259+
volumeMounts:
260+
- name: mysql-operator-config-volume
261+
mountPath: /etc/mysql-operator
262+
args:
263+
- --v=4
264+
- --mysql-agent-image=iad.ocir.io/oracle/mysql-agent
265+
266+
#04 - The Agent
267+
---
268+
apiVersion: v1
269+
kind: ServiceAccount
270+
metadata:
271+
name: mysql-agent
272+
namespace: default
273+
274+
---
275+
kind: RoleBinding
276+
apiVersion: rbac.authorization.k8s.io/v1beta1
277+
metadata:
278+
name: mysql-agent
279+
namespace: default
280+
roleRef:
281+
apiGroup: rbac.authorization.k8s.io
282+
kind: ClusterRole
283+
name: mysql-agent
284+
subjects:
285+
- kind: ServiceAccount
286+
name: mysql-agent
287+
namespace: default

pkg/apis/mysql/v1alpha1/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func getOperatorVersionLabel(labelMap map[string]string) string {
5050
return labelMap[constants.MySQLOperatorVersionLabel]
5151
}
5252

53-
// EnsureDefaults will ensure that if a user omits and fields in the
53+
// EnsureDefaults will ensure that if a user omits any fields in the
5454
// spec that are required, we set some sensible defaults.
5555
// For example a user can choose to omit the version
5656
// and number of members.

pkg/options/operator/options.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"path/filepath"
2121
"time"
2222

23+
"k8s.io/api/core/v1"
24+
2325
"github.com/golang/glog"
2426
"github.com/pkg/errors"
2527
"github.com/spf13/pflag"
@@ -36,8 +38,9 @@ const (
3638
// Images is the configuration of required MySQLOperator images. Remember to configure the appropriate
3739
// credentials for the target repositories.
3840
type Images struct {
39-
MySQLServerImage string `yaml:"mysqlServer"`
40-
MySQLAgentImage string `yaml:"mysqlAgent"`
41+
MySQLServerImage string `yaml:"mysqlServer"`
42+
MySQLAgentImage string `yaml:"mysqlAgent"`
43+
ImagePullSecret *v1.LocalObjectReference `yaml:"imagePullSecret"`
4144
}
4245

4346
// MySQLOperatorOpts holds the options for the MySQLOperator.
@@ -65,7 +68,7 @@ type MySQLOperatorOpts struct {
6568
MinResyncPeriod metav1.Duration `yaml:"minResyncPeriod"`
6669
}
6770

68-
// MySQLOperatorOpts will create a new MySQLOperatorOpts. If a valid
71+
// NewMySQLOperatorOpts will create a new MySQLOperatorOpts. If a valid
6972
// config file is specified and exists, it will be used to initialise the
7073
// server. Otherwise, a default server will be created.
7174
//

0 commit comments

Comments
 (0)