-
Notifications
You must be signed in to change notification settings - Fork 237
Support MySQL Enterprise #226
Changes from 7 commits
7e444b5
e0a5ded
ce721f9
d5d2694
83c4da0
e8328a6
eb5daf6
eefb0cc
d68b5a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Enterprise edition tutorial | ||
This tutorial will explain how to create a MySQL cluster that runs the enterprise version of MySQL. | ||
|
||
## Prerequisites | ||
|
||
- The MySQL operator repository checked out locally. | ||
- Access to a Docker registry that contains the enterprise version of MySQL. | ||
|
||
## 01 - Create the Operator | ||
You will need to create the following: | ||
|
||
1. Custom resources | ||
2. RBAC configuration <sup>*</sup> | ||
3. The Operator | ||
4. The Agent ServiceAccount & RoleBinding | ||
|
||
The creation of these resources can be achieved by following the [introductory tutorial][1]; return here before creating a MySQL cluster. | ||
|
||
## 02 - Create a secret with registry credentials | ||
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. | ||
|
||
- Remember the name of the secret *myregistrykey* as this will need to be used in step 03 when creating the cluster. | ||
- If you are pulling the MySQL Enterprise image from a different registry than the one in the example then the secret must contain the relevant credentials for that registry. | ||
|
||
>For alternative ways to create Kubernetes secrets 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). | ||
|
||
Enter your credentials into the following command and execute it to create a Kubernetes secret that will enable pulling images from the Docker store. | ||
``` | ||
kubectl create secret docker-registry myregistrykey \ | ||
--docker-server=https://index.docker.io/v1/ \ | ||
--docker-username= \ | ||
--docker-password= \ | ||
--docker-email= | ||
``` | ||
## 03 - Create your MySQL Cluster | ||
Finally, create your MySQL Cluster with the required specifications entered under `spec:` | ||
|
||
- The `repository:` field should be the path to a Docker registry containing the enterprise edition of MySQL. If this is omitted, the default is taken from the MySQL operator field `defaultMysqlServer:` which you can also specify. | ||
- The `imagePullSecrets`: field allows you to specify a list of Kubernetes secret names. These secret(s) should contain your credentials for the Docker registry. | ||
- The version to be used should be specified, without this, a default version is used which is **not** guaranteed to match an available image of MySQL Enterprise. | ||
- The namespace of the cluster must match the namespace of the RBAC permissions created in step 01. | ||
``` | ||
kubectl apply -f examples/cluster/cluster-enterprise-version.yaml | ||
``` | ||
### Check that it is running | ||
You can now run the following command to access the SQL prompt in your MySQL Cluster, just replace `<NAMESPACE>` with the namespace you created your cluster in. | ||
``` | ||
sh hack/mysql.sh <NAMESPACE>/mysql-0 | ||
``` | ||
|
||
><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. | ||
|
||
[1]: docs/tutorial.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: mysql.oracle.com/v1alpha1 | ||
kind: Cluster | ||
metadata: | ||
name: mysql-enterprise | ||
spec: | ||
version: "8.0.11" | ||
repository: store/oracle/mysql-enterprise-server | ||
imagePullSecrets: | ||
- name: myregistrykey |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already imported as |
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
@@ -27,6 +28,11 @@ const MinimumMySQLVersion = "8.0.11" | |
type ClusterSpec struct { | ||
// Version defines the MySQL Docker image version. | ||
Version string `json:"version"` | ||
// Repository defines the image to be pulled for the MySQL server. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Repository string `json:"repository"` | ||
// ImagePullSecret defines the name of the secret that contains the | ||
// required credentials for pulling from the specified Repository. | ||
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecret"` | ||
// Members defines the number of MySQL instances in a cluster | ||
Members int32 `json:"members,omitempty"` | ||
// BaseServerID defines the base number used to create unique server_id | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,15 +29,16 @@ import ( | |
) | ||
|
||
const ( | ||
mysqlServer = "mysql/mysql-server" | ||
mysqlAgent = "iad.ocir.io/oracle/mysql-agent" | ||
mysqlServer = "mysql/mysql-server" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of redefining this here use the value from the |
||
) | ||
|
||
// Images is the configuration of required MySQLOperator images. Remember to configure the appropriate | ||
// credentials for the target repositories. | ||
// credentials for the target repositories. The DefaultMySQLServerImage can be overridden on a per-cluster | ||
// basis by setting the Repository field. | ||
type Images struct { | ||
MySQLServerImage string `yaml:"mysqlServer"` | ||
MySQLAgentImage string `yaml:"mysqlAgent"` | ||
MySQLAgentImage string `yaml:"mysqlAgent"` | ||
DefaultMySQLServerImage string `yaml:"defaultMysqlServer"` | ||
} | ||
|
||
// MySQLOperatorOpts holds the options for the MySQLOperator. | ||
|
@@ -65,7 +66,7 @@ type MySQLOperatorOpts struct { | |
MinResyncPeriod metav1.Duration `yaml:"minResyncPeriod"` | ||
} | ||
|
||
// MySQLOperatorOpts will create a new MySQLOperatorOpts. If a valid | ||
// NewMySQLOperatorOpts will create a new MySQLOperatorOpts. If a valid | ||
// config file is specified and exists, it will be used to initialise the | ||
// server. Otherwise, a default server will be created. | ||
// | ||
|
@@ -106,12 +107,12 @@ func (s *MySQLOperatorOpts) EnsureDefaults() { | |
if &s.Images == nil { | ||
s.Images = Images{} | ||
} | ||
if s.Images.MySQLServerImage == "" { | ||
s.Images.MySQLServerImage = mysqlServer | ||
} | ||
if s.Images.MySQLAgentImage == "" { | ||
s.Images.MySQLAgentImage = mysqlAgent | ||
} | ||
if s.Images.DefaultMySQLServerImage == "" { | ||
s.Images.DefaultMySQLServerImage = mysqlServer | ||
} | ||
if s.MinResyncPeriod.Duration <= 0 { | ||
s.MinResyncPeriod = metav1.Duration{Duration: 12 * time.Hour} | ||
} | ||
|
@@ -122,7 +123,7 @@ func (s *MySQLOperatorOpts) AddFlags(fs *pflag.FlagSet) *pflag.FlagSet { | |
fs.StringVar(&s.KubeConfig, "kubeconfig", s.KubeConfig, "Path to Kubeconfig file with authorization and master location information.") | ||
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).") | ||
fs.StringVar(&s.Namespace, "namespace", metav1.NamespaceAll, "The namespace for which the MySQL operator manages MySQL clusters. Defaults to all.") | ||
fs.StringVar(&s.Images.MySQLServerImage, "mysql-server-image", s.Images.MySQLServerImage, "The name of the target 'mysql-server' image. Defaults to: mysql/mysql-server.") | ||
prydie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fs.StringVar(&s.Images.DefaultMySQLServerImage, "mysql-server-image", mysqlServer, "The name of the default target for the 'mysql-server' image (can be overridden on a per-cluster basis). Defaults to: "+mysqlServer+".") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fs.StringVar(&s.Images.MySQLAgentImage, "mysql-agent-image", s.Images.MySQLAgentImage, "The name of the target 'mysql-agent' image. Defaults to: iad.ocir.io/oracle/mysql-agent.") | ||
fs.DurationVar(&s.MinResyncPeriod.Duration, "min-resync-period", s.MinResyncPeriod.Duration, "The resync period in reflectors will be random between MinResyncPeriod and 2*MinResyncPeriod.") | ||
return fs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,8 +344,15 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic | |
}) | ||
} | ||
|
||
var serverImage string | ||
if cluster.Spec.Repository != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defaulting will be redundant if we can manage to default in |
||
serverImage = cluster.Spec.Repository | ||
} else { | ||
serverImage = images.DefaultMySQLServerImage | ||
} | ||
|
||
containers := []v1.Container{ | ||
mysqlServerContainer(cluster, images.MySQLServerImage, rootPassword, members, baseServerID), | ||
mysqlServerContainer(cluster, serverImage, rootPassword, members, baseServerID), | ||
mysqlAgentContainer(cluster, images.MySQLAgentImage, rootPassword, members)} | ||
|
||
podLabels := map[string]string{ | ||
|
@@ -399,6 +406,9 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic | |
}, | ||
} | ||
|
||
if cluster.Spec.ImagePullSecrets != nil { | ||
ss.Spec.Template.Spec.ImagePullSecrets = append(ss.Spec.Template.Spec.ImagePullSecrets, cluster.Spec.ImagePullSecrets...) | ||
} | ||
if cluster.Spec.VolumeClaimTemplate != nil { | ||
ss.Spec.VolumeClaimTemplates = append(ss.Spec.VolumeClaimTemplates, *cluster.Spec.VolumeClaimTemplate) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/MysqlServer/DefaultRepository/