-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gVisor: initial support for gVisor container runtime
- Loading branch information
1 parent
e59f0bc
commit 7c3e766
Showing
18 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# gVisor | ||
|
||
[gVisor](https://gvisor.dev/docs/) is an application kernel, written in Go, that implements a substantial portion of the Linux system call interface. It provides an additional layer of isolation between running applications and the host operating system. | ||
|
||
gVisor includes an Open Container Initiative (OCI) runtime called runsc that makes it easy to work with existing container tooling. The runsc runtime integrates with Docker and Kubernetes, making it simple to run sandboxed containers. | ||
|
||
## Usage | ||
|
||
To enable gVisor you should be using a container manager that is compatible with selecting the [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) such as `containerd`. | ||
|
||
Containerd support: | ||
|
||
```yaml | ||
container_manager: containerd | ||
gvisor_enabled: true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
roles/container-engine/gvisor/molecule/default/converge.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: true | ||
vars: | ||
gvisor_enabled: true | ||
container_manager: containerd | ||
roles: | ||
- role: kubespray-defaults | ||
- role: containerd | ||
- role: gvisor |
17 changes: 17 additions & 0 deletions
17
roles/container-engine/gvisor/molecule/default/files/10-mynet.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"cniVersion": "0.2.0", | ||
"name": "mynet", | ||
"type": "bridge", | ||
"bridge": "cni0", | ||
"isGateway": true, | ||
"ipMasq": true, | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "172.19.0.0/24", | ||
"routes": [ | ||
{ | ||
"dst": "0.0.0.0/0" | ||
} | ||
] | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
roles/container-engine/gvisor/molecule/default/files/container.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"metadata": { | ||
"name": "gvisor1" | ||
}, | ||
"image": { | ||
"image": "docker.io/library/hello-world:latest" | ||
}, | ||
"log_path": "gvisor1.0.log", | ||
"linux": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
roles/container-engine/gvisor/molecule/default/files/sandbox.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"metadata": { | ||
"name": "gvisor1", | ||
"namespace": "default", | ||
"attempt": 1, | ||
"uid": "hdishd83djaidwnduwk28bcsb" | ||
}, | ||
"linux": {}, | ||
"log_directory": "/tmp" | ||
} |
44 changes: 44 additions & 0 deletions
44
roles/container-engine/gvisor/molecule/default/molecule.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
driver: | ||
name: vagrant | ||
provider: | ||
name: libvirt | ||
options: | ||
driver: kvm | ||
lint: | | ||
set -e | ||
yamllint -c ../../../.yamllint . | ||
platforms: | ||
- name: ubuntu20 | ||
box: generic/ubuntu2004 | ||
cpus: 1 | ||
memory: 1024 | ||
nested: true | ||
groups: | ||
- kube_control_plane | ||
- name: centos8 | ||
box: generic/centos8 | ||
cpus: 1 | ||
memory: 1024 | ||
nested: true | ||
groups: | ||
- kube_control_plane | ||
provisioner: | ||
name: ansible | ||
env: | ||
ANSIBLE_ROLES_PATH: ../../../../ | ||
config_options: | ||
defaults: | ||
callback_whitelist: profile_tasks | ||
lint: | ||
name: ansible-lint | ||
options: | ||
c: ../../../.ansible-lint | ||
inventory: | ||
group_vars: | ||
all: | ||
become: true | ||
verifier: | ||
name: testinfra | ||
lint: | ||
name: flake8 |
48 changes: 48 additions & 0 deletions
48
roles/container-engine/gvisor/molecule/default/prepare.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
- name: Prepare generic | ||
hosts: all | ||
become: true | ||
roles: | ||
- role: kubespray-defaults | ||
- role: bootstrap-os | ||
- role: ../adduser | ||
user: "{{ addusers.kube }}" | ||
tasks: | ||
- include_tasks: "../../../../download/tasks/download_file.yml" | ||
vars: | ||
download: "{{ download_defaults | combine(downloads.cni) }}" | ||
|
||
- name: Prepare container runtime | ||
hosts: all | ||
become: true | ||
vars: | ||
container_manager: containerd | ||
kube_network_plugin: cni | ||
roles: | ||
- role: kubespray-defaults | ||
- role: ../network_plugin/cni | ||
- role: crictl | ||
tasks: | ||
- name: Copy test container files | ||
copy: | ||
src: "{{ item }}" | ||
dest: "/tmp/{{ item }}" | ||
owner: root | ||
mode: 0644 | ||
with_items: | ||
- container.json | ||
- sandbox.json | ||
- name: Create /etc/cni/net.d directory | ||
file: | ||
path: /etc/cni/net.d | ||
state: directory | ||
owner: kube | ||
mode: 0755 | ||
- name: Setup CNI | ||
copy: | ||
src: "{{ item }}" | ||
dest: "/etc/cni/net.d/{{ item }}" | ||
owner: root | ||
mode: 0644 | ||
with_items: | ||
- 10-mynet.conf |
29 changes: 29 additions & 0 deletions
29
roles/container-engine/gvisor/molecule/default/tests/test_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
|
||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | ||
|
||
|
||
def test_run(host): | ||
gvisorruntime = "/usr/local/bin/runsc" | ||
with host.sudo(): | ||
cmd = host.command(gvisorruntime + " --version") | ||
assert cmd.rc == 0 | ||
assert "runsc version" in cmd.stdout | ||
|
||
|
||
def test_run_pod(host): | ||
runtime = "runsc" | ||
|
||
run_command = "/usr/local/bin/crictl run --with-pull --runtime {} /tmp/container.json /tmp/sandbox.json".format(runtime) | ||
with host.sudo(): | ||
cmd = host.command(run_command) | ||
assert cmd.rc == 0 | ||
|
||
with host.sudo(): | ||
log_f = host.file("/tmp/gvisor1.0.log") | ||
|
||
assert log_f.exists | ||
assert b"Hello from Docker!" in log_f.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: gVisor | Download runsc binary | ||
include_tasks: "../../../download/tasks/download_file.yml" | ||
vars: | ||
download: "{{ download_defaults | combine(downloads.gvisor_runsc) }}" | ||
|
||
- name: gVisor | Download containerd-shim-runsc-v1 binary | ||
include_tasks: "../../../download/tasks/download_file.yml" | ||
vars: | ||
download: "{{ download_defaults | combine(downloads.gvisor_containerd_shim) }}" | ||
|
||
- name: gVisor | Copy binaries | ||
copy: | ||
src: "{{ local_release_dir }}/gvisor-{{ item }}" | ||
dest: "{{ bin_dir }}/{{ item }}" | ||
mode: 0755 | ||
remote_src: yes | ||
with_items: | ||
- runsc | ||
- containerd-shim-runsc-v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
roles/kubernetes-apps/container_runtimes/gvisor/tasks/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
- name: gVisor | Create addon dir | ||
file: | ||
path: "{{ kube_config_dir}}/addons/gvisor" | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
recurse: true | ||
|
||
- name: gVisor | Templates List | ||
set_fact: | ||
gvisor_templates: | ||
- { name: runtimeclass-gvisor, file: runtimeclass-gvisor.yml, type: runtimeclass } | ||
|
||
- name: gVisort | Create manifests | ||
template: | ||
src: "{{ item.file }}.j2" | ||
dest: "{{ kube_config_dir}}/addons/gvisor/{{ item.file }}" | ||
with_items: "{{ gvisor_templates }}" | ||
register: gvisor_manifests | ||
when: | ||
- inventory_hostname == groups['kube_control_plane'][0] | ||
|
||
- name: gVisor | Apply manifests | ||
kube: | ||
name: "{{ item.item.name }}" | ||
kubectl: "{{ bin_dir}}/kubectl" | ||
resource: "{{ item.item.type }}" | ||
filename: "{{ kube_config_dir }}/addons/gvisor/{{ item.item.file }}" | ||
state: "latest" | ||
with_items: "{{ gvisor_manifests.results }}" | ||
when: | ||
- inventory_hostname == groups['kube_control_plane'][0] |
6 changes: 6 additions & 0 deletions
6
roles/kubernetes-apps/container_runtimes/gvisor/templates/runtimeclass-gvisor.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
kind: RuntimeClass | ||
apiVersion: node.k8s.io/v1{{ 'beta1' if kube_version is version('v1.20.0', '<') else '' }} | ||
metadata: | ||
name: gvisor | ||
handler: runsc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.