Browse Source

Proyecto independiente de reevolution

Celestino Rey 4 months ago
commit
36a1a9cb88
6 changed files with 157 additions and 0 deletions
  1. 71 0
      README.md
  2. 1 0
      conecta.sh
  3. 11 0
      mysql-innodb-cluster.yaml
  4. 9 0
      mysql-secrets.yaml
  5. 57 0
      php-deployment.yaml
  6. 8 0
      secreto.yaml

+ 71 - 0
README.md

@@ -0,0 +1,71 @@
+# MySQL Operator for Kubernetes Installation
+
+## Using Manifest Files with kubectl
+
+First deploy the Custom Resource Definition (CRDs):
+
+    kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/9.6.0-2.2.7/deploy/deploy-crds.yaml
+
+Then deploy MySQL Operator for Kubernetes:
+
+    kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/9.6.0-2.2.7/deploy/deploy-operator.yaml
+
+Verify the operator is running by checking the deployment inside the mysql-operator namespace:
+
+    kubectl get deployment -n mysql-operator mysql-operator
+
+    NAME             READY   UP-TO-DATE   AVAILABLE   AGE
+    mysql-operator   1/1     1            1           1h
+
+
+# MySQL InnoDB Cluster Installation
+
+## Using kubectl
+
+For creating a MySQL InnoDB Cluster, first create a secret with credentials for a MySQL root user used to perform administrative tasks in the cluster. For example:
+
+    kubectl create secret generic mypwds \
+        --from-literal=rootUser=root \
+        --from-literal=rootHost=% \
+        --from-literal=rootPassword="sakila"
+
+Define your MySQL InnoDB Cluster, which references the secret. For example:
+
+    apiVersion: mysql.oracle.com/v2
+    kind: InnoDBCluster
+    metadata:
+      name: mycluster
+    spec:
+      secretName: mypwds
+      tlsUseSelfSigned: true
+      instances: 3
+      router:
+        instances: 1
+
+Assuming it's saved as mycluster.yaml, deploy it:
+
+    kubectl apply -f mycluster.yaml
+
+This sample creates an InnoDB Cluster with three MySQL Server instances and one MySQL Router instance. The process can be observed using:
+
+    kubectl get innodbcluster --watch
+
+    NAME          STATUS    ONLINE   INSTANCES   ROUTERS   AGE
+    mycluster     PENDING   0        3           1         2m6s
+    ...
+    mycluster     ONLINE    3        3           1         10s
+
+# Conectar al cluster
+
+
+    kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh
+
+en el prompt,
+
+    \connect root@mycluster-instances.mysql-cluster.svc.cluster.local
+
+> NOTA: el nombre del host es el del servicio del cluster (```mycluster-instances```) seguido del namespace (```mysql-cluster```) y finalmente por ```svc.cluster.local```.
+
+## PHP my admin
+
+Como php my admin tiene que trabajar con el cluster, no hace falta tener uno en cada wordpress. Solo hay una instancia y está aquí

+ 1 - 0
conecta.sh

@@ -0,0 +1 @@
+kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh

+ 11 - 0
mysql-innodb-cluster.yaml

@@ -0,0 +1,11 @@
+apiVersion: mysql.oracle.com/v2
+kind: InnoDBCluster
+metadata:
+  name: mycluster
+  namespace: mysql-cluster
+spec:
+  secretName: mypwds
+  tlsUseSelfSigned: true
+  instances: 1
+  router:
+    instances: 1

+ 9 - 0
mysql-secrets.yaml

@@ -0,0 +1,9 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: mysqlwp-pass
+  namespace: mysql-cluster
+data:
+  password: RHNhLTAyMTM=
+  db_user: cm9vdA==
+  db_passwd: RHNhLTAyMTM=

+ 57 - 0
php-deployment.yaml

@@ -0,0 +1,57 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: phpmyadmin-mysql-cluster
+  namespace: mysql-cluster
+  labels:
+    app: wordpress
+spec:
+  selector:
+    app: wordpress
+    tier: phpmyadmin
+  type: NodePort
+  ports:
+    - name: phpadmin
+      nodePort: 30089
+      port: 80
+      targetPort: phpmyadm
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: phpmyadmin-mysql-cluster
+  namespace: mysql-cluster
+  labels:
+    app: wordpress
+spec:
+  selector:
+    matchLabels:
+      app: wordpress
+      tier: phpmyadmin
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      labels:
+        app: wordpress
+        tier: phpmyadmin
+    spec:
+      containers:
+        - name: phpmyadmin
+          image: phpmyadmin
+          ports:
+            - containerPort: 80
+              name: phpmyadm
+          env:
+            - name: PMA_UPLOADDIR
+              value: /var/www/html/subidas
+            - name: PMA_HOST
+              # value: wordpress-mysql
+              value: mycluster-instances.mysql-cluster.svc.cluster.local
+            - name: PMA_PORT
+              value: "3306"
+            - name: MYSQL_ROOT_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: mysqlwp-pass
+                  key: password

+ 8 - 0
secreto.yaml

@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: mypwds
+data:
+  rootPassword: RHNhLTAyMTM=
+  rootUser: cm9vdA==
+  rootHost: JQ==