rabbit-slide-unasuke-container_runtime_meetup_1 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rabbit +1 -0
- data/README.md +24 -0
- data/Rakefile +17 -0
- data/config.yaml +21 -0
- data/img/esa-wip.png +0 -0
- data/img/git_grep_notify_socket_moby.png +0 -0
- data/img/icon_raw.jpg +0 -0
- data/img/ps_forest.png +0 -0
- data/img/ss_grep_container.png +0 -0
- data/img/udzura_tweet.png +0 -0
- data/pdf/container_runtime_meetup_1-slide.pdf +0 -0
- data/slide.md +237 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3be33b1b1fa33a21e6ef1bc48912086d202cdc20429e6f0813bea3c66ee4018
|
4
|
+
data.tar.gz: d8fa5a432ea8c8193f0ac67d15067bf0a58ad927abddbeaa939dea8ba20eb5be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ac72f539f33d7b6ddccdc52fcaca2182ea93891611f98b4894740092dc06119ae2ccc42a136f09431a6f1f2574f71afbed6af77a5c44c75f3ceb25db7a33cc3
|
7
|
+
data.tar.gz: 3a61bd4c809817c9842952daf9fabe705ca605a96df8fea03147406995cb98706af05c1816880f42949dfc4e4234767e944a7f9b51779032db327413143b02a8
|
data/.rabbit
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
slide.md
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Container Runtime Meetup #1
|
2
|
+
|
3
|
+
https://runtime.connpass.com/event/145088/
|
4
|
+
|
5
|
+
## 作者向け
|
6
|
+
|
7
|
+
### 表示
|
8
|
+
|
9
|
+
rake
|
10
|
+
|
11
|
+
### 公開
|
12
|
+
|
13
|
+
rake publish
|
14
|
+
|
15
|
+
## 閲覧者向け
|
16
|
+
|
17
|
+
### インストール
|
18
|
+
|
19
|
+
gem install rabbit-slide-unasuke-container_runtime_meetup_1
|
20
|
+
|
21
|
+
### 表示
|
22
|
+
|
23
|
+
rabbit rabbit-slide-unasuke-container_runtime_meetup_1.gem
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rabbit/task/slide"
|
2
|
+
|
3
|
+
# Edit ./config.yaml to customize meta data
|
4
|
+
|
5
|
+
spec = nil
|
6
|
+
Rabbit::Task::Slide.new do |task|
|
7
|
+
spec = task.spec
|
8
|
+
# spec.files += Dir.glob("doc/**/*.*")
|
9
|
+
# spec.files -= Dir.glob("private/**/*.*")
|
10
|
+
# spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Tag #{spec.version}"
|
14
|
+
task :tag do
|
15
|
+
sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
|
16
|
+
sh("git", "push", "--tags")
|
17
|
+
end
|
data/config.yaml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
id: container_runtime_meetup_1
|
3
|
+
base_name: slide
|
4
|
+
tags: ['container', 'runc', 'docker']
|
5
|
+
presentation_date: 2019-09-24
|
6
|
+
presentation_start_time:
|
7
|
+
presentation_end_time:
|
8
|
+
version: 1.0.0
|
9
|
+
licenses: []
|
10
|
+
slideshare_id:
|
11
|
+
speaker_deck_id:
|
12
|
+
ustream_id:
|
13
|
+
vimeo_id:
|
14
|
+
youtube_id:
|
15
|
+
author:
|
16
|
+
markup_language: :markdown
|
17
|
+
name: unasuke
|
18
|
+
email: yusuke1994525@gmail.com
|
19
|
+
rubygems_user: unasuke
|
20
|
+
slideshare_user:
|
21
|
+
speaker_deck_user:
|
data/img/esa-wip.png
ADDED
Binary file
|
Binary file
|
data/img/icon_raw.jpg
ADDED
Binary file
|
data/img/ps_forest.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/slide.md
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
# NOTIFY_SOCKET\\n環境変数について
|
2
|
+
subtitle
|
3
|
+
: 2019-09-24
|
4
|
+
|
5
|
+
subtitle
|
6
|
+
: Container Runtime Meetup #1
|
7
|
+
|
8
|
+
author
|
9
|
+
: うなすけ
|
10
|
+
|
11
|
+
theme
|
12
|
+
: unasuke-white
|
13
|
+
|
14
|
+
# 自己紹介
|
15
|
+
- 名前 : うなすけ
|
16
|
+
- 仕事 : 株式会社バンク (業務委託)
|
17
|
+
- インフラ寄りサーバーサイドエンジニア
|
18
|
+
- Ruby, Rails, Kubernetes...
|
19
|
+
|
20
|
+
- {::tag name="x-small"}GitHub [@unasuke](https://github.com/unasuke){:/tag}
|
21
|
+
- {::tag name="x-small"}Mastodon [@unasuke@mstdn.unasuke.com](https://mstdn.unasuke.com/@unasuke){:/tag}
|
22
|
+
- {::tag name="x-small"}Twitter [@yu\_suke1994](https://twitter.com/yu_suke1994){:/tag}
|
23
|
+
|
24
|
+
![](img/icon_raw.jpg){:relative_width="24" align="right" relative_margin_right="-10" relative_margin_top="42"}
|
25
|
+
|
26
|
+
# Excuse (僕の実力について)
|
27
|
+
- Railsでweb API を作ってて、「コンテナ?便利じゃん〜」くらいのレベルの開発者
|
28
|
+
- image-specは読んだことがあります
|
29
|
+
- @udzuraさんにそそのかされて来ました
|
30
|
+
- <https://twitter.com/udzura/status/1166345876769394689>
|
31
|
+
|
32
|
+
![](img/udzura_tweet.png){:relative_width="80"}
|
33
|
+
|
34
|
+
# 調査する対象を決めるまで
|
35
|
+
![](https://img.esa.io/uploads/production/attachments/11214/2019/09/23/3132/e0316fda-c78e-48eb-b86b-5704c2652c48.png){:relative_width="90"}
|
36
|
+
|
37
|
+
<https://runtime.connpass.com/event/145088>
|
38
|
+
|
39
|
+
# 調査する対象を決めるまで
|
40
|
+
とりあえず最新リリースを読む対象にするじゃないですか
|
41
|
+
|
42
|
+
<https://github.com/opencontainers/runc/releases/tag/v1.0.0-rc8>
|
43
|
+
|
44
|
+
# 調査する対象を決めるまで
|
45
|
+
```go
|
46
|
+
status, err := startContainer(context, spec, CT_ACT_RUN, nil)
|
47
|
+
```
|
48
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/run.go#L76>
|
49
|
+
|
50
|
+
ああなんかこの辺でContainerが起動するんだな
|
51
|
+
|
52
|
+
# 調査する対象を決めるまで
|
53
|
+
```go
|
54
|
+
notifySocket := newNotifySocket(context, os.Getenv("NOTIFY_SOCKET"), id)
|
55
|
+
if notifySocket != nil {
|
56
|
+
notifySocket.setupSpec(context, spec)
|
57
|
+
}
|
58
|
+
```
|
59
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/utils_linux.go#L411-L414>
|
60
|
+
|
61
|
+
`NOTIFY_SOCKET` ← これなに?
|
62
|
+
|
63
|
+
# 調査する対象を決めるまで
|
64
|
+
この時点での認識
|
65
|
+
|
66
|
+
> 「環境変数がある状態で起動させると色々な通知が飛んでくるのだろうか?」
|
67
|
+
|
68
|
+
# Dive into code
|
69
|
+
```go
|
70
|
+
func newNotifySocket(context *cli.Context, notifySocketHost string, id string) *notifySocket {
|
71
|
+
if notifySocketHost == "" {
|
72
|
+
return nil
|
73
|
+
}
|
74
|
+
|
75
|
+
root := filepath.Join(context.GlobalString("root"), id)
|
76
|
+
path := filepath.Join(root, "notify.sock")
|
77
|
+
|
78
|
+
notifySocket := ¬ifySocket{
|
79
|
+
socket: nil,
|
80
|
+
host: notifySocketHost,
|
81
|
+
socketPath: path,
|
82
|
+
}
|
83
|
+
|
84
|
+
return notifySocket
|
85
|
+
}
|
86
|
+
```
|
87
|
+
`notifySocket`のインスタンスはここで生成される
|
88
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/notify_socket.go#L23-L38>
|
89
|
+
|
90
|
+
# Dive into code
|
91
|
+
```go
|
92
|
+
func newNotifySocket(context *cli.Context, notifySocketHost string, id string)
|
93
|
+
```
|
94
|
+
|
95
|
+
このcontext は <https://godoc.org/github.com/urfave/cli#Context> を指す
|
96
|
+
|
97
|
+
なので `/tmpfs/[container-id]/notify.sock` があるはず
|
98
|
+
|
99
|
+
# Dive into code
|
100
|
+
```go
|
101
|
+
func (s *notifySocket) setupSpec(context *cli.Context, spec *specs.Spec) {
|
102
|
+
mount := specs.Mount{Destination: s.host, Source: s.socketPath, Options: []string{"bind"}}
|
103
|
+
spec.Mounts = append(spec.Mounts, mount)
|
104
|
+
spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("NOTIFY_SOCKET=%s", s.host))
|
105
|
+
}
|
106
|
+
```
|
107
|
+
直後に`setupSpec`を呼んでいる
|
108
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/notify_socket.go#L44-L50>
|
109
|
+
|
110
|
+
# Dive into code
|
111
|
+
> If systemd is supporting sd_notify protocol, this function will add support for sd_notify protocol from within the container.
|
112
|
+
|
113
|
+
なるほどsystemd?
|
114
|
+
|
115
|
+
まあなんか色々やってるんだな (runtime-specのMountあたり)
|
116
|
+
|
117
|
+
# Dive into code
|
118
|
+
```go
|
119
|
+
func (s *notifySocket) setupSocket() error {
|
120
|
+
addr := net.UnixAddr{
|
121
|
+
Name: s.socketPath,
|
122
|
+
Net: "unixgram",
|
123
|
+
}
|
124
|
+
```
|
125
|
+
|
126
|
+
`createContainer`後にsetupSocketが呼ばれる
|
127
|
+
|
128
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/notify_socket.go#L52-L56>
|
129
|
+
|
130
|
+
# Dive into code
|
131
|
+
<https://golang.org/pkg/net/#UnixAddr>
|
132
|
+
|
133
|
+
```go
|
134
|
+
type UnixAddr struct {
|
135
|
+
Name string
|
136
|
+
Net string
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
`unixgram` ← datagram socket (UDP的な送りっぱなしのプロトコル)
|
141
|
+
<https://github.com/golang/go/blob/master/src/net/unixsock_posix.go#L16-L27>
|
142
|
+
|
143
|
+
# Dive into code
|
144
|
+
> ListenUnixgram acts like ListenPacket for Unix networks.
|
145
|
+
<https://golang.org/pkg/net/#ListenUnixgram>
|
146
|
+
|
147
|
+
connectionを張るっぽい
|
148
|
+
|
149
|
+
そして `runner` 構造体の `notifySocket` field に`notifySocket` 構造体のインスタンスが格納される
|
150
|
+
|
151
|
+
# runner.run の中で……
|
152
|
+
```go
|
153
|
+
// Setting up IO is a two stage process. We need to modify process to deal
|
154
|
+
// with detaching containers, and then we get a tty after the container has
|
155
|
+
// started.
|
156
|
+
handler := newSignalHandler(r.enableSubreaper, r.notifySocket)
|
157
|
+
```
|
158
|
+
|
159
|
+
SignalHandlerを作成している
|
160
|
+
<https://github.com/opencontainers/runc/blob/v1.0.0-rc8/utils_linux.go#L305-L308>
|
161
|
+
|
162
|
+
# ここまで
|
163
|
+
- `NOTIFY_SOCKET` という環境変数をもとにsoket通信をしている?
|
164
|
+
- これは `unixgram` によって通信するもの
|
165
|
+
- systemd が何か関係しているようだ
|
166
|
+
|
167
|
+
# `NOTIFY_SOCKET` をググる
|
168
|
+
- <https://www.freedesktop.org/software/systemd/man/sd_notify.html#Notes>
|
169
|
+
- [sd_notifyの通信方法 - Qiita](https://qiita.com/ozaki-r/items/ced43d5e32af67c7ae04)
|
170
|
+
- [systemd(1) — Arch Linux マニュアルページ](https://man.kusakata.com/man/systemd.1.html)
|
171
|
+
|
172
|
+
# freedesktop.org
|
173
|
+
> These functions send a single datagram with the state string as payload to the AF_UNIX socket referenced in the $NOTIFY_SOCKET environment variable. If the first character of $NOTIFY_SOCKET is "@", the string is understood as Linux abstract namespace socket.
|
174
|
+
|
175
|
+
<https://www.freedesktop.org/software/systemd/man/sd_notify.html#Notes>
|
176
|
+
|
177
|
+
# sd_notifyの通信方法 - Qiita
|
178
|
+
> systemdのマネージャ(デーモンプロセス)は、起動プロセスの最後の方でsd_notifyという関数を用いて、起動が完了したことをsystemd本体(PID=1)に通知する。(注:sd_notifyは実際にはもっと汎用的なステータス通知に使える。)
|
179
|
+
|
180
|
+
<https://qiita.com/ozaki-r/items/ced43d5e32af67c7ae04>
|
181
|
+
|
182
|
+
# なるほどね
|
183
|
+
じゃあ、例えばDockerでも使われてるんだろうか?
|
184
|
+
|
185
|
+
# Dockerではどうか
|
186
|
+
<https://github.com/docker/cli> にはない
|
187
|
+
|
188
|
+
と思ったら <https://github.com/moby/moby> にはあった
|
189
|
+
|
190
|
+
# Dockerでの `NOTIFY_SOCKET`
|
191
|
+
`$ git grep NOTIFY_SOCKET`
|
192
|
+
|
193
|
+
![](img/git_grep_notify_socket_moby.png){:relative_width="100"}
|
194
|
+
|
195
|
+
ある
|
196
|
+
|
197
|
+
# 手元のマシンでそれっぽいものが作成されているのか?
|
198
|
+
```shell
|
199
|
+
$ ss --family=unix | grep systemd | wc -l
|
200
|
+
110
|
201
|
+
```
|
202
|
+
|
203
|
+
👀
|
204
|
+
|
205
|
+
# 手元のマシンでそれっぽいものが作成されているのか?
|
206
|
+
`$ ss --family=unix | grep container`
|
207
|
+
|
208
|
+
![](img/ss_grep_container.png){:relative_width="90"}
|
209
|
+
|
210
|
+
なんかおる
|
211
|
+
|
212
|
+
# 手元のマシンでそれっぽいものが作成されているのか?
|
213
|
+
`$ ps aux --forest`
|
214
|
+
|
215
|
+
![](img/ps_forest.png){:relative_width="100"}
|
216
|
+
|
217
|
+
# 環境変数を覗いてみる
|
218
|
+
dockerdの環境変数
|
219
|
+
|
220
|
+
```shell
|
221
|
+
$ sudo cat /proc/601/environ
|
222
|
+
LANG=ja_JP.UTF-8
|
223
|
+
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin
|
224
|
+
NOTIFY_SOCKET=/run/systemd/notify
|
225
|
+
LISTEN_PID=601
|
226
|
+
LISTEN_FDS=1
|
227
|
+
LISTEN_FDNAMES=docker.socket
|
228
|
+
INVOCATION_ID=e65738cc4b8f461e968d23c6740a557e
|
229
|
+
JOURNAL_STREAM=9:22835
|
230
|
+
```
|
231
|
+
|
232
|
+
# まとめと今後の目標
|
233
|
+
- `NOTIFY_SOCKET` でsystemdとやりとりしているようだ
|
234
|
+
- `dockerd` には `NOTIFY_SOCKET` が与えられていることが確認できた
|
235
|
+
- `runc run` を実行したときにもこれは与えられるのか?
|
236
|
+
- 実際にどのようなデータがどのようなタイミングで送られるのか?
|
237
|
+
- dockerでは? runcでは?他では?
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbit-slide-unasuke-container_runtime_meetup_1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- unasuke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rabbit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
description: https://runtime.connpass.com/event/145088/
|
28
|
+
email:
|
29
|
+
- yusuke1994525@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rabbit"
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- config.yaml
|
38
|
+
- img/esa-wip.png
|
39
|
+
- img/git_grep_notify_socket_moby.png
|
40
|
+
- img/icon_raw.jpg
|
41
|
+
- img/ps_forest.png
|
42
|
+
- img/ss_grep_container.png
|
43
|
+
- img/udzura_tweet.png
|
44
|
+
- pdf/container_runtime_meetup_1-slide.pdf
|
45
|
+
- slide.md
|
46
|
+
homepage: https://slide.rabbit-shocker.org/authors/unasuke/container_runtime_meetup_1/
|
47
|
+
licenses: []
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.0.3
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: 'Container Runtime Meetup #1'
|
68
|
+
test_files: []
|