• 市原 裕史
• LINE Corporation
• インフラプラットフォーム室 Verda2 Team
• Network Software Developer
• SDN/NFV
• OpenStack Neutron
• Docker
• Kubernetes
ABOUT ME
Slide 3
Slide 3 text
仮想計算機からコンテナへ
Server
VM
OS
Hyper Visor
VM VM
Server
OS
Container Container
Container Container
Server
OS
Process Process
1991年 Linux リリース
2010年 OpenStack リリース
2014年 Kubernetes リリース
OS OS OS
Slide 4
Slide 4 text
モノリシックからマイクロサービスへ
Process
機能A 機能B
機能C 機能D
Process
機能A
Process
機能C
Process
機能B
Process
機能D
Container
Container
Kubernetes Services 機能
仮想IPとサービスプロキシ
l user space proxy
l iptables proxy
l ipvs proxy
サービスディスカバリ
l DNS
サービスタイプ
l ClusterIP
l NodePort
l LoadBalancer
l ExternalName
https://kubernetes.io/docs/concepts/services-networking/service/
Pod
Pod
Pod
Service
PodのIPアドレスの変更
10.99.125.234:80 my-nginx Service (http)
Slide 22
Slide 22 text
ClusterIP どのように通信するのか?
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx ClusterIP 10.99.125.234 80/TCP 5h17m
$ ip a | grep "inet "
inet 127.0.0.1/8 scope host lo
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
inet 192.168.33.10/24 brd 192.168.33.255 scope global enp0s8
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
inet 10.244.0.1/24 scope global cni0
inet 10.244.0.0/32 scope global flannel.1
$ ip r
default via 10.0.2.2 dev enp0s3
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.244.0.0/24 dev cni0 proto kernel scope link src 10.244.0.1 linkdown
10.244.1.0/24 via 10.244.1.0 dev flannel.1 onlink
10.244.2.0/24 via 10.244.2.0 dev flannel.1 onlink
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.33.0/24 dev enp0s8 proto kernel scope link src 192.168.33.10
10.99.125.234 に疎通可能そうなネットワークインターフェースは⾒当たらない
Worker
iptablesによってパケットの書き換え
Worker
Pod
Worker
nginx Pod
10.244.1.4:80
nginx Pod
10.244.2.2:80
10.99.125.234
iptables
10.244.1.4
10.244.1.4
Slide 30
Slide 30 text
更に複雑な例
Network Policy
Slide 31
Slide 31 text
Pod へのクラスタ内外の通信のアクセス許可をコントロールする
Network Policy
Worker
Pod
Worker
Pod
Pod Pod
Pod Pod
https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy/
https://kubernetes.io/docs/concepts/services-networking/network-policies/
Network Policy 着信制限 結果
https://cloud.google.com/kubernetes-engine/docs/tutorials/network-policy
$ kubectl run -l app=foo --image=alpine --restart=Never --rm -i test-1 -- wget -qO- --timeout=2 http://hello-
web:8080
Hello, world!
Version: 1.0.0
Hostname: hello-web-76d4fc9f5b-c98kz
$ kubectl run -l app=bar --image=alpine --restart=Never --rm -i test-1 -- wget -qO- --timeout=2 http://hello-
web:8080
If you don't see a command prompt, try pressing enter.
wget: download timed out
pod default/test-1 terminated (Error)
label: app=hello
Worker1
hello-app
8080
Firewall
label: app=foo
label: app=bar
Client A
Client B
Slide 35
Slide 35 text
Network Policy 着信制限 iptables
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:K7cgKlec-rOcRZmV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:r0vz6Rgdk8ddL4bG" -m conntrack --ctstate INVALID -j DROP
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:ziYb2WzOoIMVstsP" -j MARK --set-xmark 0x0/0x1000000
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:8YswtCBJpM8NBzfl" -m comment --comment "Start of policies" -j MARK --set-
xmark 0x0/0x2000000
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:zmd0DgaOCBkFFlYd" -m mark --mark 0x0/0x2000000 -j cali-pi-
_6OJfcXg5T4SeuT6eE80
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:8dNeQcZoZeI9oNzW" -m comment --comment "Return if policy accepted" -m
mark --mark 0x1000000/0x1000000 -j RETURN
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:WAdLtw9Uyo9c3Vfi" -m comment --comment "Drop if no policies passed
packet" -m mark --mark 0x0/0x2000000 -j DROP
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:nvKHosQ-U2PISrW5" -j cali-pri-k8s_ns.default
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:ETIe11gXYxo1RL5F" -m comment --comment "Return if profile accepted" -m
mark --mark 0x1000000/0x1000000 -j RETURN
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:tp5L1HaKwMICs94e" -m comment --comment "Drop if no profiles matched" -j
DROP
Network Policy 適⽤後に追加されたルール
Slide 36
Slide 36 text
Network Policy 着信制限 iptables
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:K7cgKlec-rOcRZmV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:r0vz6Rgdk8ddL4bG" -m conntrack --ctstate INVALID -j DROP
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:ziYb2WzOoIMVstsP" -j MARK --set-xmark 0x0/0x1000000
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:8YswtCBJpM8NBzfl" -m comment --comment "Start of policies" -j MARK --set-
xmark 0x0/0x2000000
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:zmd0DgaOCBkFFlYd" -m mark --mark 0x0/0x2000000 -j cali-pi-
_6OJfcXg5T4SeuT6eE80
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:8dNeQcZoZeI9oNzW" -m comment --comment "Return if policy accepted" -m
mark --mark 0x1000000/0x1000000 -j RETURN
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:WAdLtw9Uyo9c3Vfi" -m comment --comment "Drop if no policies passed
packet" -m mark --mark 0x0/0x2000000 -j DROP
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:nvKHosQ-U2PISrW5" -j cali-pri-k8s_ns.default
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:ETIe11gXYxo1RL5F" -m comment --comment "Return if profile accepted" -m
mark --mark 0x1000000/0x1000000 -j RETURN
-A cali-tw-cali7e6f9a42eba -m comment --comment "cali:tp5L1HaKwMICs94e" -m comment --comment "Drop if no profiles matched" -j
DROP
Network Policy 適⽤後に追加されたルール
ジャンプ先の cali-pi-_6OJfcXg5T4SeuT6eE80 と
cali-pri-k8s_ns.default のどちらかで条件を満たせば通信許可
Slide 37
Slide 37 text
Network Policy 着信制限 iptables
-A cali-pi-_6OJfcXg5T4SeuT6eE80 -m comment --comment "cali:9Zdqkrk8NUVBY_ck" -m set --match-set cali4-
s:0Mv1nWHW09z0NgcXya-DCdb
src -j MARK --set-xmark 0x1000000/0x1000000
-A cali-pi-_6OJfcXg5T4SeuT6eE80 -m comment --comment "cali:dR3oD81dXG8jV32f" -m mark --mark 0x1000000/0x1000000 -j
RETURN
$ sudo toolbox ipset list cali4-s:0Mv1nWHW09z0NgcXya-DCdb
Spawning container root-gcr.io_google-containers_toolbox-20180309-00 on /var/lib/toolbox/root-gcr.io_google-containers_toolbox-
20180309-00.
Press ^] three times within 1s to kill container.
Name: cali4-s:0Mv1nWHW09z0NgcXya-DCdb
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 1048576
Size in memory: 136
References: 3
Number of entries: 1
Members:
10.48.1.16
ipset エントリ cali4-s:0Mv1nWHW09z0NgcXya-DCdb
に含まれる IP アドレスからの通信は許可のためのマーク
app=foo ラベルを持つ Pod の IP アドレスが登録されている