mysql-operator 尝试与研究

 

  • 安装指南
  •  先下载到本地
git clone https://github.com/kubernetes/charts.git
  •  安装helm

参考:

http://www.cnblogs.com/ericnie/p/8463127.html

  •  下载mysql-operator镜像
docker pull  iad.ocir.io/oracle/mysql-operator:0.1.0

 同时下载mysqlserver和agent,启动mysql实例需要

docker pull mysql/mysql-server:5.7.20-1.1.2

docker pull wcr.io/oracle/mysql-agent:0.1.0
  •  建立命名空间
kubectl create namespace mysql-operator
  • 创建mysql-operator

[root@k8s-master mysql-operator]# helm install --name my-release mysql-operator --set rbac.enabled=true
NAME: my-release
LAST DEPLOYED: Tue May 22 14:53:39 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ServiceAccount
NAME SECRETS AGE
mysql-operator 1 14m
mysql-agent 1 14m

==> v1beta1/ClusterRole
NAME AGE
mysql-operator 14m

==> v1beta1/ClusterRoleBinding
NAME AGE
mysql-operator 14m
mysql-agent 14m

==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
mysql-operator 1 1 1 1 14m

==> v1beta1/CustomResourceDefinition
NAME KIND
mysqlclusters.mysql.oracle.com CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlbackups.mysql.oracle.com CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlrestores.mysql.oracle.com CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlbackupschedules.mysql.oracle.com CustomResourceDefinition.v1beta1.apiextensions.k8s.io


NOTES:
Thanks for installing the MySQL Operator.

Check if the operator is running with

kubectl -n mysql-operator get po

验证下结果

[root@k8s-master mysql-operator]# kubectl get pods -n mysql-operator
NAME                             READY     STATUS    RESTARTS   AGE
mysql-operator-541631688-7937r   1/1       Running   0          52s

 获取crd

[root@k8s-master cluster]# kubectl get crd
NAME                                    KIND
domains.weblogic.oracle                 CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlbackups.mysql.oracle.com           CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlbackupschedules.mysql.oracle.com   CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlclusters.mysql.oracle.com          CustomResourceDefinition.v1beta1.apiextensions.k8s.io
mysqlrestores.mysql.oracle.com          CustomResourceDefinition.v1beta1.apiextensions.k8s.io

 

  • 集群建立

各种集群建立,详细可以参考

https://github.com/oracle/mysql-operator/blob/master/docs/user/clusters.md

这里列一个最简单的。

 

[root@k8s-master cluster]# cat cluster.yaml 
apiVersion: "mysql.oracle.com/v1"
kind: MySQLCluster
metadata:
  name: mysql

 

[root@k8s-master cluster]# kubectl create -f cluster.yaml 
mysqlcluster "mysql" created
[root@k8s-master cluster]# kubectl get mysqlclusters
NAME      KIND
mysql     MySQLCluster.v1.mysql.oracle.com

发现在当前的命名空间下生成了实例

