Skip to content

Instantly share code, notes, and snippets.

@AlexisDucastel
AlexisDucastel / rke2-commands.md
Created September 23, 2021 22:10 — forked from superseb/rke2-commands.md
RKE2 / rancherd commands

RKE2 commands

Install

curl -sL https://get.rke2.io | sh
systemctl daemon-reload
systemctl start rke2-server
@AlexisDucastel
AlexisDucastel / mysql-max-mem.sql
Last active August 2, 2021 23:58
MySQL max memory calculation
SELECT
ROUND(base.mem_MB, 3) as base_mem_MB,
ROUND(per_conn.mem_MB, 3) as per_conn_mem_MB,
@@GLOBAL.max_connections as max_conn,
ROUND(@@GLOBAL.max_connections * per_conn.mem_MB, 3) as max_conn_MB,
ROUND(@@GLOBAL.max_connections * per_conn.mem_MB + base.mem_MB, 3) as total_MB
FROM
( SELECT (@@GLOBAL.key_buffer_size + @@GLOBAL.query_cache_size + @@GLOBAL.tmp_table_size + @@GLOBAL.innodb_buffer_pool_size + @@GLOBAL.innodb_log_buffer_size)/1024/1024 as mem_MB) as base,
( SELECT (@@GLOBAL.sort_buffer_size + @@GLOBAL.read_buffer_size + @@GLOBAL.read_rnd_buffer_size + @@GLOBAL.join_buffer_size + @@GLOBAL.thread_stack + @@GLOBAL.binlog_cache_size) /1024/1024 as mem_MB) as per_conn \G
@AlexisDucastel
AlexisDucastel / split-k8s-list.sh
Last active July 20, 2021 14:38
Split Kubernetes items list into multiple yaml files
kubectl get x -o yaml | yq e '.items[]|splitDoc' - | awk '/^ name:/{file=$NF".yaml"} !/^--/{s=s $0"\n"} /^---/{print s > (file); close(file); s=""}'
@AlexisDucastel
AlexisDucastel / ksb.sh
Created March 23, 2021 07:25
Draft Kubernetes Storage Benchmark
#!/bin/bash
function pod_wait_for_status {
while true
do
STATUS=$(kubectl get pod $1 2>/dev/null|tail -n 1| awk '{print $3}')
debug 2 "Pod $1 is in state $STATUS (waiting for $2)"
[ "$STATUS" = "$2" ] && break
sleep 1
done
@AlexisDucastel
AlexisDucastel / 00-docker-shorewall.md
Created October 24, 2020 22:00 — forked from lukasnellen/00-docker-shorewall.md
setup shorewall for docker networking beyond the default bridge network, e.g., for docker-compose

Docker(-compose) with shorewall

The shorewall documentation explains in http://shorewall.org/Docker.html how to configure shorewall for use with docker. The problem with the configuration is that it only allows connections from the host to the main bridge docker0. Connections to other networks on dynamically created bridges, with names starting by default with br-, is blocked. Instead of the recommended contents of /etc/shorewall/interfaces, use wild-card interface names as follows:

#ZONE	INTERFACE	OPTIONS
#dock	docker0		bridge     # disabled default recommendation
dock 	docker0		physical=docker+,routeback=1
dock 	br		physical=br-+,routeback=1
@AlexisDucastel
AlexisDucastel / restore-rkestate-file.md
Created November 19, 2019 16:27 — forked from superseb/restore-rkestate-file.md
Recover cluster.rkestate file from controlplane node

Recover cluster.rkestate file from controlplane node

RKE

Run on controlplane node, uses any found hyperkube image

docker run --rm --net=host -v $(docker inspect kubelet --format '{{ range .Mounts }}{{ if eq .Destination "/etc/kubernetes" }}{{ .Source }}{{ end }}{{ end }}')/ssl:/etc/kubernetes/ssl:ro --entrypoint bash $(docker inspect $(docker images -q --filter=label=org.label-schema.vcs-url=https://github.com/rancher/hyperkube.git) --format='{{index .RepoTags 0}}' | tail -1) -c 'kubectl --kubeconfig /etc/kubernetes/ssl/kubecfg-kube-node.yaml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .' > cluster.rkestate
@AlexisDucastel
AlexisDucastel / test-pleg.md
Created September 20, 2019 11:50 — forked from superseb/test-pleg.md
PLEG tester

PLEG tester

A few commands to run to test what triggers PLEG.

Docker response time

When using Docker, all container statuses are compared and it needs to happen within 3 minutes. Else the following log will be shown:

@AlexisDucastel
AlexisDucastel / rancher-server-standalone.yml
Created April 24, 2019 10:02
Rancher 2 server standalone on Kubernetes
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: rancher-server
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
@AlexisDucastel
AlexisDucastel / gist:1df4efd6b4e8b0253edf0e67874a9283
Created March 19, 2019 14:38
List listening TCP ports on linux
cat /proc/net/tcp| cut -c -36|grep '0A$'| cut -c 16-19| while read line; do echo $((16#$line)); done
@AlexisDucastel
AlexisDucastel / stats.sh
Created November 29, 2018 10:47
Second scale metrics consumer
#!/bin/bash
COUNT=$1
tail -n$COUNT /home/ubuntu/metrics.log | \
awk '{M+=$1;U+=$2;N+=$3;S+=$4;I+=$5;T+=$6} END {printf "%d\t=%.2f+%.2f+%.2f+%.2f+%.2f\n",M/NR,U/NR,N/NR,S/NR,I/NR,T/NR}'