Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ephemeral_Containers_という謎の機能をk8sはどうやって実現しているのか.pdf
Search
yugo kobayashi
September 28, 2021
330
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ephemeral_Containers_という謎の機能をk8sはどうやって実現しているのか.pdf
yugo kobayashi
September 28, 2021
More Decks by yugo kobayashi
See All by yugo kobayashi
[k8sjp]KubeCon_NA_2023_Recap.pdf
koba1t
0
97
[k8sjp #56] Kustomize v5 を含む最新機能とテクニックの紹介
koba1t
2
12k
kustomizeのあまり知られていないが 便利な機能 (kustomize edit,create) の紹介
koba1t
0
3.6k
Recap: Customizing Kustomize with Client-Side Custom Resources
koba1t
0
350
CLE33
koba1t
0
80
カスタムコントローラは万能なのでアプリケーションを作るためにも使える
koba1t
1
740
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
280
Accessibility Awareness
sabderemane
1
210
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
How to Talk to Developers About Accessibility
jct
2
550
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
76k
Building the Perfect Custom Keyboard
takai
2
880
Practical Orchestrator
shlominoach
192
12k
Un-Boring Meetings
codingconduct
0
420
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Ethics towards AI in product and experience design
skipperchong
2
380
Transcript
Ephemeral Containers という docker にもない謎の機能を k8s はどうやって実現しているのか koba1t Kubernetes Meetup
Tokyo #45 LT
自己紹介 name: 小林優吾 github: koba1t twitter: 0x6b6f62 所属: ヤフー株式会社 2
Ephemeral Containersとは エフェメラルコンテナは、トラブルシューティングなどのユーザーが開始するアクションを実行 するために、すでに存在するPod内で一時的に実行するコンテナです。エフェメラルコンテナ は、アプリケーションの構築ではなく、serviceの調査のために利用します。 -- https://kubernetes.io/ja/docs/concepts/workloads/pods/ephemeral-containers/ --
[Demo] Ephemeral Containers
[Demo] Ephemeral Containers 参考: https://kubernetes.io/docs/tasks/debug-application-cluster/debug-running-pod/#ephemeral-container-example
Ephemeral Containersとは エフェメラルコンテナは、トラブルシューティングなどのユーザーが開始するアクションを実行 するために、すでに存在するPod内で一時的に実行するコンテナです。エフェメラルコンテナ は、アプリケーションの構築ではなく、serviceの調査のために利用します。 -- https://kubernetes.io/ja/docs/concepts/workloads/pods/ephemeral-containers/ -- - どうやって隔離されるはずのコンテナの越えてプロセスに触っているのか?
kubeletのコードを読みに行く 起点はkubelet内(kubelet/kuberuntime/kuberuntime_container.go)のコンテナ起動に利用される startContainer() https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container.go#L173 https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container.go#L208 この関数内でgetTargetID() が 有効な値を返すかでEphemeral Containerかそうでな いか区別している
https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container.go#L120 このgetTargetID() の戻り値 `target` が generateContainerConfig() の引数の一つに なる https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container.go#L215
kubeletのコードを読みに行く2 generateContainerConfig() で呼び出す applyPlatformSpecificContainerConfig()の 引数nsTargetになる https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container.go#L215 applyPlatformSpecificContainerConfig()は各プラットフォーム固有の処理をやってて、 linuxではgenerateLinuxContainerConfig()をそのまま実行してる https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container_linux.go#L59-L62 generateLinuxContainerConfig()内で
という感じにSecurityContext.NamespaceOptions でtargetのPIDを設定してる https://github.com/kubernetes/kubernetes/blob/v1.23.0-alpha.2/pkg/kubelet/kuberuntime/kuberuntime_container_linux.go#L59-L62
結局の所kubeletは何をしているか CRIへtargetとなるコンテナのPIDを追加して渡している
結局の所kubeletは何をしているか デバッグするターゲットコンテナと同じ PID Namespace にdebug 用コンテナを起動するというリクエストが CRI(Container Runtime Interface) のAPIに送られる
CRIへtargetとなるコンテナのPIDを追加して渡している
結局の所kubeletは何をしているか デバッグするターゲットコンテナと同じ PID Namespace にdebug 用コンテナを起動するというリクエストが CRI(Container Runtime Interface) のAPIに送られる
CRIへtargetとなるコンテナのPIDを追加して渡している 同じ PID Namespace で起動したら他のコンテナのプロセスに触れる?
None
None
None
None
Ephemeral Containersとは エフェメラルコンテナは、トラブルシューティングなどのユーザーが開始するアクションを実行 するために、すでに存在するPod内で一時的に実行するコンテナです。エフェメラルコンテナ は、アプリケーションの構築ではなく、serviceの調査のために利用します。 -- https://kubernetes.io/ja/docs/concepts/workloads/pods/ephemeral-containers/ -- - pod内に起動したとしてどうやってコンテナを越えてプロセスに触るの?
> 共通のPID Namespaceにプロセスを起動することで隔離されなくなる
余談 - ところで “PID Namespace” の設定は通常のPod定義で仕様できるのだろうか?
余談 - ところで “PID Namespace” の設定は通常のPod定義で利用できるのだろうか? CRIのAPI定義(LinuxContainerSecurityContext構造体内のNamespaceOptions)ではPID Namespaceを指定できるが、k8sのpod等で利用している core/v1 のContainer構造体定
義内の SecurityContext では指定できない。 https://pkg.go.dev/k8s.io/cri-api/pkg/apis/runtime/v1alpha2#LinuxContainerSecurityContext https://pkg.go.dev/k8s.io/api/core/v1#SecurityContext 内部的に使用する値のようで通常のPod定義には利用できそうにない
追記
dockerでも “pid” を指定するオプションがある Ephemeral Container と原理上は同じことができそう... https://docs.docker.com/engine/reference/commandline/container_run/
dockerでも似たようなことはできた...