部署MySQL、Nacos、Redis
1. 安装mysql
在安装mysql的适合用到了若依的初始化数据,所以需要使用docker compose build ruoyi-mysql 建立镜像。
使用加载镜像:minikube image load mysql镜像
我在部署Mysql时没有用到k8s的存储,此处可以进行自行修改。下面是yaml文件内容:
apiVersion: apps/v1
kind: Deployment # 副本控制器RC
metadata:
name: mysql #RC 的名称,全局唯一
namespace: default # 默认空间
spec:
replicas: 1 #Pod 副本的期待数量
selector:
matchLabels:
app: mysql # 符合目标的Pod拥有此标签
template: # 根据此模版创建Pod的副本
metadata:
labels:
app: mysql # Pod副本拥有的标签,对应RC的Selector
spec:
containers: # Pod的内容的定义部分
- name: mysql # 容器的名称
image: ry-mysql # 容器对应的Docker Image
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306 # 容器应用监听的端口号
env:
- name: MYSQL_ROOT_PASSWORD # 设置mysql的初始化密码
value: "password" # 设置mysql的初始化密码
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
volumes:
- name: mysql-data
hostPath:
path: /var/lib/mysql
---
apiVersion: v1
kind: Service # 表明是Kubernetes Service
metadata:
name: mysql # Service 的全局唯一名称
spec:
type: NodePort
selector:
app: mysql
ports: # Service 提供服务的端口
- port: 3306 # Service 对应的Pod拥有这里定义的标签
targetPort: 3306
2. 安装Nacos
此处安装需要注意mysql的连接地址和SPRING_DATASOURCE_PLATFORM此参数一定要配置,要不然莫名其妙的使用内嵌数据库,不知道为啥在docker compose和单独部署没有问题,在minikube中部署一定要此参数,此变量折腾了我2天.....
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm-cpf1
data:
application.properties: |
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
server.tomcat.accesslog.max-days=30
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
# default current work dir
server.tomcat.basedir=file:.
#*************** Config Module Related Configurations ***************#
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
#spring.datasource.platform=mysql
spring.sql.init.platform=${SPRING_DATASOURCE_PLATFORM:mysql}
db.num=${MYSQL_DATABASE_NUM:1}
db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user.0=${MYSQL_SERVICE_USER}
db.password.0=${MYSQL_SERVICE_PASSWORD}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm-cpf
data:
application.properties: |
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
server.tomcat.accesslog.max-days=30
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
# default current work dir
server.tomcat.basedir=file:.
#*************** Config Module Related Configurations ***************#
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
#spring.datasource.platform=mysql
spring.sql.init.platform=${SPRING_DATASOURCE_PLATFORM:}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=${MYSQL_DATABASE_NUM:1}
db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user.0=${MYSQL_SERVICE_USER}
db.password.0=${MYSQL_SERVICE_PASSWORD}
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
nacos.core.auth.plugin.nacos.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless-cpf
labels:
app: nacos-headless-cpf
spec:
type: NodePort
# clusterIP: None
ports:
- port: 8848
name: server
targetPort: 8848
# nodePort: 30000
- port: 9848
name: client-rpc
targetPort: 9848
- port: 9849
name: raft-rpc
targetPort: 9849
## 兼容1.4.x版本的选举端口
- port: 7848
name: old-raft-rpc
targetPort: 7848
selector:
app: nacos-cpf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "mysql"
mysql.db.name: "ry-config"
mysql.port: "3306"
mysql.user: "root"
mysql.password: "password"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos-cpf
spec:
serviceName: nacos-headless
replicas: 1
template:
metadata:
labels:
app: nacos-cpf
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
volumes:
- name: application-conf
configMap:
name: nacos-cm-cpf
containers:
- name: k8snacos-cpf
imagePullPolicy: IfNotPresent
image: nacos/nacos-server:latest
resources:
requests:
memory: "1Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client
- containerPort: 9848
name: client-rpc
- containerPort: 9849
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
env:
- name: MODE
value: "standalone"
- name: SPRING_DATASOURCE_PLATFORM #此参数必须配置,要不然出现莫名其妙的问题而不能启动
value: "mysql"
# - name: NACOS_REPLICAS
# value: "1"
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.name
- name: MYSQL_SERVICE_PORT
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.port
- name: MYSQL_SERVICE_USER
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.user
- name: MYSQL_SERVICE_PASSWORD
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
# - name: NACOS_SERVERS
# value: "nacos-0.nacos-headless.default.svc.cluster.local:8848 nacos-1.nacos-headless.default.svc.cluster.local:8848 nacos-2.nacos-headless.default.svc.cluster.local:8848"
volumeMounts:
- name: application-conf
mountPath: /home/nacos/conf/application.properties
readOnly: true
subPath: application.properties
# - name: application-conf
# mountPath: /home/nacos/conf/nacos-logback.xml
# readOnly: true
# subPath: nacos-logback.xml
selector:
matchLabels:
app: nacos-cpf
3. 安装Redis
安装redis没有遇到啥坑,直接安装就可以。
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
imagePullPolicy: IfNotPresent
# command: ["redis-server","/etc/redis/redis.conf"]
ports:
- containerPort: 6379
---
kind: Service
apiVersion: v1
metadata:
name: redis
spec:
type: ClusterIP
selector:
app: redis
ports:
- port: 6379
代码地址:https://gitee.com/cpf84/myminikube 欢迎star