【k8s系列】(202301) gvisor安装与containerd集成

安装

安装地址:Installation - gVisor

1
2
3
4
5
6
7
8
9
10
ARCH=$(uname -m)
URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}
wget ${URL}/runsc ${URL}/runsc.sha512 \
${URL}/containerd-shim-runsc-v1 ${URL}/containerd-shim-runsc-v1.sha512
sha512sum -c runsc.sha512 \
-c containerd-shim-runsc-v1.sha512
rm -f *.sha512
chmod a+rx runsc containerd-shim-runsc-v1
sudo mv runsc containerd-shim-runsc-v1 /usr/local/bin

与containerd集成

下发runtimeclass资源

1
2
3
4
5
6
7
8
9
10
11
root@node01:~# cat rc.yaml
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: untrusted
handler: runsc
root@node01:~# kubectl apply -f rc.yaml
root@node01:~# kubectl get runtimeclass
NAME HANDLER AGE
untrusted runsc 7m34s

修改containerd配置文件

1
vim /etc/containerd/config.toml

增加

1
2
3
# gVisor: https://gvisor.dev/
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc]
runtime_type = "io.containerd.runsc.v1"

image.png

1
2
# 重启containerd
root@node01:~# systemctl restart containerd

准备pod的yaml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
root@node01:~# kubectl run nginx-gvisor --image=nginx --dry-run=client -oyaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-gvisor
name: nginx-gvisor
spec:
containers:
- image: nginx
name: nginx-gvisor
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}

root@node01:~# kubectl run nginx-gvisor --image=nginx --dry-run=client -oyaml > nginx-gvisor.yaml


## 稍加修改,最终如下
root@node01:~# cat nginx-gvisor.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-gvisor
spec:
runtimeClassName: untrusted
containers:
- image: nginx
name: nginx-gvisor

root@node01:~# kubectl apply -f nginx-gvisor.yaml

root@node01:~# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-gvisor 1/1 Running 0 8m3s

成了~

参考资料

### Kubernetes 最小化微服务漏洞 gVisor与Containerd集成


【k8s系列】(202301) gvisor安装与containerd集成
http://example.com/2023/01/11/k8s/【k8s系列】(202301) gvisor安装与containerd集成/
作者
ningan123
发布于
2023年1月11日
许可协议