Skip to content

Instantly share code, notes, and snippets.

@adleong
adleong / lost-sock.sh
Last active January 31, 2023 21:03
Detect half-open connections in Kubernetes
#!/bin/bash
pods=$(kubectl get po -A -l linkerd.io/control-plane-ns -ojsonpath="{range .items[*]}{.metadata.name} {.metadata.namespace}{'\n'}{end}")
IFS=" "
while read name namespace; do
tcp=$(kubectl debug -n $namespace $name --image=cr.l5d.io/linkerd/debug:stable-2.12.0 -it -- cat /proc/net/tcp)
close_wait=$(echo $tcp | awk 'BEGIN {cnt=0} $4==08 {cnt++} END {print cnt}')
fin_wait_2=$(echo $tcp | awk 'BEGIN {cnt=0} $4==05 {cnt++} END {print cnt}')
@adleong
adleong / scrape-policy.yml
Created August 12, 2022 22:01
A policy which grants linkerd-viz permission to scrape metrics from the proxies in this namespace
---
apiVersion: policy.linkerd.io/v1beta1
kind: Server
metadata:
name: proxy-admin
labels:
linkerd.io/extension: viz
spec:
podSelector:
matchExpressions:
---
apiVersion: policy.linkerd.io/v1beta1
kind: Server
metadata:
namespace: emojivoto
name: emoji-grpc
labels:
app.kubernetes.io/part-of: emojivoto
app.kubernetes.io/name: emoji
app.kubernetes.io/version: v11
@adleong
adleong / yml
Created October 31, 2022 02:30
nginx ingress with tracing
apiVersion: v1
kind: Namespace
metadata:
labels:
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
name: ingress-nginx
---
apiVersion: v1
automountServiceAccountToken: true
@adleong
adleong / gist:d6dd9636a10042a4eb1696361ef14b67
Created October 31, 2022 02:34
emojivoto with tracing
apiVersion: v1
kind: Namespace
metadata:
name: emojivoto
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: emoji
namespace: emojivoto
# Step 1: Install Linkerd
# Step 2: Install Linkerd Viz (optional, but helpful for seeing what's going on)
# Step 3: Install Linkerd Jaeger
# Step 4: Install Nginx Ingress:
linkerd inject https://gist.githubusercontent.com/adleong/f7318d9282ab99ba12c3479405882e60/raw/713daaa51f035d0d484ea79daf77cc3aaded8010/yml | kubectl apply -f -
# Notice the tracing related config in the nginx config configmap in the aboe gist: https://gist.github.com/adleong/f7318d9282ab99ba12c3479405882e60#file-yml-L340
# Step 5: Install Emojivoto
# Two backend pods, one always failing
# and another one returning OK response
# Slowcooker is used to generate traffic
# that will be routed via traffic split
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec: