需要持久化储存数据的,建立有状态服务。
无状态服务是不会持久化的,重启就归零
KubeSphere 创建自建应用后,创建有状态服务,但是自己应用的有状态服务不能外放端口,需要在服务哪里删除pod,在创建负载指定相关的有状态服务,就可以外放端口了
安装mysql8
添加初始化密码参数
MYSQL_ROOT_PASSWORD
数据库要指定持久化卷,不然重启pod数据就会归零
数据库将的cnf配置映射出来
my.cnf
[mysqld]
port = 3306
#basedir = /var/lib/mysql
datadir = /var/lib/mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
#secure-file-priv= NULL
secure-file-priv= /var/lib/mysql-files
lower_case_table_names=1
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
max_connections=1500
max_connect_errors=100
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
wait_timeout = 1800
interactive_timeout = 1800
#lock_wait_timeout = 3600
#tmp_table_size = 64M
#max_heap_table_size = 64M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
#!includedir /etc/mysql/conf.d/
/var/lib/mysql
/etc/mysql/my.cnf
my.cnf
启动效果