Sometimes, containers may fail to work properly after an exception occurs. If there is no sufficient information in the business log to help you identify the cause, you need to use coredump for further analysis. This document how to generate and save coredump for containers.
This document only applies to TKE clusters.
You have logged in to the TKE console.
Run the following command on the node to set the storage path format of the core file for the node:
# Run the following command on the node: echo "/tmp/cores/core.%h.%e.%p.%t" > /proc/sys/kernel/core_pattern
Main parameters are described as follows:
The complete path where the core file is generated is as follows:
After configuring the node, you need not modify the existing container configuration. The container configuration will automatically take effect through inheritance. If you require batch execution on multiple nodes, perform the corresponding operation accordingly:
To prevent the loss of the core file after the container restarts, you need to mount a volume for the container. As the cost of mounting an independent cloud disk for each pod is too high, you need to mount the component to COS. For the directions, see Installing the COS add-on.
Log in to the COS console, and manually create a COS bucket for storing the core file generated by the container coredump. In this document, a custom bucket named coredump is created as an example. For directions, see Creating a bucket.
You can choose any of the following three methods to create a Secret for accessing COS based on your needs:
kubectl create secret generic cos-secret -n kube-system --from-literal=SecretId=AKI*****************lV --from-literal=SecretKey=paQ9***************sZF
Remember to replace SecretId, SecretKey, and namespace.
To use the COS plug-in, you need to manually create a PV and PVC and then bind them.
This step creates a Deployment workload as an example.
/tmp/coresis used as an example.
You can create a Pod by using a YAML file. Below is a sample:
containers: - name: pod-cos command: ["tail", "-f", "/etc/hosts"] image: "centos:latest" volumeMounts: - mountPath: /tmp/cores name: core volumes: - name: core persistentVolumeClaim: # Replaced by your pvc name. claimName: coredump