48 lines
1.4 KiB
Bash
Executable File
48 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to fix "too many open files" error in Kubernetes
|
|
# This error occurs when the system hits inotify limits
|
|
|
|
echo "Fixing inotify limits for Kubernetes..."
|
|
|
|
# Check current inotify limits
|
|
echo "Current inotify limits:"
|
|
sysctl fs.inotify.max_user_watches
|
|
sysctl fs.inotify.max_user_instances
|
|
sysctl fs.inotify.max_queued_events
|
|
|
|
echo ""
|
|
echo "Increasing inotify limits..."
|
|
|
|
# Increase inotify limits (temporary - lasts until reboot)
|
|
sudo sysctl -w fs.inotify.max_user_watches=524288
|
|
sudo sysctl -w fs.inotify.max_user_instances=1024
|
|
sudo sysctl -w fs.inotify.max_queued_events=16384
|
|
|
|
# Verify the changes
|
|
echo ""
|
|
echo "New inotify limits:"
|
|
sysctl fs.inotify.max_user_watches
|
|
sysctl fs.inotify.max_user_instances
|
|
sysctl fs.inotify.max_queued_events
|
|
|
|
echo ""
|
|
echo "For permanent fix, add these lines to /etc/sysctl.conf:"
|
|
echo "fs.inotify.max_user_watches=524288"
|
|
echo "fs.inotify.max_user_instances=1024"
|
|
echo "fs.inotify.max_queued_events=16384"
|
|
echo ""
|
|
echo "Then run: sudo sysctl -p"
|
|
|
|
echo ""
|
|
echo "If you're using Docker Desktop or Kind, you may need to:"
|
|
echo "1. Restart Docker Desktop"
|
|
echo "2. Or for Kind: kind delete cluster && kind create cluster"
|
|
echo "3. Or adjust the node's system limits directly"
|
|
|
|
echo ""
|
|
echo "For production environments, consider adding these limits to your deployment:"
|
|
echo "securityContext:"
|
|
echo " runAsUser: 1000"
|
|
echo " runAsGroup: 1000"
|
|
echo " fsGroup: 1000" |