Skip to content

Instructions for getting coredumps in Kubernetes

Hugo Denizart edited this page Aug 19, 2022 · 2 revisions

Instructions for doing coredumps in DigitalOcean Kubernetes

  1. From your computer, get into a node as root using nsenter_node.sh:
#!/bin/sh
set -x

node=${1}
nodeName=$(kubectl get node ${node} -o template --template='{{index .metadata.labels "kubernetes.io/hostname"}}') 
nodeSelector='"nodeSelector": { "kubernetes.io/hostname": "'${nodeName:?}'" },'
podName=${USER}-nsenter-${node}

kubectl run ${podName:?} --restart=Never -it --rm --image overriden --overrides '
{
  "spec": {
    "hostPID": true,
    "hostNetwork": true,
    '"${nodeSelector?}"'
    "tolerations": [{
        "operator": "Exists"
    }],
    "containers": [
      {
        "name": "nsenter",
        "image": "alexeiled/nsenter:2.34",
        "command": [
          "/nsenter", "--all", "--target=1", "--", "su", "-"
        ],
        "stdin": true,
        "tty": true,
        "securityContext": {
          "privileged": true
        }
      }
    ]
  }
}' --attach "$@"

eg. ./nsenter_node.sh pool-default-gp-4-csih3

  1. before touching anything in the remote shell, note down the default values of ulimit -c and /proc/sys/kernel/core_pattern

  2. enable coredumps:
    ulimit -c unlimited

  3. set-up s3fs; see https://github.com/s3fs-fuse/s3fs-fuse. follow ubuntu/debian install instructions and mounting instructions for 3rd-party S3 providers

  4. create dump script in /dump.sh:

#!/bin/sh

cat - > /mountpoint/coredump
  1. instruct the system to use that script for writing coredump:
    echo "|/dump.sh" > /proc/sys/kernel/core_pattern

  2. kill -SEGV <pid> where pid is pid from the host, not from the container namespace! run ps -aux or top from the host, not from the container shells!

  3. revert things back as they were; for do-kube-1.21.11-do.1:
    ulimit -c 0
    echo "core" > /proc/sys/kernel/core_pattern