Last active
November 26, 2019 19:28
-
-
Save texascloud/a0d12f3c1498ea53740d3b0f27a7a54a to your computer and use it in GitHub Desktop.
Stress deployment for testing limits of kubernetes nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#!/usr/bin/env bash | |
# This script reproduces what the kubelet does | |
# to calculate memory.available relative to root cgroup. | |
# current memory usage | |
memory_capacity_in_kb=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}') | |
memory_capacity_in_bytes=$((memory_capacity_in_kb * 1024)) | |
memory_usage_in_bytes=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes) | |
memory_total_inactive_file=$(cat /sys/fs/cgroup/memory/memory.stat | grep total_inactive_file | awk '{print $2}') | |
memory_working_set=${memory_usage_in_bytes} | |
if [ "$memory_working_set" -lt "$memory_total_inactive_file" ]; | |
then | |
memory_working_set=0 | |
else | |
memory_working_set=$((memory_usage_in_bytes - memory_total_inactive_file)) | |
fi | |
memory_available_in_bytes=$((memory_capacity_in_bytes - memory_working_set)) | |
memory_available_in_kb=$((memory_available_in_bytes / 1024)) | |
memory_available_in_mb=$((memory_available_in_kb / 1024)) | |
echo "memory.capacity_in_bytes $memory_capacity_in_bytes" | |
echo "memory.usage_in_bytes $memory_usage_in_bytes" | |
echo "memory.total_inactive_file $memory_total_inactive_file" | |
echo "memory.working_set $memory_working_set" | |
echo "memory.available_in_bytes $memory_available_in_bytes" | |
echo "memory.available_in_kb $memory_available_in_kb" | |
echo "memory.available_in_mb $memory_available_in_mb" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: stress | |
namespace: default | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
foo: bar | |
template: | |
metadata: | |
labels: | |
foo: bar | |
spec: | |
nodeSelector: | |
# Modify this to be whatever Node you want to deploy to | |
kubernetes.io/hostname: ip-10-0-1-146.us-west-2.compute.internal | |
containers: | |
- image: camelcasenotation/stress:latest | |
name: stress | |
command: ["sh", "-c"] | |
args: ["stress -m 1 --vm-bytes 6000M --vm-hang 0 --timeout 180s"] | |
resources: | |
requests: | |
memory: 100Mi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment