- 安装指南
- 先下载到本地
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.
同时下载mysqlserver和agent,启动mysql实例需要
docker pull mysql/mysql-server:5.7.-1.1. docker pull wcr.io/oracle/mysql-agent:0.1.
- 建立命名空间
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--7937r / Running 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 / Running 8d
mysql- / Running 14m
tomcat / Running 7d
[root@k8s-master cluster]# kubectl logs mysql- -c mysql-agent
Starting mysql-agent version 0.1.
ERROR: logging before flag.Parse: I0523 ::46.287788 flags.go:] FLAG: --address="0.0.0.0"
ERROR: logging before flag.Parse: I0523 ::46.287883 flags.go:] FLAG: --alsologtostderr="false"
ERROR: logging before flag.Parse: I0523 ::46.287893 flags.go:] FLAG: --healthcheck-port=""
ERROR: logging before flag.Parse: I0523 ::46.287903 flags.go:] FLAG: --hostname="mysql-0"
ERROR: logging before flag.Parse: I0523 ::46.287910 flags.go:] FLAG: --log-backtrace-at=":0"
ERROR: logging before flag.Parse: I0523 ::46.287920 flags.go:] FLAG: --log-dir=""
ERROR: logging before flag.Parse: I0523 ::46.287927 flags.go:] FLAG: --log-flush-frequency="5s"
ERROR: logging before flag.Parse: I0523 ::46.287936 flags.go:] FLAG: --logtostderr="true"
ERROR: logging before flag.Parse: I0523 ::46.287943 flags.go:] FLAG: --min-resync-period="12h0m0s"
ERROR: logging before flag.Parse: I0523 ::46.287950 flags.go:] FLAG: --mysql-cluster-name="mysql"
ERROR: logging before flag.Parse: I0523 ::46.287956 flags.go:] FLAG: --namespace="default"
ERROR: logging before flag.Parse: I0523 ::46.287962 flags.go:] FLAG: --stderrthreshold=""
ERROR: logging before flag.Parse: I0523 ::46.287969 flags.go:] FLAG: --v=""
ERROR: logging before flag.Parse: I0523 ::46.287976 flags.go:] FLAG: --vmodule=""
ERROR: logging before flag.Parse: I0523 ::46.817877 cluster_manager.go:] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 ::56.941725 cluster_manager.go:] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 ::06.993075 cluster_manager.go:] Database not yet running. Waiting...
ERROR: logging before flag.Parse: I0523 ::17.415974 innodb_cluster.go:] Clearing the MySQL binary logs
ERROR: logging before flag.Parse: I0523 ::18.086997 cluster_manager.go:] Creating the cluster on the primary instance
ERROR: logging before flag.Parse: I0523 ::23.170507 cluster_manager.go:] {
"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 ::23.170595 cluster_manager.go:] MySQL instance is online
ERROR: logging before flag.Parse: I0523 ::23.345615 agent_controller.go:] Creating event broadcaster
ERROR: logging before flag.Parse: I0523 ::23.532123 reflector.go:] Starting reflector *v1.Pod (19h15m21.324440719s) from github.com/oracle/mysql-operator/vendor/k8s.io/client-go/informers/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.532225 reflector.go:] Listing and watching *v1.Pod from github.com/oracle/mysql-operator/vendor/k8s.io/client-go/informers/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.553086 agent_controller.go:] Creating event broadcaster
ERROR: logging before flag.Parse: I0523 ::23.553397 cluster_labeler.go:] Starting the ClusterLabelerController
ERROR: logging before flag.Parse: I0523 ::23.553412 cluster_labeler.go:] Waiting for ClusterLabelerController informer caches to sync
ERROR: logging before flag.Parse: I0523 ::23.553426 cache.go:] Waiting for caches to sync for innodb-cluster-labeler controller
ERROR: logging before flag.Parse: I0523 ::23.555114 agent_controller.go:] Starting AgentController
ERROR: logging before flag.Parse: I0523 ::23.555151 agent_controller.go:] Waiting for caches to sync
ERROR: logging before flag.Parse: I0523 ::23.555171 cache.go:] Waiting for caches to sync for operator-backup-controller controller
ERROR: logging before flag.Parse: I0523 ::23.555407 agent_controller.go:] Starting AgentController
ERROR: logging before flag.Parse: I0523 ::23.555419 agent_controller.go:] Waiting for caches to sync
ERROR: logging before flag.Parse: I0523 ::23.555427 cache.go:] Waiting for caches to sync for operator-restore-controller controller
ERROR: logging before flag.Parse: I0523 ::23.556287 reflector.go:] Starting reflector *v1.MySQLBackup (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.556320 reflector.go:] Listing and watching *v1.MySQLBackup from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.557559 reflector.go:] Starting reflector *v1.MySQLRestore (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.562579 reflector.go:] Listing and watching *v1.MySQLRestore from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.564784 reflector.go:] Starting reflector *v1.MySQLCluster (0s) from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::23.564827 reflector.go:] Listing and watching *v1.MySQLCluster from github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/factory.go:
ERROR: logging before flag.Parse: I0523 ::24.135073 cluster_manager.go:] MySQL instance is online
ERROR: logging before flag.Parse: I0523 ::24.153865 shared_informer.go:] caches populated
ERROR: logging before flag.Parse: I0523 ::24.153925 cache.go:] Caches are synced for innodb-cluster-labeler controller
ERROR: logging before flag.Parse: I0523 ::24.153946 cluster_labeler.go:] Starting ClusterLabelerController controller worker
ERROR: logging before flag.Parse: I0523 ::24.153965 cluster_labeler.go:] Started ClusterLabelerController controller worker
ERROR: logging before flag.Parse: I0523 ::24.154389 cluster_labeler.go:] Labeling default/mysql- as primary
ERROR: logging before flag.Parse: I0523 ::24.173303 shared_informer.go:] caches populated
ERROR: logging before flag.Parse: I0523 ::24.173358 cache.go:] Caches are synced for operator-restore-controller controller
ERROR: logging before flag.Parse: I0523 ::24.173386 agent_controller.go:] Caches are synced
ERROR: logging before flag.Parse: I0523 ::24.174961 patch.go:] Patching Pod mysql-/default: {"metadata":{"labels":{"v1.mysql.oracle.com/role":"primary"}}}
ERROR: logging before flag.Parse: I0523 ::24.177780 shared_informer.go:] caches populated
ERROR: logging before flag.Parse: I0523 ::24.177837 cache.go:] Caches are synced for operator-backup-controller controller
ERROR: logging before flag.Parse: I0523 ::24.177859 agent_controller.go:] Caches are synced
ERROR: logging before flag.Parse: I0523 ::39.439539 cluster_manager.go:] MySQL instance is online
ERROR: logging before flag.Parse: I0523 ::54.769749 cluster_manager.go:] MySQL instance is online
ERROR: logging before flag.Parse: I0523 ::10.081533 cluster_manager.go:] MySQL instance is online
ERROR: logging before flag.Parse: I0523 ::25.442784 cluster_manager.go:] MySQL instance is online
[root@k8s-master cluster]# kubectl logs mysql- -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=
++ expr +
+ /entrypoint.sh --server_id= --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= --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= --innodb-autoinc-lock-mode= --innodb-flush-method=O_DIRECT_NO_FSYNC --innodb-open-files= --innodb-log-buffer-size=4M --innodb-monitor-enable=% --innodb-print-all-deadlocks=ON --innodb-undo-log-truncate=ON --innodb-undo-tablespaces= --innodb-undo-logs= --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/
[Entrypoint] MySQL Docker Image 5.7.-1.1.
[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.
Annotations: <none>
API Version: mysql.oracle.com/v1
Kind: MySQLCluster
Metadata:
Cluster Name:
Creation Timestamp: --22T06::42Z
Generation:
Resource Version:
Self Link: /apis/mysql.oracle.com/v1/namespaces/default/mysqlclusters/mysql
UID: 71c8a94e-5d8c-11e8-aaa7-080027e2ae0a
Spec:
Replicas:
Version: 5.7.-1.1.
Status:
Errors: <nil>
Metadata:
Creation Timestamp: <nil>
Phase:
Events: <none>
研究继续中....