-
-
Save backnotprop/b991f9053bc0cf98929af6ad2bbe37c2 to your computer and use it in GitHub Desktop.
GKE CPU Pinning Script - Run this as a DaemonSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTFS="/mnt/hostfs" | |
function sleep_forever() { | |
while true; do sleep 100; done | |
} | |
function setup_kubectl() { | |
# Setup kubectl | |
cd $HOSTFS/var/run/secrets/kubernetes.io/serviceaccount | |
TOKEN=$(cat token) | |
kubectl config set-cluster scylla --server=https://kubernetes.default --certificate-authority=ca.crt | |
kubectl config set-credentials [email protected] --token=$TOKEN | |
kubectl config set-context scylla --cluster=scylla [email protected] | |
kubectl config use-context scylla | |
} | |
setup_kubectl | |
echo "Changing kubelet configs and restarting the kubelet service" | |
if [[ `grep "cpuManagerPolicy" $HOSTFS/home/kubernetes/kubelet-config.yaml | wc -l` -eq 0 ]] | |
then | |
kubectl drain $NODE --force --ignore-daemonsets --delete-local-data --grace-period=60 | |
echo cpuManagerPolicy: static | tee -a $HOSTFS/home/kubernetes/kubelet-config.yaml | |
elif [[ `grep "cpuManagerPolicy" $HOSTFS/home/kubernetes/kubelet-config.yaml | wc -l` -gt 1 ]] | |
then | |
kubectl drain $NODE --force --ignore-daemonsets --delete-local-data --grace-period=60 | |
sed -i '/cpuManagerPolicy/d' $HOSTFS/home/kubernetes/kubelet-config.yaml | |
echo cpuManagerPolicy: static | tee -a $HOSTFS/home/kubernetes/kubelet-config.yaml | |
else | |
echo "Policy already there!" | |
echo "Uncondoning the node" | |
kubectl uncordon $NODE | |
sleep_forever | |
fi | |
rm $HOSTFS/var/lib/kubelet/cpu_manager_state | |
# Couldn't get systemctl to work... | |
# Not a good solution, but it works | |
kill -9 $(pidof kubelet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment