Created
July 1, 2020 09:23
-
-
Save aseaday/a0972045222ccf0c3976f827f56001a1 to your computer and use it in GitHub Desktop.
This file contains 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
## Get Docker Image | |
btrfs subvol create images/alpine | |
CID=$(docker run -d python:3.8-alpine true) | |
docker export $CID | tar -C images/alpine/ -xf- | |
btrfs subvol snapshot images/alpine/ containers/springrain | |
touch containers/springrain/I_AM_HERE | |
## tmux as a container and mount | |
tmux | |
unshare --mount --uts --ipc --net --pid --fork bash | |
hostname springrain | |
exec bash | |
ps aux | |
strace ps aux | |
### | |
mount -t proc proc /proc | |
ps aux | |
### | |
mount --bind /fundocker/containers/springrain /fundocker/containers/springrain | |
mkdir /fundocker/containers/springrain/oldroot | |
cd /fundocker/containers/springrain/ | |
pivot_root . oldroot | |
ps aux | |
mount -t proc proc /proc | |
mount | head | |
umount -l /oldroot | |
## networking | |
CPID=$(pidof unshare) | |
echo $CPID | |
ip link add name h$CPID type veth peer name c$CPID | |
ip link set c$CPID netns $CPID | |
ip link set h$CPID master docker0 up | |
export CPID=11716 | |
ip link set lo up | |
ip link set name eth0 up | |
ip addr add 172.17.42.3/16 dev eth0 | |
ip route add default via 172.17.0.1 | |
## cgroup | |
bin/cat <<EOF > ./test.py | |
a = '' | |
i=0 | |
while True: | |
i += 1 | |
print("%dmb" % (i*10,)) | |
some_str = ' ' * 10000000 | |
a = a + some_str | |
EOF | |
mkdir /sys/fs/cgroup/memory/mygroup | |
echo "100000000" > /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes | |
mkdir /sys/fs/cgroup/cpu/mycpugroup | |
sudo echo '5000' > /sys/fs/cgroup/cpu/mycpugroup/cpu.cfs_quota_us | |
cgexec -g cpu:mycpugroup ./test | |
``` | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <cstring> | |
#include <thread> | |
void test_cpu() { | |
printf("thread: test_cpu start\n"); | |
int total = 0; | |
while (1) { | |
++total; | |
} | |
} | |
void test_mem() { | |
printf("thread: test_mem start\n"); | |
int step = 20; | |
int size = 10 * 1024 * 1024; // 10Mb | |
for (int i = 0; i < step; ++i) { | |
char* tmp = new char[size]; | |
memset(tmp, i, size); | |
sleep(1); | |
} | |
printf("thread: test_mem done\n"); | |
} | |
int main(int argc, char** argv) { | |
std::thread t1(test_cpu); | |
std::thread t2(test_mem); | |
t1.join(); | |
t2.join(); | |
return 0; | |
} | |
``` | |
### K3S | |
alias kubectl='k3s kubectl' | |
kubectl get nodes | |
kubectl create deployment hello-node --image=jmalloc/echo-server:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment