Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@ishii1648

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

インフラ環境の構築や検証をしているとメモリが圧迫された時の挙動を確認したくなる時があるかと思います。
そんな時に以下のコンテナを使うと指定したメモリを専有してくれて便利です。
(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"
3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ishii1648
東京でSREをしています。kubernetesやGoが大好きです。
allabout
その道のプロである専門家(ガイド)を基盤に、総合情報サイトを中心とした様々なサービスをWEB&リアルで展開

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?