我在 Kubernetes 集群上部署 WordPress + MySQL 应用程序时遇到问题。
当使用 HorizontalPodAutoscaler
自动缩放我的 wordpress
和 wordpress-mysql
部署时,它适用于 wordpress
一个,但不是 wordpress-mysql
一个。
实际上,当创建多个 MySQL pod 时,有些会进入 CrashLoopBackOff
状态:
$ kubectl get all -n wordpress
NAME READY STATUS RESTARTS AGE
po/wordpress-3874566264-7031k 1/1 Running 0 16h
po/wordpress-mysql-898811424-2bdnn 0/1 CrashLoopBackOff 6 16h
po/wordpress-mysql-898811424-dxj92 1/1 Running 146 16h
po/wordpress-mysql-898811424-vs29j 0/1 CrashLoopBackOff 148 16h
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/wordpress 10.254.121.190 10.0.0.13 80:30003/TCP 16h
svc/wordpress-mysql None <none> 3306/TCP 16h
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
hpa/wordpress Deployment/wordpress 28% / 80%, 0% / 80% 1 10 1 16h
hpa/wordpress-mysql Deployment/wordpress-mysql 90% / 80%, 0% / 80% 1 10 3 16h
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/wordpress 1 1 1 1 16h
deploy/wordpress-mysql 3 3 3 1 16h
NAME DESIRED CURRENT READY AGE
rs/wordpress-3874566264 1 1 1 16h
rs/wordpress-mysql-898811424 3 3 1 16h
当我查看他们的日志时,我明白了:
$ kubectl logs -p wordpress-mysql-898811424-2bdnn -n wordpress
2018-09-12 08:04:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-12 08:04:12 0 [Note] mysqld (mysqld 5.6.41) starting as process 436 ...
2018-09-12 08:04:12 436 [Note] Plugin 'FEDERATED' is disabled.
2018-09-12 08:04:12 436 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-09-12 08:04:12 436 [Note] InnoDB: The InnoDB memory heap is disabled
2018-09-12 08:04:12 436 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-09-12 08:04:12 436 [Note] InnoDB: Memory barrier is not used
2018-09-12 08:04:12 436 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-09-12 08:04:12 436 [Note] InnoDB: Using Linux native AIO
2018-09-12 08:04:12 436 [Note] InnoDB: Using CPU crc32 instructions
2018-09-12 08:04:12 436 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-09-12 08:04:12 436 [Note] InnoDB: Completed initialization of buffer pool
2018-09-12 08:04:12 436 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
2018-09-12 08:04:12 436 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2018-09-12 08:04:12 436 [Note] InnoDB: Retrying to lock the first data file
2018-09-12 08:04:13 436 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
2018-09-12 08:04:13 436 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2018-09-12 08:04:14 436 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
2018-09-12 08:04:14 436 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2018-09-12 08:04:15 436 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
[...]
2018-09-12 08:05:51 436 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2018-09-12 08:05:52 436 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
2018-09-12 08:05:52 436 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2018-09-12 08:05:52 436 [Note] InnoDB: Unable to open the first data file
2018-09-12 08:05:52 7f57a329f5c0 InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
2018-09-12 08:05:52 436 [ERROR] InnoDB: Can't open './ibdata1'
2018-09-12 08:05:52 436 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2018-09-12 08:05:52 436 [ERROR] Plugin 'InnoDB' init function returned error.
2018-09-12 08:05:52 436 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-09-12 08:05:52 436 [ERROR] Unknown/unsupported storage engine: InnoDB
2018-09-12 08:05:52 436 [ERROR] Aborting
2018-09-12 08:05:52 436 [Note] Binlog end
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'partition'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_METRICS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMPMEM'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_CMP'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_LOCKS'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'INNODB_TRX'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'BLACKHOLE'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'ARCHIVE'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'MRG_MYISAM'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'MyISAM'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'MEMORY'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'CSV'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'sha256_password'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'mysql_old_password'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'mysql_native_password'
2018-09-12 08:05:52 436 [Note] Shutting down plugin 'binlog'
2018-09-12 08:05:52 436 [Note] mysqld: Shutdown complete
所以这可能是很正常的,因为每个 MySQL pod 都试图同时访问 ./ibdata1
,但是我的问题是:是否真的可以有多个 MySQL pod 共享相同的数据?如果答案是肯定的,那么我应该如何避免这些恼人的错误?
如果您需要其他信息,请告诉我,我会编辑我的帖子。
预先感谢您的帮助!
最佳答案
So it might be quite normal because each MySQL pod is trying to access ./ibdata1 at the same time
是的,如果您尝试这样做(您没有提供 list ),那么这就是您处于 CrashLoopBackOff 状态的原因。首次启动的实例将锁定它,所有后续实例都将失败。
... trying to access ./ibdata1 at the same time ... is it really possible to have several MySQL pods sharing the same data?
如果我们在两个独立的 mysql 实例上讨论相同的数据文件夹(完全相同的持久卷,或主机路径或 nfs 共享......) - 那么不,不是真的,并且出于多种原因不可取。
如果您需要多个 mysql 实例(进程、容器或 pod)共享相同的数据(而不是数据文件夹!),您需要使用复制(使用只读副本或其他...),其中每个实例都有自己的数据文件夹结构,但它们以某种方式在它们之间同步数据。这是 a MySQL single-master topology with multiple slaves running asynchronous replication 的一个例子关于kubernetes官方文档。请注意,这不是生产设置,也不是 HA 设置,而只是一个简单复制场景的说明,以供您了解。
现在,一些简单的问题:你确定你不能处理服务于多个 wordpress 实例的单个 mysql 实例的负载吗?您是否正在尝试进行 HA 设置?因为回答这些问题中的每一个都需要与“从 1 开始增加 pod 数量”不同的方法和架构决策。
关于mysql - 具有 CrashLoopBackOff 状态的多个 MySQL Kubernetes pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52290766/