1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

メモリ圧迫テストで利用できるコンテナの作り方

Last updated at Posted at 2020-08-01

インフラ環境の構築や検証をしているとメモリが圧迫された時の挙動を確認したくなる時があるかと思います。
そんな時に以下のコンテナを使うと指定したメモリを専有してくれて便利です。
(k8s環境を想定していますが、dockerさえ入っていればdocker runで起動することが可能です)

構成

・docker-entrypoint.sh
・Dockerfile
・deployment.yml

内容

・docker-entrypoint.sh

#!/bin/sh

MEMORY_USE_M=`echo $(($MEMORY_USE/1024/1024))`

echo "${MEMORY_USE_M}MB"
/usr/bin/stress -m 1 --vm-bytes $MEMORY_USE --vm-hang 0 -q

・Dockerfile

FROM ubuntu:18.04

ENV MEMORY_USE 1134217728

RUN curl -O http://ports.ubuntu.com/pool/universe/s/stress/stress_1.0.4-2_arm64.deb && \
    apt-get install ./stress_1.0.4-2_arm64.deb
ADD docker-entrypoint.sh .

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]

・stress.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: stress
  labels:
    run: stress
spec:
  replicas: 1
  selector:
    matchLabels:
      run: stress
  template:
    metadata:
      labels:
        run: stress
    spec:
      containers:
      - image: stress:latest
        name: stress
        imagePullPolicy: IfNotPresent
        env:
        - name: MEMORY_USE
          value: "2134217728"
1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?