Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Created May 18, 2023 18:55
Show Gist options
  • Save alexeldeib/5faf6467511d4d36a5cd47c5e08e72e0 to your computer and use it in GitHub Desktop.
Save alexeldeib/5faf6467511d4d36a5cd47c5e08e72e0 to your computer and use it in GitHub Desktop.
kubelet 30s kill pod
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: &name kubelet-killer-30sec
labels:
app: *name
spec:
selector:
matchLabels:
app: *name
template:
metadata:
labels:
app: *name
spec:
hostNetwork: true
hostPID: true
containers:
- image: docker.io/alexeldeib/nsenter:static # requires an image with bash, curl, sleep, and nsenter (vanilla ubuntu works)
imagePullPolicy: Always
name: *name
command: ["/entrypoint.sh"]
args: ["killit"] # if you don't use my image or build one from Dockerfile, set this to "downloadandinstall"
resources:
requests:
{}
limits:
{}
securityContext:
privileged: true
volumeMounts:
- name: actions
mountPath: "/opt/actions"
- name: hostmount
mountPath: "/mnt/actions"
- name: usr
mountPath: /mnt/usr
volumes:
- name: usr
hostPath:
path: /usr
type: DirectoryOrCreate
- name: hostmount
hostPath:
path: /opt/actions
type: DirectoryOrCreate
- name: actions
configMap:
name: nsenter-actions
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nsenter-actions
labels:
app: nsenter
data:
killit: |
#!/usr/bin/env bash
set -uo pipefail
# This script should be executed on VM host in the directly as the deb packages
# the host will be mounted at /host, the debs will be copied to /mnt
# then the container will nsenter and install everything against the host.
set -x
echo "starting kubelet killer"
# !!DANGER!! but but nice because it restarts kubelet
trap 'systemctl restart kubelet' EXIT SIGINT SIGTERM
systemctl stop kubelet
# do stuff
sleep 30
# restart it
systemctl restart kubelet
echo "finished elet killer"
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment