Skip to content

Instantly share code, notes, and snippets.

@brianpursley
brianpursley / nginx.sh
Created June 24, 2022 20:42
Nginx pod with readiness probe using path that is 302 redirected to another path
kubectl create ns nginx-test
kubectl apply --namespace nginx-test -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
default.conf: |
server {
@brianpursley
brianpursley / Validate.md
Created May 13, 2022 19:46
Validate functions that operate on cmd and args

Most Validate functions take no parameters, and only validate against Options:

~/go/src/k8s.io/kubernetes (master) $ grep -r ./staging/src/k8s.io/kubectl -Pe 'func.*\(.*Options\).Validate\(\)'
./staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go:func (o *SetResourcesOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/set/set_selector.go:func (o *SetSelectorOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/set/set_image.go:func (o *SetImageOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/set/set_subject.go:func (o *SubjectOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/set/set_env.go:func (o *EnvOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go:func (o ProxyOptions) Validate() error {
./staging/src/k8s.io/kubectl/pkg/cmd/label/label.go:func (o *LabelOptions) Validate() error {
@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