Skip to content

Instantly share code, notes, and snippets.

View nevermosby's full-sized avatar
🎯
Focusing

Wen-Quan Li nevermosby

🎯
Focusing
View GitHub Profile
@nevermosby
nevermosby / linux-traffic-control.sh
Created September 5, 2022 06:58
How to do the traffic shaping with Linux TC
#!/bin/bash
#USAGE: sudo ./netspeed -l limit_in_kbit -s
usage="sudo $(basename "$0") -l speed_limit -s
-l speed_limit - speed limit with units (eg. 1mbit, 100kbit, more on \`man tc\`)
-s - remove all limits
"
# default values
LIMIT=0
@nevermosby
nevermosby / access-kind.sh
Last active August 17, 2022 02:54
expose k8s api server provisioned by KIND
### 1. local port forward on k8s server
#
# :8080 ---> 127.0.0.1:12345(k8s api server local port)
#
sudo socat TCP-LISTEN:8080,reuseaddr,fork tcp:127.0.0.1:12345
### 2. local port foward on k8s client host
#
# :8888 ---> 1.2.3.4:8080(the external ip of k8s server)
#
@nevermosby
nevermosby / bpf-tc-drop-tcp-inlined.o
Created May 24, 2020 06:29
bpf program only can be loaded into kernel if the program contains inlined function
Disassembly of section tc:
tc_drop_tcp:
0: bf 16 00 00 00 00 00 00 r6 = r1
1: b7 01 00 00 00 00 00 00 r1 = 0
2: 73 1a f4 ff 00 00 00 00 *(u8 *)(r10 - 12) = r1
3: b7 01 00 00 69 6f 6e 0a r1 = 175009641
4: 63 1a f0 ff 00 00 00 00 *(u32 *)(r10 - 16) = r1
5: 18 01 00 00 20 74 63 20 00 00 00 00 73 65 63 74 r1 = 8386658476233028640 ll
7: 7b 1a e8 ff 00 00 00 00 *(u64 *)(r10 - 24) = r1
8: 18 01 00 00 45 6e 74 65 00 00 00 00 72 69 6e 67 r1 = 7453010373394067013 ll
@nevermosby
nevermosby / bpf-tc-drop-tcp-not-inline.o
Created May 24, 2020 06:28
bpf program cannot loaded into kernel if the program contains not-inlined functions
Disassembly of section tc:
tc_drop_tcp:
0: bf 16 00 00 00 00 00 00 r6 = r1
1: b7 01 00 00 69 6f 6e 0a r1 = 175009641
2: 63 1a f8 ff 00 00 00 00 *(u32 *)(r10 - 8) = r1
3: 18 01 00 00 20 74 63 20 00 00 00 00 73 65 63 74 r1 = 8386658476233028640 ll
5: 7b 1a f0 ff 00 00 00 00 *(u64 *)(r10 - 16) = r1
6: 18 01 00 00 45 6e 74 65 00 00 00 00 72 69 6e 67 r1 = 7453010373394067013 ll
8: 7b 1a e8 ff 00 00 00 00 *(u64 *)(r10 - 24) = r1
9: b7 01 00 00 00 00 00 00 r1 = 0
@nevermosby
nevermosby / build-curl-with-c-ares.sh
Last active April 4, 2024 00:40
build curl with c ares for custom dns server
## for some distributions of Linix, like ubuntu 18.04
## `curl` does not include `c-ares` module so that you cannot do `curl --dns-servers 8.8.8.0 www.example.com`
## you will get error message as below:
## curl: (4) A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.
# build curl from source code
# You can do that with building `curl` from souce code. below is tested against ubuntu 18.04
# download the code from git repo
git clone https://github.com/curl/curl.git && cd curl
@nevermosby
nevermosby / update-k8s-pv.sh
Created December 8, 2019 02:32
manually update kubernetes PV path
#!/bin/sh
# 1. delete pv, pv会变成terminating状态
kubectl delete pv [pv-name]
# 2. delete pvc, pvc会变成terminating状态
kubectl delete pvc [pvc-name-related-to-pv]
# 3. patch pvc to remove protection, 具体可以看这里:https://stackoverflow.com/questions/51358856/kubernetes-cant-delete-persistentvolumeclaim-pvc,然后pv和pvc就被干净删除了
kubectl patch pvc [pvc-name] -p '{"metadata":{"finalizers": []}}' --type=merge
@nevermosby
nevermosby / etcdctl-mannual.md
Last active August 28, 2019 09:11
etcdctl-mannual

use etcdctl for etcd v3 API

if you have access to the etcd server, you can use the following steps to try etcd v3 API to fetch Kubernetes cluster data

  1. set environment to use v3 API
# set ETCDCTL_API
export ETCDCTL_API=3
  1. use etcdctl tool to fetch all the namespaces
# fetch all the namespaces
@nevermosby
nevermosby / deepequal.go
Last active February 12, 2019 03:12
source code of relect.DeepEqual in golang
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Deep equality test via reflection
package reflect
import "unsafe"
@nevermosby
nevermosby / go-help-modules.txt
Created October 4, 2018 04:52
the output of `go help modules` command
# go help modules
A module is a collection of related Go packages.
Modules are the unit of source code interchange and versioning.
The go command has direct support for working with modules,
including recording and resolving dependencies on other modules.
Modules replace the old GOPATH-based approach to specifying
which source files are used in a given build.
Preliminary module support
@nevermosby
nevermosby / ss-man.sh
Last active May 25, 2018 05:28
ss command help dos
ss -ltn # list out all the listening sockets
ss -ltp # list out all the listening socketes and the related process name with pid
ss -t4 state time-wait # list all Ipv4 tcp sockets that are in "time-wait" state
# state list
1. established
2. syn-sent
3. syn-recv
4. fin-wait-1
5. fin-wait-2