Docker mysql 把数据存储在本地目录,很简单,只需要映射本地目录到容器即可
参考mysql官方链接
docker run -d \
-e MYSQL_ROOT_PASSWORD=123456 \
--name mysql \
-v /lettin/lettin-pro/service/mysql/data:/var/lib/mysql \
-p 3306:3306 \
--restart=always \
mysql:5.6
K8S 部署mysql单机
apiVersion : apps/v1
kind : Deployment
metadata :
annotations :
deployment.kubernetes.io/revision : "1"
creationTimestamp : "2024-07-15T09:17:14Z"
generation : 1
labels :
app : mysql
k8s.kuboard.cn/name : mysql
name : mysql
resourceVersion : "2791160"
uid : 8dcddef8- d95e- 4832- 900d- 5930aca8350f
spec :
progressDeadlineSeconds : 600
replicas : 1
revisionHistoryLimit : 10
selector :
matchLabels :
app : mysql
k8s.kuboard.cn/name : mysql
strategy :
rollingUpdate :
maxSurge : 25%
maxUnavailable : 25%
type : RollingUpdate
template :
metadata :
creationTimestamp : null
labels :
app : mysql
k8s.kuboard.cn/name : mysql
spec :
containers :
- env :
- name : MYSQL_ROOT_PASSWORD
value : "123456"
image : mysql: 8.0
imagePullPolicy : IfNotPresent
name : mysql
ports :
- containerPort : 3306
hostPort : 3306
name : port
protocol : TCP
readinessProbe :
failureThreshold : 5
initialDelaySeconds : 30
periodSeconds : 10
successThreshold : 1
tcpSocket :
port : 3306
timeoutSeconds : 1
resources : { }
terminationMessagePath : /dev/termination- log
terminationMessagePolicy : File
volumeMounts :
- mountPath : /var/lib/mysql
name : volume- 2hkxz
dnsPolicy : ClusterFirst
restartPolicy : Always
schedulerName : default- scheduler
securityContext : { }
serviceAccount : default
serviceAccountName : default
terminationGracePeriodSeconds : 30
volumes :
- hostPath :
path : /usr/local/mysql/data
type : DirectoryOrCreate
name : volume- 2hkxz
status :
availableReplicas : 1
conditions :
- lastTransitionTime : "2024-07-15T09:17:14Z"
lastUpdateTime : "2024-07-15T09:17:54Z"
message : ReplicaSet "mysql- 6c4497b6d9" has successfully progressed.
reason : NewReplicaSetAvailable
status : "True"
type : Progressing
- lastTransitionTime : "2024-07-15T09:23:25Z"
lastUpdateTime : "2024-07-15T09:23:25Z"
message : Deployment has minimum availability.
reason : MinimumReplicasAvailable
status : "True"
type : Available
observedGeneration : 1
readyReplicas : 1
replicas : 1
updatedReplicas : 1