Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kubectl debugを試してみた / k8snovice8-kubectl-debug

Naoki Oketani
February 08, 2021

kubectl debugを試してみた / k8snovice8-kubectl-debug

Naoki Oketani

February 08, 2021
Tweet

More Decks by Naoki Oketani

Other Decks in Technology

Transcript

  1. $ cat whoami.yaml social: github: oke-py twitter: ngoktanio job: role:

    Cloud Native Security Architect keyword: [“NIST SP 800-190”, “Sysdig”]
  2. デプロイを高速化する REPOSITORY TAG SIZE alpine latest 5.35MB ubuntu 18.04 56.7MB

    centos 7 301MB gcr.io/distroless/base-debian10 latest 16.1MB “Smaller image size reduces resource usage and speeds deployments.” [3][4]
  3. $ kubectl exec -it ephemeral-demo -- sh [2] OCI runtime

    exec failed: exec failed: container_linux.go:346: starting container process caused "exec: \"sh\": executable file not found in $PATH": unknown あ、”sh”が入っていなくてトラブルシューティングできない・・・ ここで、エフェメラルコンテナとkubectl debugの出番
  4. エフェメラルコンテナを利用する $ k run demo --image=k8s.gcr.io/pause:3.1 --restart=Never $ k debug

    -it demo --image=busybox # ps aux PID USER TIME COMMAND 1 root 0:00 sh 7 root 0:00 ps aux プロセスをみることができない Pod: demo Container pause EphemeralContainer busybox
  5. エフェメラルコンテナを利用する $ k run demo --image=k8s.gcr.io/pause:3.1 --restart=Never $ k debug

    -it demo --image=busybox --target=demo # ps aux PID USER TIME COMMAND 1 root 0:00 /pause 8 root 0:00 sh 15 root 0:00 ps aux Pod: demo Container pause EphemeralContainer busybox
  6. Podのコピーを利用する $ k run myapp --image=busybox --restart=Never -- sleep 1d

    $ k debug myapp -it --image=ubuntu --share-processes \ --copy-to=myapp-debug $ k get pod NAME READY ... myapp 1/1 myapp-debug 2/2 Pod: myapp-debug Container busybox Container ubuntu Pod: myapp Container busybox
  7. Nodeのデバッグをする $ k debug node/mynode -it --image=ubuntu “The container runs

    in the host IPC, Network, and PID namespaces. The root filesystem of the Node will be mounted at /host.” [2] 強力すぎてセキュリティおじさんはヒヤヒヤしてしまう マルチテナントクラスターでは使えるとまずいかも?
  8. reference [1] Ephemeral Containers https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/ [2] Debug Running Pods https://kubernetes.io/docs/tasks/debug-application-cluster/debug-running-pod/

    [3] KEP-277: Ephemeral Containers https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/277-ephemeral-containers [4] KEP-1441: kubectl debug https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1441-kubectl-debug [5] Update Ephemeral Containers KEP for beta in 1.21 https://github.com/kubernetes/enhancements/pull/2244