配置livenessProbe与readinessProbe时无法创建指定文件,请求协助排查
/tmp/healthy File for Kubernetes Liveness/Readiness Probes Hey there, let's work through why your liveness probe is failing because it can't find /tmp/healthy—I've run into similar headaches before, so let's break this down step by step:
1. Confirm the touch Command Is Actually Running
First, let's make sure the command that creates your marker file is executing successfully:
- Pull your container logs to check for startup script errors:
If an earlier command in your startup script fails and exits, thekubectl logs <your-pod-name>touch /tmp/healthycommand might never get to run. Look for error messages that halt script execution. - Manually jump into the container to test the command directly:
If this fails, you'll see an explicit error (like permission denied) pointing to the root cause. Whilekubectl exec -it <your-pod-name> -- /bin/sh # Once inside, run these commands: touch /tmp/healthy ls /tmp/tmpis usually world-writable, some hardened images or PodsecurityContextsettings might restrict write access for non-root users.
2. Fix Probe Timing Mismatches
A super common issue is the probe checking too early before your container finishes initializing:
- Look at your probe's
initialDelaySecondsvalue. If it's set to a tiny number (like 0 or 1), the probe starts checking before yourtouchcommand has a chance to run. Try bumping this up to give your container time to set up—start with 30 seconds and adjust as needed:livenessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 30 periodSeconds: 10
3. Double-Check Paths for Typos
It sounds trivial, but typos are easy to miss! Verify:
- The path in your probe (
/tmp/healthy) matches exactly what's in yourtouchcommand. No mix-ups like/temp/healthy(a common typo between "tmp" and "temp"). - You're using absolute paths for both the
touchcommand and probe check. Relative paths can break if your container's working directory isn't what you expect.
4. Rule Out File Cleanup Processes
In some setups, cleanup scripts or sidecar containers might be deleting files in /tmp. If your Pod has multiple containers, check if any of them are modifying the /tmp directory. You can also temporarily add a sleep 60 after the touch command to see if the file exists briefly before being deleted.
内容的提问来源于stack exchange,提问作者morla

