github.com/imran-kn/cilium-fork@v1.6.9/contrib/k8s/k8s-heap-dump.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright 2018 Authors of Cilium
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -x
    18  
    19  trap cleanup EXIT
    20  
    21  TMPDIR=cilium-heap-$(date -u '+%Y%m%d-%H%M%S')
    22  mkdir -p $TMPDIR
    23  
    24  function cleanup {
    25  	rm -rf $TMPDIR
    26  }
    27  
    28  pods=$(kubectl -n kube-system get pods -l k8s-app=cilium | awk '{print $1}' | grep cilium)
    29  IFS=$'\r\n'
    30  for p in $pods; do
    31  	PROFILE=$(kubectl -n kube-system exec -ti $p -- gops pprof-heap 1)
    32  	PROFILE=$(echo $PROFILE | awk '{print $5}')
    33  	kubectl cp kube-system/$p:$PROFILE $TMPDIR/${p}_$(basename $PROFILE)
    34  done
    35  
    36  zip -r ${TMPDIR}.zip $TMPDIR