[root@k8s-master cluster]# kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
busybox   1/1       Running   31         8d
mysql-0   2/2       Running   0          14m
tomcat    1/1       Running   7          7d
[root@k8s-master cluster]# kubectl logs mysql-0  -c mysql-agent
Starting mysql-agent version 0.1.0
ERROR: logging before flag.Parse: I0523 02:11:46.287788      18 flags.go:52] FLAG: --address="0.0.0.0"
ERROR: logging before flag.Parse: I0523 02:11:46.287883      18 flags.go:52] FLAG: --alsologtostderr="false"
ERROR: logging before flag.Parse: I0523 02:11:46.287893      18 flags.go:52] FLAG: --healthcheck-port="10512"
ERROR: logging before flag.Parse: I0523 02:11:46.287903      18 flags.go:52] FLAG: --hostname="mysql-0"
ERROR: logging before flag.Parse: I0523 02:11:46.287910      18 flags.go:52] FLAG: --log-backtrace-at=":0"
ERROR: logging before flag.Parse: I0523 02:11:46.287920      18 flags.go:52] FLAG: --log-dir=""
ERROR: logging before flag.Parse: I0523 02:11:46.287927      18 flags.go:52] FLAG: --log-flush-frequency="5s"
ERROR: logging before flag.Parse: I0523 02:11:46.287936      18 flags.go:52] FLAG: --logtostderr="true"
ERROR: logging before flag.Parse: I0523 02:11:46.287943      18 flags.go:52] FLAG: --min-resync-period="12h0m0s"
ERROR: logging before flag.Parse: I0523 02:11:46.287950      18 flags.go:52] FLAG: --mysql-cluster-name="mysql"
ERROR: logging before flag.Parse: I0523 02:11:46.287956      18 flags.go:52] FLAG: --namespace="default"
ERROR: logging before flag.Parse: I0523 02:11:46.287962      18 flags.go:52] FLAG: --stderrthreshold="2"
ERROR: logging before flag.Parse: I0523 02:11:46.287969      18 flags.go:52] FLAG: --v="4"
ERROR: logging before flag.Parse: I0523 02:11:46.287976      18 flags.go:52] FLAG: --vmodule=""
ERROR: logging before flag.Parse: I0523 02:11:46.817877      18 cluster_manager.go:105] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 02:11:56.941725      18 cluster_manager.go:105] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 02:12:06.993075      18 cluster_manager.go:105] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 02:12:17.415974      18 innodb_cluster.go:121] Clearing the MySQL binary logs
ERROR: logging before flag.Parse: I0523 02:12:18.086997      18 cluster_manager.go:280] Creating the cluster on the primary instance
ERROR: logging before flag.Parse: I0523 02:12:23.170507      18 cluster_manager.go:285] {
    "clusterName": "MySQLCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "mysql-0:3306",
        "status": "OK_NO_TOLERANCE",
        "statusText": "Cluster is NOT tolerant to any failures.",
        "topology": {
            "mysql-0:3306": {
                "address": "mysql-0:3306",
                "mode": "R/W",
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}
ERROR: logging before flag.Parse: I0523 02:12:23.170595      18 cluster_manager.go:137] MySQL instance is online
ERROR: logging before flag.Parse: I0523 02:12:23.345615      18 agent_controller.go:99] Creating event broadcaster
ERROR: logging before flag.Parse: I0523 02:12:23.532123      18 reflector.go:202] Starting reflector *v1.Pod (19h15m21.324440719s) from github.com/oracle/mysql-operator/vendor/k8s.io/client-go/informers/factory.go:86
ERROR: logging before flag.Parse: I0523 02:12:23.532225      18 reflector.go:240] Listing and watching *v1.Pod from github.com/oracle/mysql-operator/vendor/k8s.io/client-go/informers/factory.go:86
ERROR: logging before flag.Parse: I0523 02:12:23.553086      18 agent_controller.go:107] Creating event broadcaster
ERROR: logging before flag.Parse: I0523 02:12:23.553397      18 cluster_labeler.go:241] Starting the ClusterLabelerController
ERROR: logging before flag.Parse: I0523 02:12:23.553412      18 cluster_labeler.go:244] Waiting for ClusterLabelerController informer caches to sync
ERROR: logging before flag.Parse: I0523 02:12:23.553426      18 cache.go:30] Waiting for caches to sync for innodb-cluster-labeler controller
ERROR: logging before flag.Parse: I0523 02:12:23.555114      18 agent_controller.go:166] Starting AgentController
ERROR: logging before flag.Parse: I0523 02:12:23.555151      18 agent_controller.go:169] Waiting for caches to sync
ERROR: logging before flag.Parse: I0523 02:12:23.555171      18 cache.go:30] Waiting for caches to sync for operator-backup-controller controller
ERROR: logging before flag.Parse: I0523 02:12:23.555407      18 agent_controller.go:175] Starting AgentController
ERROR: logging before flag.Parse: I0523 02:12:23.555419      18 agent_controller.go:178] Waiting for caches to sync
ERROR: logging before flag.Parse: I0523 02:12:23.555427      18 cache.go:30] Waiting for caches to sync for operator-restore-controller controller
ERROR: logging before flag.Parse: I0523 02:12:23.556287      18 reflector.go:202] Starting reflector *v1.MySQLBackup (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:23.556320      18 reflector.go:240] Listing and watching *v1.MySQLBackup from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:23.557559      18 reflector.go:202] Starting reflector *v1.MySQLRestore (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:23.562579      18 reflector.go:240] Listing and watching *v1.MySQLRestore from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:23.564784      18 reflector.go:202] Starting reflector *v1.MySQLCluster (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:23.564827      18 reflector.go:240] Listing and watching *v1.MySQLCluster from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:72
ERROR: logging before flag.Parse: I0523 02:12:24.135073      18 cluster_manager.go:137] MySQL instance is online
ERROR: logging before flag.Parse: I0523 02:12:24.153865      18 shared_informer.go:122] caches populated
ERROR: logging before flag.Parse: I0523 02:12:24.153925      18 cache.go:37] Caches are synced for innodb-cluster-labeler controller
ERROR: logging before flag.Parse: I0523 02:12:24.153946      18 cluster_labeler.go:249] Starting ClusterLabelerController controller worker
ERROR: logging before flag.Parse: I0523 02:12:24.153965      18 cluster_labeler.go:252] Started ClusterLabelerController controller worker
ERROR: logging before flag.Parse: I0523 02:12:24.154389      18 cluster_labeler.go:152] Labeling default/mysql-0 as primary
ERROR: logging before flag.Parse: I0523 02:12:24.173303      18 shared_informer.go:122] caches populated
ERROR: logging before flag.Parse: I0523 02:12:24.173358      18 cache.go:37] Caches are synced for operator-restore-controller controller
ERROR: logging before flag.Parse: I0523 02:12:24.173386      18 agent_controller.go:186] Caches are synced
ERROR: logging before flag.Parse: I0523 02:12:24.174961      18 patch.go:95] Patching Pod mysql-0/default: {"metadata":{"labels":{"v1.mysql.oracle.com/role":"primary"}}}
ERROR: logging before flag.Parse: I0523 02:12:24.177780      18 shared_informer.go:122] caches populated
ERROR: logging before flag.Parse: I0523 02:12:24.177837      18 cache.go:37] Caches are synced for operator-backup-controller controller
ERROR: logging before flag.Parse: I0523 02:12:24.177859      18 agent_controller.go:176] Caches are synced
ERROR: logging before flag.Parse: I0523 02:12:39.439539      18 cluster_manager.go:137] MySQL instance is online
ERROR: logging before flag.Parse: I0523 02:12:54.769749      18 cluster_manager.go:137] MySQL instance is online
ERROR: logging before flag.Parse: I0523 02:13:10.081533      18 cluster_manager.go:137] MySQL instance is online
ERROR: logging before flag.Parse: I0523 02:13:25.442784      18 cluster_manager.go:137] MySQL instance is online
[root@k8s-master cluster]# kubectl logs mysql-0  -c mysql
++ grep '^search' /etc/resolv.conf
+ search='search default.svc.cluster.local. svc.cluster.local. cluster.local.'
+ echo 'search default.svc.cluster.local. svc.cluster.local. cluster.local. mysql.default.svc.cluster.local'
++ cat /etc/hostname
++ grep -o '[^-]*$'
+ index=0
++ expr 1000 + 0
+ /entrypoint.sh --server_id=1000 --user=mysql --datadir=/var/lib/mysql --log-error=/var/lib/mysql/mysqld.err --default-storage-engine=innodb --default-tmp-storage-engine=innodb --internal-tmp-disk-storage-engine=innodb --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_520_ci --core-file --default-password-lifetime=0 --default-time-zone=SYSTEM --explicit-defaults-for-timestamp=ON --performance-schema-consumer-events-transactions-current=ON --performance-schema-consumer-events-transactions-history=ON --innodb-buffer-pool-size=128M --innodb-buffer-pool-instances=4 --innodb-autoinc-lock-mode=2 --innodb-flush-method=O_DIRECT_NO_FSYNC --innodb-open-files=128 --innodb-log-buffer-size=4M --innodb-monitor-enable=% --innodb-print-all-deadlocks=ON --innodb-undo-log-truncate=ON --innodb-undo-tablespaces=2 --innodb-undo-logs=2 --binlog_checksum=NONE --gtid_mode=ON --enforce_gtid_consistency=ON --log_bin --binlog-format=ROW --log-slave-updates=ON --master-info-repository=TABLE --relay-log-info-repository=TABLE --slave-preserve-commit-order=ON --disabled_storage_engines=MyISAM,BLACKHOLE,FEDERATED,ARCHIVE --transaction-isolation=READ-COMMITTED --transaction-write-set-extraction=XXHASH64 --loose-group-replication-ip-whitelist=0.0.0.0/0
[Entrypoint] MySQL Docker Image 5.7.20-1.1.2
[Entrypoint] Initializing database
[Entrypoint] Database initialized
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.

