Skip to content

Instantly share code, notes, and snippets.

@brianpursley
brianpursley / kubectl-echo.md
Created April 13, 2022 20:51
Create an echo server in Kubernetes

Creates a pod called echo that listens on port 8080, echoing everything it receives.

kubectl run echo --image=busybox -- nc -lk -p 8080 -e cat

To test it out, you can do this, to listen on local port 8080 and forward all connections to the echo pod:

kubectl port-forward echo 8080:8080
@brianpursley
brianpursley / gist:3e303b6859a7c06693ff61923997d4c7
Created February 6, 2022 22:54
Start a TCP echo pod in Kubernetes
kubectl run tcpecho --image=alpine --restart=Never -- /bin/sh -c "apk add socat && socat -v tcp-listen:8080,fork EXEC:cat"
@brianpursley
brianpursley / gist:229291b6f9aadd78e6120275b57fec87
Last active May 25, 2021 16:47
Test all kubernetes.io links found in source code to determine which ones are broken
grep -orihEI "(https?:\/\/kubernetes.io/[-a-zA-Z0-9@:%._\+~#=>?/]*[-a-zA-Z0-9@:%_\+~#=>?])" * | sort | uniq -u | xargs -I % bash -c 'if wget --spider % 2>/dev/null; then echo "[OK] %"; else echo "[MISSING] %"; fi' > /tmp/output.txt
cat /tmp/output.txt | grep "\[MISSING\]" | cut -d " " -f2 | xargs -I % grep -riI %
@brianpursley
brianpursley / workers.go
Last active September 22, 2020 18:07
Example of using go routines as async producer/consumer workers communicating over a channel
package main
import (
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
@brianpursley
brianpursley / latency.log
Created August 2, 2020 20:12
http requests reporting latency of more than 10 seconds (grepped from master kube-apiserver.log artifact from https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/93408/pull-kubernetes-e2e-gce-ubuntu-containerd/1289803648271912962)
I0802 06:18:52.492532 9 httplog.go:89] "HTTP" verb="GET" URI="/api/v1/nodes?resourceVersion=680&timeout=8m1s&timeoutSeconds=481&watch=true" latency="21.143508754s" userAgent="metrics-server/v0.0.0 (linux/amd64) kubernetes/$Format" srcIP="34.83.47.168:37848" resp=0
I0802 06:18:52.492782 9 httplog.go:89] "HTTP" verb="GET" URI="/api/v1/pods?resourceVersion=692&timeout=9m42s&timeoutSeconds=582&watch=true" latency="21.140854044s" userAgent="metrics-server/v0.0.0 (linux/amd64) kubernetes/$Format" srcIP="34.83.47.168:37848" resp=0
I0802 06:18:58.427831 9 httplog.go:89] "HTTP" verb="GET" URI="/api/v1/namespaces/kube-system/secrets?allowWatchBookmarks=true&fieldSelector=metadata.name%3Dmetrics-server-token-2jd7g&resourceVersion=416&timeout=9m52s&timeoutSeconds=592&watch=true" latency="32.681829847s" userAgent="kubelet/v1.20.0 (linux/amd64) kubernetes/766e56b" srcIP="34.83.47.168:58092" resp=0
I0802 06:18:58.428238 9 httplog.go:89] "HTTP" verb="GET" URI="/api/v1/namespaces/kube-system/configmaps
@brianpursley
brianpursley / kubernetes-periodics.txt
Created July 27, 2020 17:36
find . -name "*.yaml" | xargs -L1 yq r -j | jq -r '.periodics[] | "\(.name): \(.interval)"' 2> /dev/null | grep -v ": null" | sort > kubernetes-periodics.txt
application-periodic-default-gke: 2h
ci-aws-ebs-csi-driver-migration-test-latest: 6h
ci-benchmark-kube-dns-master: 2h
ci-benchmark-microbenchmarks: 20m
ci-benchmark-nodelocal-dns-master: 2h
ci-benchmark-scheduler-master: 2h
ci-benchmark-scheduler-perf-master: 2h
ci-build-and-push-k8s-at-golang-tip: 8h
ci-cadvisor-canarypush: 24h
ci-cadvisor-e2e: 8h
@brianpursley
brianpursley / BstExample.java
Created July 16, 2020 23:48
Binary Search Tree DFS, BFS, and Search using Java
package example;
import java.util.ArrayDeque;
import java.util.Arrays;
public class BstExample {
static class Node {
private int value;
private Node left;
@brianpursley
brianpursley / flake-culprit-output.txt
Last active May 15, 2020 01:15
output of running `./flake-culprits.sh pull-kubernetes-e2e-kind 250` on 5/14/2020 9:15pm ET
89 [sig-api-machinery] client-go should negotiate watch and report errors with accept \
71 [sig-apps] DisruptionController Listing PodDisruptionBudgets for all namespaces should list and delete a collection of PodDisruptionBudgets
69 [sig-api-machinery] Garbage collector should orphan pods created by rc if delete options say so [Conformance]
68 [sig-storage] Subpath Atomic writer volumes should support subpaths with projected pod [LinuxOnly] [Conformance]
67 [k8s.io] Docker Containers should use the image defaults if command and args are blank [NodeConformance] [Conformance]
67 [k8s.io] Pods should be updated [NodeConformance] [Conformance]
67 [k8s.io] PrivilegedPod [NodeConformance] should enable privileged commands [LinuxOnly]
67 [k8s.io] [sig-node] Security Context should support container.SecurityContext.RunAsUser [LinuxOnly]
67 [sig-storage] ConfigMap should be consumable from pods in volume with mappings [NodeConformance] [Conformance]
67 [sig-storage] Projec
@brianpursley
brianpursley / flake-culprit.sh
Last active May 15, 2020 01:15
Count how many times a test occurs before the first failure, to help track down tests that cause other tests that come after them to fail
#!/bin/bash
#
# Example Usage:
#
# ./flake-culprits.sh pull-kubernetes-e2e-kind 250
#
job=$1
max=$2
@brianpursley
brianpursley / test-output-pr90978.txt
Created May 12, 2020 16:11
make test-integration WHAT=./test/integration/scheduler GOFLAGS="-v" KUBE_TEST_ARGS='-run ^TestNominatedNodeCleanUp$$$$'
+++ [0512 12:10:46] Checking etcd is on PATH
/usr/bin/etcd
+++ [0512 12:10:46] Starting etcd instance
/home/bpursley/go/src/k8s.io/kubernetes/third_party/etcd:/home/bpursley/gems/bin:/home/bpursley/.nvm/versions/node/v12.14.0/bin:/usr/lib/jvm/jdk-13.0.1/bin:/home/bpursley/.local/bin:/home/bpursley/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bpursley/.dotnet/tools:/usr/share/rvm/bin:/home/bpursley/bin:/usr/local/go/bin:/home/bpursley/go/bin:/home/bpursley/.krew/bin:/home/bpursley/kubectl-plugins
etcd --advertise-client-urls http://127.0.0.1:2379 --data-dir /tmp/tmp.Ga0I2sAFta --listen-client-urls http://127.0.0.1:2379 --debug > "/dev/null" 2>/dev/null
Waiting for etcd to come up.
+++ [0512 12:10:47] On try 1, etcd: : {"health":"true"}
{"header":{"cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"2","raft_term":"2"}}+++ [0512 12:10:47] Running integration test cases
+++ [0512 12:10:52] Running tests without code cov