mysql docker oom_记一次 K3s MySQL 启动 OOM 排查

以前用Docker Compose做开发环境,MySQL也在Docker里运行,一切使用正常。后来开发环境迁移到K3s(轻量级的K8s),但是MySQL一启动就被OOM Killer干掉,所以一直没迁移MySQL。

重现

使用Kubectl直接运行一个MySQL即可重现:

apiVersion: apps/v1

kind: Deployment

metadata:

name: mysql

spec:

replicas: 1

selector:

matchLabels:

app: mysql

template:

metadata:

labels:

app: mysql

spec:

containers:

- name: mysql

image: mysql:5.7

imagePullPolicy: IfNotPresent

env:

- name: MYSQL_ROOT_PASSWORD

value: root

resources:

limits:

memory: 4G

cpu: 500m

dmesg 可以看mysqld分配超过了3.7G内存然后被杀掉:

[ 839.399262] Tasks state (memory values in pages):

[ 839.399263] [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name

...

[ 839.399278] [ 34888] 0 34888 4208240 974177 7962624 0 -998 mysqld

[ 839.399280] oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=...,mems_allowed=0,oom_memcg=/kubepods/pod..,task_memcg=/kubepods/pod../56..,task=mysqld,pid=34888,uid=0

[ 839.399294] Memory cgroup out of memory: Killed process 34888 (mysqld) total-vm:16832960kB, anon-rss:3895388kB, file-rss:1320kB, shmem-rss:0kB

[ 839.496988] oom_reaper: reaped process 34888 (mysqld), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

排查

优化MySQL

你可能感兴趣的:(mysql,docker,oom)