1 of 8

Inspektor GadgetでKubernetesクラスタをデバッグしよう

2023/10/12 SRETT#7 satoken

2 of 8

k8sクラスタのデバッグ大変ですよね?

  • kubectlコマンドでがんばる
    • logs, describe
    • 適当なPod作ってデバッグ
  • Dashboardで色々追う
    • ログ、メトリクス、トレース、APM etc

© 2023 3-shake Inc.

2

3 of 8

Inspektor Gadget

  • eBPFを利用してk8sクラスタをデバッグするツール
  • CNCFのSandbox Projectsの1つ
  • krewでinstall
  • kubectl gadget ~ サブコマンドが使えるようになる

© 2023 3-shake Inc.

3

4 of 8

Inspektor Gadgetの仕組み

  • gadget deployコマンドでDaemonSetをインストール
  • DaemonSetがNodeのカーネルにeBPFプログラムを接続し様々な情報を取得

© 2023 3-shake Inc.

4

5 of 8

gadgetコマンド

$ kubectl gadget -h

Collection of gadgets for Kubernetes developers

Usage:

kubectl-gadget [command]

Available Commands:

advise Recommend system configurations based on collected information

audit Audit a subsystem

completion Generate the autocompletion script for the specified shell

deploy Deploy Inspektor Gadget on the cluster

help Help about any command

profile Profile different subsystems

prometheus Expose metrics using prometheus

script Run a bpftrace-compatible scripts

snapshot Take a snapshot of a subsystem and print it

sync Synchronize gadget information with your cluster

top Gather, sort and periodically report events according to a given criteria

trace Trace and print system events

traceloop Get strace-like logs of a container from the past

undeploy Undeploy Inspektor Gadget from cluster

version Show version

© 2023 3-shake Inc.

5

6 of 8

gadget traceコマンド

$ kubectl gadget trace -h

Trace and print system events

Usage:

kubectl-gadget trace [command]

Available Commands:

bind Trace socket bindings

capabilities Trace security capability checks

dns Trace DNS requests

exec Trace new processes

fsslower Trace open, read, write and fsync operations slower than a threshold

mount Trace mount and umount system calls

network Trace network streams

oomkill Trace when OOM killer is triggered and kills a process

open Trace open system calls

signal Trace signals received by processes

sni Trace Server Name Indication (SNI) from TLS requests

tcp Trace TCP connect, accept and close

tcpconnect Trace connect system calls

tcpdrop Trace TCP kernel-dropped packets/segments

tcpretrans Trace TCP retransmissions

ネットワークやプロセス

などいろいろなイベント

をトレース

© 2023 3-shake Inc.

6

7 of 8

gadget adviseコマンド

$ kubectl gadget advise -h

Recommend system configurations based on collected information

Usage:

kubectl-gadget advise [command]

Available Commands:

network-policy Generate network policies based on recorded network activity

seccomp-profile Generate seccomp profiles based on recorded syscalls activity

Network Policyやseccompの

ファイルを生成してくれる

© 2023 3-shake Inc.

7

8 of 8

あらかじめQA

  • IaCは?
  • 本番投入していますか?
    • していません。個人的に追っている&遊んでる状態
    • 特権のDaemonSetが立つという性質上、誰に使わせるなどルール決めが必要
      • eBPFのverifyがあるとはいえgadget scriptで任意のコード実行できるので
    • 奥の手として使うのはありかも
      • Inspektor GadgetのBlogにトラシューの実例が乗ってます
  • 興味があればお試しください、おしまい

© 2023 3-shake Inc.

8