Skip to content

Instantly share code, notes, and snippets.

View clementnuss's full-sized avatar
🐄

Clément Nussbaumer clementnuss

🐄
View GitHub Profile
@clementnuss
clementnuss / README.md
Created February 14, 2024 11:45
asciinema-server Kubernetes deployment
@clementnuss
clementnuss / README.md
Last active December 27, 2023 10:58
MariaDB backup with Kubernetes CronJob

Kubernetes CronJob to backup, compress (with gzip --rsyncable), and finally use restic to backup your DBs to an S3 endpoint.

more details in my blog post

Advantages:

  • using mariadb:latest Docker image, to ensure I don't use an outdated mariadb-dump binary
  • backing up each database in a separate file, to make for easier restore
  • compressing the backups with gzip and the --rsyncable option (details here), which makes gzip "regularly reset his compression algorithm to what it was at the beginning of the file", so that changes to a portion of the file do not alter the whole compressed output, which permits to make incremental backups.
  • using restic to store the backups on an S3 endpoint (Cloudflare R2, with a generous free tier!), which makes for simple management and rotation, as well as for simple restores.
@clementnuss
clementnuss / eBPF-execve-argv-envp-print.md
Created November 28, 2023 13:36
eBPF - using bpftrace to debug argv and env of an executable

Using eBPF to print argv and envp when running a specific file

With bpftrace on Linux, it's quite simple to monitor when a specific binary is run, and to print it's args and the environment variables passed to it.

This can be done with the following bpftrace "program":

tracepoint:syscalls:sys_enter_execve
/str(args->filename) == "/etc/network/if-up.d/resolved" /
{
@clementnuss
clementnuss / etcdctl-leader-transfer.md
Created July 7, 2023 05:49
etcd - move leader away

etcd - moving the leader away

When patching some Kubernetes control-plane nodes on which etcd also happens to be running, you might want to gracefully transfer the leadership of the etcd cluster away before patching and eventually patching the node.

This can be achieved with the following script, provided you specify the adequate environment variables in /etc/profile.d/etcd-all:

set -o pipefail && \
source /etc/profile.d/etcd-all && \
AM_LEADER=$(etcdctl endpoint status | grep $(hostname) | cut -d ',' -f 5 | tr -d ' ') && \
@clementnuss
clementnuss / yqblank.sh
Last active June 2, 2023 23:09
fish/bash function to prevent changing blank lines while using yq
#fish
function yqblank;
yq eval "$argv[1]" "$argv[2]" | diff -B "$argv[2]" - | patch "$argv[2]" -o -
end
#bash
yqblank() {
yq "$1" "$2" | diff -B "$2" - | patch "$2" -
}
@clementnuss
clementnuss / s3-batch-deletion.md
Created January 7, 2023 09:21
Batch deletion of S3 objects #blog

Batch deletion of S3 objects

If you ever tried to delete more than a few hundred files on S3, you might have noticed how slow it was.

To speed-up the deletion, we can use a few bash commands to parallelize the deletion, and we can also use some json description of the objets we want to delete.

Concretely, it permits us to delete e.g. 1000 files with a single s3 API request.

How ?

@clementnuss
clementnuss / rollout-restart.go
Last active September 28, 2022 13:57
script to rollout restart all deployments on a kubernetes cluster by packs of 20, waiting 1min between packs
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/bitfield/script"
)
@clementnuss
clementnuss / xclip
Last active May 23, 2022 13:31
`xclip` script to permit replacing xclip with lemonade easily
#!/bin/bash
stdin="$([[ -p /dev/stdin ]] && cat -)"
lemonade copy $stdin

the following ffmpeg permits to save images in highest quality to generate a timelapse:

export RTSP_STREAM='rtsps://abcdeffhijklmnop:1234/asdlfkjasdlf'
ffmpeg -loglevel error -rtsp_transport tcp \
  -i $RTSP_STREAM \
  -vf fps=1/120 \
  -q:v 1 -strftime 1 \
  "%Y-%m-%d_%H-%M-%S.jpg"
@clementnuss
clementnuss / cni_interceptor.sh
Last active March 29, 2021 12:00
Bash script permitting to intercept CNI calls and log env, stdin, stdout, stderr
#!/bin/bash
# Auther Clément Nussbaumer <clement@astutus.org>, Aug 2020
#
# CNI interception script: permits to do live debugging of CNI calls.
# Usage: rename the real cni binary file with by prepending the orginal binary name with real_
# E.g. for multus, real_multus. Now put this script in place the binary:
# Concretely, name it `multus` if you want to intercept multus calls.
cni=$(echo $0 | awk '{split($0,r,"/"); print r[length(r)]}')
echo 'intercepted '$cni' cni with command: ' $CNI_COMMAND ' and caller: ' $(ps -o comm= $PPID) | logger -t cni