Skip to content
프로젝트

airwallex/k8s-pod-restart-info-collector

GitHub에서 보기

소개

Kubernetes Pod 문제를 자동으로 진단하고 K8s Pod의 재시작 원인, 로그, 이벤트를 수집합니다.

시스템 및 인프라

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
-1
in 7 days
-1
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

k8s-pod-restart-info-collector

k8s-pod-restart-info-collector is a simple K8s customer controller that watches for Pods changes and collects K8s Pod restart reasons, logs, and events to Slack channel when a Pod restarts.

For more information, see the blog on Medium: Automated Troubleshooting of Kubernetes (K8s) Pods Issues

This project is actively used and maintained by Airwallex DevOps team.

Overview of the Data Collected

Here are two Slack screenshots of the example messages.

Brief Alert Message

image

Detailed Alert Message

As shown below, by clicking “Show more”, we can see the Reason, “Pod Status”, “Pod Events”, “Node Status and Events”, and “Pod Logs Before Restart”.

image

How to test and develop locally

export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxxxx/xxxxx
go run .

Install using Helm

Replace the slackWebhookUrl, clusterName and slackChannel.

helm upgrade --install k8s-pod-restart-info-collector ./helm \
   --set slackWebhookUrl="https://hooks.slack.com/services/Change-Me" \
   --set clusterName="Change-Me" \
   --set slackChannel="Change-Me"

Check Commands:

# check commands
kubectl get pod,deploy,sa,secret -l app.kubernetes.io/instance=k8s-pod-restart-info-collector
helm status k8s-pod-restart-info-collector
helm get values k8s-pod-restart-info-collector
helm get manifest k8s-pod-restart-info-collector
helm get all k8s-pod-restart-info-collector
# see logs
kubectl logs deployment/k8s-pod-restart-info-collector -f

Run a debug-pod to verify the collector:

kubectl run debug-pod --image=alpine -- date;sleep 30
kubectl get pod debug-pod -w

Uninstall

To uninstall/delete the k8s-pod-restart-info-collector helm release:

helm uninstall k8s-pod-restart-info-collector

The command removes all the Kubernetes components associated with the chart and deletes the release.

Helm Parameters

Name Description Value
clusterName K8s cluster name (Display on slack message) required
slackUsername Slack username (Display on slack message) default: "k8s-pod-restart-info-collector"
slackChannel Slack channel name default: "restart-info-nonprod"
muteSeconds The time to mute duplicate pod alerts default: "600"
ignoreRestartCount The number of pod restart count to ignore default: "30"
ignoredNamespaces A set of namespaces to be ignored. This should be provided as a comma-separated list or a regular expression. default: ""
ignoredPodNamePrefixes A set of pod name prefixes to be ignored. This should be provided as a comma-separated list or a regular expression. default: ""
watchedNamespaces A set of namespaces to be watched. This should be provided as a comma-separated list or a regular expression. default: ""
watchedPodNamePrefixes A set of pod name prefixes to be watched. This should be provided as a comma-separated list or a regular expression. default: ""
ignoreRestartsWithExitCodeZero Whether restart events with an exit code of 0 should be ignored default: false
slackWebhookUrl Slack webhook URL required if slackWebhooUrlSecretKeyRef is not present
slackWebhookurlSecretKeyRef.key Slack webhook URL SecretKeyRef.key
slackWebhookurlSecretKeyRef.name Slack webhook URL SecretKeyRef.name

FAQ

  1. When will the collector send Pod restart messages to Slack channel?

    When a Pod restarts. However, if one of the following conditions is met, the messages are not sent.

    1. Pod restartCount > 30
    2. In the previous 10 minutes, the same Pod restart message was sent
  2. How to customize slack channel for each pods

    Adding alert-slack-channel: "your-slack-channel-name" to Pod annotations or labels. For example, a label: alert-slack-channel: "restart-info-nonprod"

How to write a K8s controller

Please refer to:

Copyright and license

Copyright [2022] [Airwallex (Hong Kong) Limited]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contribution

If you are interested in contributing, see CONTRIBUTION.md.

관련 프로젝트 살펴보기

불러오는 중…