Skip to content

Instantly share code, notes, and snippets.

View Oats87's full-sized avatar

Chris Kim Oats87

View GitHub Profile
etcdctl get / --prefix --endpoints=${ETCDCTL_ENDPOINTS} --keys-only | grep ${NAMESPACE}
for i in $(kubectl get state -n hobbyfarm | awk '{print $1}' | grep -v "NAME"); do kubectl -n hobbyfarm patch state $i -p '{"metadata":{"finalizers": []}}' --type=merge; done
kubectl get configmap -n kube-system cattle-controllers -o json | jq -r '.metadata.annotations["control-plane.alpha.kubernetes.io/leader"]' | jq -r ".holderIdentity"
#!/bin/sh
sed -i "/\b\UUID\b/d" /etc/sysconfig/network-scripts/ifcfg-ens192
rm -vf /etc/ssh/ssh_host_*
systemctl stop systemd-journald.socket
find /var/log -type f -exec rm {} \;
rm -rf /var/log/journal/*
rm /root/.bash_history; history -c
systemctl poweroff
@Oats87
Oats87 / push.sh
Created October 7, 2020 18:35
Requires skopeo and lots of disk space
#!/bin/bash
REPO=${REPO:-rancher}
IMAGE=${IMAGE:-rancher-agent}
TAG=${TAG:-v2.5.1-rc1}
DESTREPO=${DESTREPO:-oats87}
DESTIMAGE=${DESTIMAGE:-$IMAGE}
DESTTAG=${DESTTAG:-$TAG}
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml; export PATH=$PATH:/var/lib/rancher/rke2/bin
crictl -r /var/run/k3s/containerd/containerd.sock exec -it $(crictl -r /var/run/k3s/containerd/containerd.sock ps | grep etcd | awk '{print $1}') /bin/bash
@Oats87
Oats87 / collect.sh
Created July 7, 2022 16:18
Collect pprof for Rancher in K8s
#!/bin/sh
for pod in $(kubectl get pods --no-headers -l app=rancher -n cattle-system | cut -d ' ' -f1); do
echo Collecting pprof information for $pod - this will take some time.
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/profile -o profile;
kubectl -n cattle-system cp $pod:profile pprof-$pod-profile -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/goroutine -o goroutine;
kubectl -n cattle-system cp $pod:goroutine pprof-$pod-goroutine -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/heap -o heap;
kubectl -n cattle-system cp $pod:heap pprof-$pod-heap -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/threadcreate -o threadcreate;
@Oats87
Oats87 / get-init-machine-for-cluster.sh
Created April 11, 2023 15:53
Get the init machine for a managed K3s/RKE2 cluster in Rancher. Requires jq
CLUSTER_NAME="CLUSTER-NAME"; kubectl get rkebootstrap -n fleet-default $(kubectl get secrets -n fleet-default --field-selector=type=rke.cattle.io/machine-plan -l cluster.x-k8s.io/cluster-name="$CLUSTER_NAME",rke.cattle.io/init-node=true -o json | jq -r '.items[0].metadata.ownerReferences[0].name') -o json | jq -r '.metadata.ownerReferences[0].name'
@Oats87
Oats87 / diff-yaml.sh
Created April 18, 2023 20:03
This requires `yq`, `diff`, and `bash`
#!/bin/bash
FILE=${1:-0}
if [ "${FILE}" = "0" ]; then
echo "need to specify a file"
exit 1
fi
fileNo=$(ls $FILE-split | wc -l | awk '{print $1}')