Im trying to run a basic MySQL 8 pod in Kubernetes. I did a basic deployment without any resource limits or whatsoever. What i do notice that the memory consumption is high. I have a nearly empty database (i think there are max 100 rows with basic data) and the pod is consuming 750M memory.
Is there anything that you can do about this?
apiVersion: apps/v1
kind: Deployment
metadata:
name: db
namespace: my-namespace
spec:
replicas: 1
selector:
matchLabels:
app: db
strategy:
type: Recreate
template:
metadata:
labels:
app: db
spec:
containers:
- name: db
image: mysql:8.0
resources:
env:
- name: MYSQL_DATABASE
value: mydb
- name: MYSQL_USER
value: myuser
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: secret
key: "DATABASE_PASSWORD"
ports:
- containerPort: 3306
name: transport
protocol: TCP
volumeMounts:
- name: db
mountPath: /var/lib/mysql
subPath: mysql
volumes:
- name: db
persistentVolumeClaim:
claimName: db
Best Pim
What i did to reduce the consumption mainly is disable the performance schema. Further i reduced the default connection limit to ensure that it does not reserve the memory for those who are not being used.
It will indeed mean that it can collapse if there are more users but i guess its a guess in on one of those
Proper monitoring on all will do the trick
In the future please add more information about your environment (local, kubeadm
, minikube
, cloud
) and scenario. It would be easier to reproduce or troubleshoot.
I would not say that 750M
RAM is high consumption. For test I've deployed MySQL 8.0
on my GKE cluster using HELM
based on this chart. I've only changed default MySql image version to 8.0
.
$ helm install sql stable/mysql
Pure instance of MySQL on my cluster without any limits
, requests
or data:
$ kubectl top pods
NAME CPU(cores) MEMORY(bytes)
sql-mysql-6c9489d5b9-m8zmh 8m 376Mi
So if MySQL
works with actual data it's normal to consume more resources.
I would say it's normal behaviour.
For general resources use in MySql
you can check How MySQL Uses Memory.
However if you working on local environment with some limited resources you should specify Limits in your YAMLs.
I've just ran a docker container with MySQL and it consumes ~400M of RAM with an empty database that is not even being queried by some application.
docker run -itd -e MYSQL_ROOT_PASSWORD=password mysql
docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
a779ef705921 happy_lumiere 2.22% 373.4MiB / 1.943GiB 18.77% 1.05kB / 0B 0B / 0B 38
According to this assessment it seems to me that 750M is not that much.
You can check out these Best Practices for Configuring Optimal MySQL Memory Usage.