Share
Embed
Deep Dive into Runtime Shim
moricho
August 22, 2020
Transcript
27 slides
-
01. Deep Dive into Runtime Shim ContainerRuntime Meetup #2 August
22, 2020 by @_moricho_ -
imageͷཧ (pull, rm, …) ίϯςφͷ͋Β ΏΔૢ࡞ΛΩοΫ͢Δ gRPCαʔϏε ࣮ࡍͷίϯςφૢ࡞ʹ ɺ
low level runtime (ޙड़) Λ༻ 05. High level runtime (CRI runtime) https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto Kubelet ͔Β CRI (Container Runtime Interface) Λ௨ͯ͠ݺΕΔ දతͳͷ container-d, cri-o ͳͲ -
06. High level runtime (CRI runtime) Kubelet ͔Β CRI (Container
Runtime Interface) Λ௨ͯ͠ݺΕΔ -
high level rutimeͷ໋ྩʹΑͬͯɺ ࣮ࡍʹίϯςφϓϩηεΛ࣮ߦ͢Δ෦ 07. Low level runtime (OCI runtime)
දతͳͷ runc, runsc (gVisor) ͳͲ ͨͩͷόΠφϦ state, create, start, kill, delete Λඋ͍͑ͯΔ opencontainers/runtime-specͷruntime.mdࢀর -
08. Low level runtime (OCI runtime) create࣌ʹɺcapability, hostname, mount, ,,,ͳ
Ͳίϯςφ࣮ߦʹඞཁͳใ͕ॻ͔Εͨ config.json ͕͞ΕΔ ৄࡉ opencontainers/runtime-spec ͷ config.md -
runcͷdetached modeͰͷىಈͷྫ (ӈਤ) low level runtimeίϯςφΛ্ཱͪ͛ͨΒ exitͯ͠͠·͏ ͦͯ͠ίϯςφdefaultͰhostͷinitϓϩηεʹ reparent͞ΕΔ(high
level runtime͔ΒΩοΫͨ͠ ߹ͦͪΒ) => ίϯςφϓϩηε(ݽࣇϓϩηε)͕ࢮΜͩ ͱ͖ʹ͍Εͳ͍ɺhigh level runtimeΛ࠶ىಈ ͨ͠Γఀࢭ͢Δͱίϯςφ·Ͱࢮ͵ 11. low level runtime Ͳ͜ʹ͍ͬͨʁ https://iximiuz.com/en/posts/implementing-container-runtime-shim/ runc container -
shim͕ low level runtime ΛΩοΫ low level runtime͕exitͨ͠ޙίϯςφͷ ໘Λݟͯ͘ΕΔ
ɾίϯςφcreate࣌ͷerror handling statusͷreport ɾίϯςφͷstdout/stderrΛϩάϑΝΠϧ stream ɾexitίʔυͷtrack ͜ΕΒΛhigh level runtimeͱڞ༗ 12. Runtime Shimͷׂ https://iximiuz.com/en/posts/implementing-container-runtime-shim/ runc shim -
16. Runtime Shimͷׂ ~subreaper~ low level runtime͕exit͢Δͱίϯςφϓϩηε͕hostͷinitϓϩηεʹreparent͞ΕΔ shimϓϩηεΛsubreaperͱ͢Δ͜ͱͰɺinitͰͳ͘shimϓϩηεʹreparent =>
shimϓϩηε͕ίϯςφͷexitΛtrackͯ͠ϑΝΠϧͳͲʹॻ͖ࠐΈɺ high level runtime͕ޙ͔Βࢀর͢Δ -
18. Runtime Shimͷׂ ~subreaper~ subreaperΛ͏ͱ ͱͷϓϩηε͔Β prctl(2) Λ “PR_SET_CHILD_SUBREAPER”
͜ͱҾʹ͠ ͯݺͿ ͜ͷϓϩηεͷࢠϓϩηεͦͷࢠଙʹ͢ ͯ”subreaper”ͷϚʔΫ͕༩͞ΕΔ ݽࣇϓϩηε͕ࢮΜͩ߹ => ࠷͍ۙઌͷ subreaper ϓϩηε ʹ”SIGCHLD”͕ૹΒΕɺwaitΛͬͯऴྃεςʔ λεΛΔ -
19. Runtime Shimͷׂ ~ίϯςφͷstdout/stderrͷอ࣋~ high level runtime͕࠶ىಈ/ఀࢭͯ͠ɺshim͕ίϯςφͷstdout/stderrͷstreamΛಛఆϑΝΠϧʹྲྀ͢ docker logs
kubectl logs Ͱ׆͖ͯ͘Δ Container Shim ϩά -
22. Runtime Shimͷׂ ~ίϯςφͷstdout/stderrͷอ࣋~ Container Shim ϩά kubectl logs <pod>
-c hoge kubelet High level -
23. Runtime Shimͷׂ ~ίϯςφͷstdout/stderrͷอ࣋~ Container Shim ϩά kubectl logs <pod>
-c hoge kubelet High level -
24. Wrap Up Runtime Shim ɾHigh/Low level runtime͕͞Ε͕͕ͪͩɺ͔ܽͤͳ͍ॏཁͳίϯϙʔωϯτ ɾLow level
runtimeίϯςφ࡞ͬͯૣʑexit => Shim͕໘ΛݟΔ ɾHigh level runtimeʹίϯςφʹؔ͢ΔใΛڞ༗ ɾ͋Μ·Γຊޠใམͪͯͳ͍ Φεεϝͷӳޠهࣄ: https://iximiuz.com/en/posts/implementing-container-runtime-shim/ minimamͳRuntime ShimΛRustͰ࣮͍ͯ͠Δ -
26. ࢀߟࢿྉ ɾImplementing Container Runtime Shim: runc https://iximiuz.com/en/posts/implementing-container-runtime-shim/ ɾDon’t Fear
the Subreaper https://medium.com/@william.la.martin/dont-fear-the-subreaper-19c8127c031e ɾDealing with process termination in Linux (with Rust examples) https://iximiuz.com/en/posts/dealing-with-processes-termination-in-Linux/#awaiting-a-grandchild-process-termination ɾprctl(2) — Linux manual page https://man7.org/linux/man-pages/man2/prctl.2.html