U1.58 Ubuntu Quick Start (QS): Kubernetes MySql InnoDB Cluster on premises - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Reading

We start with

Oracle MYSQL Operator

Installing the MYSQL Operator using kubectl

  • for u2004s01
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml

yury@u2004s01:~$ kubectl get deployment -n mysql-operator mysql-operator
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
mysql-operator   1/1     1            1           114s

Setting Up a MySQL InnoDB Cluster

kubectl create secret generic mypwds \
        --from-literal=rootUser=root \
        --from-literal=rootHost=% \
        --from-literal=rootPassword="root"
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/samples/sample-cluster.yaml

yury@u2004s01:~$ kubectl get pods -n default -o wide
NAME          READY   STATUS    RESTARTS   AGE     IP             NODE       NOMINATED NODE   READINESS GATES
mycluster-0   2/2     Running   0          6m23s   10.32.27.195   u2004s02   <none>           1/2

yury@u2004s01:~$ kubectl get innodbcluster --watch
NAME        STATUS         ONLINE   INSTANCES   ROUTERS   AGE
mycluster   INITIALIZING   0        3           1         104m

yury@u2004s01:~$ kubectl get innodbcluster --watch
NAME        STATUS         ONLINE   INSTANCES   ROUTERS   AGE
mycluster   INITIALIZING   0        3           1         142m
  • mycluster has STATUS=INITIALIZING after 142m.
  • to delete the cluster
    • for u2004s01
kubectl delete -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/samples/sample-cluster.yaml

Modifying cluster yaml

  • read the article Chapter 2 MySQL Operator Properties
    • they wrote:
      • edition
        • MySQL Server Edition; either commercial or community.
        • Type:: string
  • we add edition: community
    • for u2004s01
wget https://raw.githubusercontent.com/mysql/mysql-operator/trunk/samples/sample-cluster.yaml
nano sample-cluster.yaml 
new version of sample-cluster.yaml
apiVersion: mysql.oracle.com/v2alpha1
kind: InnoDBCluster
metadata:
  name: mycluster
spec:
  secretName: mypwds
  edition: community
  instances: 3
  router:
    instances: 1
  • create the cluster
    • for u2004s01
yury@u2004s01:~$ kubectl apply -f sample-cluster.yaml
The InnoDBCluster "mycluster" is invalid: spec.edition: Invalid value: "community": spec.edition in body should match '^(commercial|enterprise)$'

Oracle MYSQL Operator Summary

  • they wrote: The MySQL Operator for Kubernetes currently is in a preview state. DO NOT USE IN PRODUCTION.
  • We believe that the current version of Oracle MYSQL Operator only works under Oracle Container Engine for Kubernetes (OKE).
    • The version we had is equal to 8.0.26-2.0.2
show details
yury@u2004s01:~$ kubectl describe deployment/mysql-operator -n mysql-operator
Name:                   mysql-operator
Namespace:              mysql-operator
CreationTimestamp:      Wed, 19 Jan 2022 09:44:44 +0000
Labels:                 app.kubernetes.io/component=database
                        app.kubernetes.io/created-by=mysql-operator
                        app.kubernetes.io/instance=mysql-operator
                        app.kubernetes.io/managed-by=mysql-operator
                        app.kubernetes.io/name=mysql-operator
                        app.kubernetes.io/version=8.0.26-2.0.2
                        version=1.0
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               name=mysql-operator
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:           name=mysql-operator
  Service Account:  mysql-operator-sa
  Containers:
   mysql-operator:
    Image:      mysql/mysql-operator:8.0.26-2.0.2
    Port:       <none>
    Host Port:  <none>
    Args:
      mysqlsh
      --log-level=@INFO
      --pym
      mysqloperator
      operator
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   mysql-operator-55795bdb5c (1/1 replicas created)
Events:          <none>

MOCO MYSQL Operator

Installing MOCO MYSQL Operator

Installing cert-manager
curl -fsLO https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml
kubectl apply -f cert-manager.yaml
Installing moco operator
  • for u2004s01
curl -fsLO https://github.com/cybozu-go/moco/releases/latest/download/moco.yaml
Installing kubectl-moco
  • Install krew
    • for u2004s01
(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
)

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
  • Installing kubectl-moco using Krew
    • for u2004s01
kubectl krew update
kubectl krew install moco
  • Test kubectl-moco
yury@u2004s01:~$ kubectl moco
the utility command for MOCO.

Usage:
  kubectl-moco [command]

Available Commands:
  credential  Fetch the credential of a specified user
  help        Help about any command
...

Installing MYSQL Cluster with MOCO

First attempt
  • for u2004s01
kubectl apply -f- <<EOF
apiVersion: moco.cybozu.com/v1beta2
kind: MySQLCluster
metadata:
  namespace: default
  name: test
spec:
  # replicas is the number of mysqld Pods.  The default is 1.
  replicas: 3
  podTemplate:
    spec:
      # Make the data directory writable. If moco-init fails with "Permission denied", uncomment the following settings.
      # securityContext:
      #   fsGroup: 10000
      #   fsGroupChangePolicy: "OnRootMismatch"  # available since k8s 1.20
      # affinity:
      #  podAntiAffinity:
      #    requiredDuringSchedulingIgnoredDuringExecution:
      #    - labelSelector:
      #        matchExpressions:
      #        - key: app.kubernetes.io/name
      #          operator: In
      #          values:
      #          - mysql
      #        - key: app.kubernetes.io/instance
      #          operator: In
      #          values:
      #          - test
      #      topologyKey: "kubernetes.io/hostname"
      containers:
      # At least a container named "mysqld" must be defined.
      - name: mysqld
        image: quay.io/cybozu/mysql:8.0.27
        # By limiting CPU and memory, Pods will have Guaranteed QoS class.
        # requests can be omitted; it will be set to the same value as limits.
        resources:
          limits:
            cpu: "2"
            memory: "3Gi"
  volumeClaimTemplates:
  # At least a PVC named "mysql-data" must be defined.
  - metadata:
      name: mysql-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 3Gi
EOF
  • Here is a responce
error: unable to recognize "STDIN": no matches for kind "MySQLCluster" in version "moco.cybozu.com/v1beta2"
another attempt
  • for u2004s01
kubectl apply -f- <<EOF
apiVersion: moco.cybozu.com/v1beta1
kind: MySQLCluster
metadata:
  namespace: default
  name: test
spec:
  replicas: 3
  podTemplate:
    spec:
      containers:
      - name: mysqld
        image: quay.io/cybozu/mysql:8.0.27
  volumeClaimTemplates:
  - metadata:
      name: mysql-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
EOF
  • Here is a responce
mysqlcluster.moco.cybozu.com/test created

yury@u2004s01:~$ kubectl get pods -n default -o wide
NAME          READY   STATUS    RESTARTS   AGE     IP              NODE       NOMINATED NODE   READINESS GATES
moco-test-0   3/3     Running   0          9m28s   10.32.105.6     u2004s03   <none>           <none>
moco-test-1   3/3     Running   0          9m28s   10.32.121.133   u2004s04   <none>           <none>
moco-test-2   3/3     Running   0          9m28s   10.32.27.204    u2004s02   <none>           <none>

Test MOCO

  • Create Databse
    • for u2004s01
yury@u2004s01:~$ kubectl moco -n default mysql -it -u moco-writable test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 261
Server version: 8.0.27 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE MyTestDb;
Query OK, 1 row affected (0.28 sec)

mysql> quit
Bye
  • Show Databses
    • for u2004s01
yury@u2004s01:~$ kubectl moco -n default mysql -it --index 1 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 254
Server version: 8.0.27 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| MyTestDb           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.05 sec)

mysql> quit
Bye


yury@u2004s01:~$ kubectl moco -n default mysql -it --index 3 test
Error: index should be smaller than replicas
⚠️ **GitHub.com Fallback** ⚠️