在Google Cloud Kubernetes部署Elasticsearch6遇CrashLoopBackOff故障求助
What's Causing the Crash?
Looking at your kubectl describe pod output, the key clue is the Exit Code: 137—this means your Elasticsearch container was killed by the Linux Out-of-Memory (OOM) Killer.
The f1-micro machine type only has ~614MB of total memory, and a chunk of that is already used by the Kubernetes node's OS and system processes. Elasticsearch defaults to a JVM heap size that's too large for this tiny instance, so the kernel kills the container as soon as it tries to allocate more memory than is available. That's why you're getting no logs—Elasticsearch doesn't even have time to start logging before it's terminated.
Step-by-Step Fixes
1. Tune Elasticsearch JVM Heap Size
First, limit the JVM heap memory Elasticsearch uses to fit within the node's available resources. Add the ES_JAVA_OPTS environment variable to your Pod spec to set a smaller heap (256MB is a safe start for f1-micro).
2. Set Kubernetes Resource Requests & Limits
Explicitly define memory/CPU requests and limits to ensure Kubernetes allocates enough resources to the container and prevents it from starving other processes.
Here's your updated pod.yml with both changes:
apiVersion: v1 kind: Pod metadata: name: test-elasticsearch labels: name: test-elasticsearch spec: containers: - image: launcher.gcr.io/google/elasticsearch6 name: elasticsearch env: - name: ES_JAVA_OPTS value: "-Xms256m -Xmx256m" resources: requests: memory: "512Mi" cpu: "200m" limits: memory: "512Mi" cpu: "500m"
3. (Better Long-Term Fix) Upgrade to a Larger Machine Type
If you plan to use Elasticsearch for anything beyond testing, f1-micro is way too under-resourced. Consider recreating your cluster with a larger machine type like g1-small (1.7GB memory) which will give Elasticsearch enough room to run without memory pressure:
gcloud container clusters create elasticsearch-cluster --machine-type=g1-small --num-nodes=3
How to Apply the Fix
- Delete the existing problematic Pod:
kubectl delete pod test-elasticsearch
- Apply the updated Pod spec:
kubectl create -f pod.yml
- Check the Pod status after a minute:
kubectl get pods
You should see the status change to Running once the container starts successfully.
内容的提问来源于stack exchange,提问作者Fabian