[Entrypoint] ignoring /docker-entrypoint-initdb.d/*

[Entrypoint] Server shut down

[Entrypoint] MySQL init process done. Ready for start up.

[Entrypoint] Starting MySQL 5.7.20-1.1.2

 describe下新建的集群

[root@k8s-master cluster]# kubectl describe mysqlclusters mysql
Name:        mysql
Namespace:    default
Labels:        v1.mysql.oracle.com/cluster=mysql
        v1.mysql.oracle.com/version=0.1.0
Annotations:    
API Version:    mysql.oracle.com/v1
Kind:        MySQLCluster
Metadata:
  Cluster Name:        
  Creation Timestamp:    2018-05-22T06:50:42Z
  Generation:        0
  Resource Version:    611750
  Self Link:        /apis/mysql.oracle.com/v1/namespaces/default/mysqlclusters/mysql
  UID:            71c8a94e-5d8c-11e8-aaa7-080027e2ae0a
Spec:
  Replicas:    1
  Version:    5.7.20-1.1.2
Status:
  Errors:    
  Metadata:
    Creation Timestamp:    
  Phase:        
Events:            

 

研究继续中....

转载于:https://www.cnblogs.com/ericnie/p/9072230.html

你可能感兴趣的:(mysql-operator 尝试与研究)