Skip to content

Commit d8d69e7

Browse files
committed
Add node taint script
1 parent 48918c3 commit d8d69e7

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Check if correct number of arguments provided
6+
if [ $# -ne 2 ]; then
7+
echo "Usage: $0 <node-name> <service-name>"
8+
echo "Example: $0 node-1 frontend"
9+
exit 1
10+
fi
11+
12+
NODE_NAME="$1"
13+
SERVICE_NAME="$2"
14+
15+
# Default taint configuration
16+
TAINT_KEY="dedicated"
17+
TAINT_VALUE="special"
18+
TAINT_EFFECT="NoSchedule"
19+
20+
echo "=== Tainting node and adding toleration ==="
21+
echo "Node: $NODE_NAME"
22+
echo "Service: $SERVICE_NAME"
23+
echo "Taint: $TAINT_KEY=$TAINT_VALUE:$TAINT_EFFECT"
24+
echo
25+
26+
# Check if kubectl is available
27+
if ! command -v kubectl &> /dev/null; then
28+
echo "Error: kubectl is not installed"
29+
exit 1
30+
fi
31+
32+
# Check if node exists
33+
if ! kubectl get node "$NODE_NAME" &> /dev/null; then
34+
echo "Error: Node '$NODE_NAME' does not exist"
35+
exit 1
36+
fi
37+
38+
# Check if service (deployment) exists
39+
if ! kubectl get deployment "$SERVICE_NAME" &> /dev/null; then
40+
echo "Error: Deployment '$SERVICE_NAME' does not exist"
41+
exit 1
42+
fi
43+
44+
# Taint the node
45+
echo "1. Tainting node '$NODE_NAME'..."
46+
kubectl taint nodes "$NODE_NAME" "$TAINT_KEY=$TAINT_VALUE:$TAINT_EFFECT" --overwrite
47+
echo "✓ Node tainted successfully"
48+
49+
# Add toleration to the service
50+
echo "2. Adding toleration to deployment '$SERVICE_NAME'..."
51+
kubectl patch deployment "$SERVICE_NAME" -p '{
52+
"spec": {
53+
"template": {
54+
"spec": {
55+
"tolerations": [
56+
{
57+
"key": "'$TAINT_KEY'",
58+
"operator": "Equal",
59+
"value": "'$TAINT_VALUE'",
60+
"effect": "'$TAINT_EFFECT'"
61+
}
62+
]
63+
}
64+
}
65+
}
66+
}'
67+
echo "✓ Toleration added successfully"
68+
69+
echo
70+
echo "=== Operation completed ==="
71+
echo "The deployment '$SERVICE_NAME' can now be scheduled on the tainted node '$NODE_NAME'"
72+
echo
73+
echo "Verify with:"
74+
echo " kubectl describe node $NODE_NAME | grep -A5 Taints"
75+
echo " kubectl get deployment $SERVICE_NAME -o yaml | grep -A10 tolerations"

0 commit comments

Comments
 (0)