Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rust 🤝 Container Runtime @ Rust.Tokyo 2021

うたもく
September 18, 2021

Rust 🤝 Container Runtime @ Rust.Tokyo 2021

https://rust.tokyo/lineup/en/5

In this session, I'll talk about the possibility of using Rust in a container runtime. I'll share my experiences with youki, the container runtime in Rust that I'm working on. From these experiences, I feel that Rust is a language that should contribute more to this field. By sharing my knowledge in this presentation, many Rustaceans will be interested in this field. I also believe that the experience I'll be sharing here will be helpful not only for container runtime but also for using Rust at lower layers.

At the beginning of the presentation, I will explain container technology such as cgroups and briefly explain with actual codes of youki.

うたもく

September 18, 2021
Tweet

More Decks by うたもく

Other Decks in Technology

Transcript

  1. self‐introduction • うたもく(@utam0k) • I work for a web company

    and use Scala language • I'm studying containers in earnest starting in 2021. • Member of the containers 2
  2. What I want you to know • Youki, a container

    runtime written in Rust • A brief description of container technology ◦ What is container runtime? ◦ Learning container technologies with youki's code • Rust 🤝 Container Runtime 3
  3. What is youki? • I’m creator of youki • A

    container runtime written in Rust • Developed under containers, the organization that develop podman • ★ 1.3K in github.com • youki = 容器 = container (Meaning "container" in Japanese) 4
  4. Kubelet(K8s)
 Linux etc...
 High-Level Runtime
 CRI
 Low-Level Runtime
 OCI
 CRI

    − Container Runtime Interface
 OCI − Open Container Initiative
 Container Runtime
 6
  5. What is a container? • A process ≒ A container

    ◦ Processes in which various resources are isolated Process Files Process Files Process Files OS 8
  6. isolated? • pivot_root ◦ Change the destination that the root

    directory of a process points to • namespace ◦ Ability to isolate resources that a process can manipulate • cgroup ◦ Allows configuration of resources available to processes 9
  7. isolated? • pivot_root ◦ Change the destination that the root

    directory of a process points to • namespace ◦ Ability to isolate resources that a process can manipulate • cgroup ◦ Allows configuration of resources available to processes 10
  8. cgroup • Create a group of processes and configure settings

    for that group • For example... ◦ Limit CPU usage time, specifying assigned CPUs ◦ Device access control ◦ Pause/resume tasks • There are resource controllers for different types of resources 11
  9. /sys/fs/cgroup
 CPU
 Memory
 Devices
 P P P P P P

    P P P P Represent tree with directories inherit 12
  10. Rust × Container Runtime 👍 :+1: • Performance • Easy

    to handle system calls • A Good fit between low layers and Rust community 15
  11. Rust × Container Runtime 👍 :+1: • Performance • Easy

    to handle system calls • A Good fit between low layers and Rust community 16
  12. Performance • Enables containers to be launched even with tight

    memory limits $ podman --runtime youki run --rm --memory 1M fedora echo work work $ podman --runtime runc run --rm --memory 1M fedora echo work Error: OCI runtime error: .... 17
  13. Performance • Enables containers to be launched even with tight

    memory limits • Faster container startup and deletion ◦ There is a C language implementation of a container runtime called crun ▪ Probably not that different in speed from crun ◦ Technically challenging and interesting :) 18
  14. Rust × Container Runtime 👍 :+1: • Performance • Easy

    to handle system calls • A Good fit between low layers and Rust community 19
  15. Easy to handle system calls • Threads and processes can

    be precise controlled ◦ Difficult when language runtime is multithreaded ▪ Rust and C are not ◦ setns(2) - reassociate thread with a namespace A multithreaded process may not change user namespace with setns(). ◦ Youki has little trouble in this area • Existence of libc crate and nix crate. Thanks 🙏 20
  16. Rust × Container Runtime 👍 :+1: • Performance • Easy

    to handle system calls • A Good fit between low layer and Rust community 21
  17. Good fit between low layers and Rust community • Low

    Layer Programming 🤝 Rust ◦ There are many programmers in the Rust community who like this layer ◦ Topics adopted for the linux kernel • Rustacean, who is also interested in this layer, joined youki to learn more about container technology 22
  18. Rust × Container Runtime 😖 :confounded: • There are no

    libraries or other assets • Little knowledge in the Rust community 23
  19. Rust × Container Runtime 😖 :confounded: • There are no

    libraries or other assets • Little knowledge in the Rust community 24
  20. There are no libraries or other assets • There are

    still few libraries compared to the major languages (Go / C) in the container area ◦ For example, Go has a library set in the specification repository to parse a JSON file according to the specification • FFI(Foreign Function Interface)... ? ◦ We want to use the full potential of Rust! 25
  21. There are no libraries or other assets • The Issue

    youki would like to solve in any way possible • Cut out the codes used in youki and crate it ◦ containers/oci-spec-rs ◦ cgroup(It's not complete) • We are trying to create a common integration test tool for the container runtime community 26
  22. Rust × Container Runtime 😖 :confounded: • There are no

    libraries or other assets • Little knowledge in the Rust community 27
  23. Little knowledge in the Rust community • There are few

    Rustacean in the container world • Youki is a gateway to containers for Rustacean ◦ Youki's maintainers have got knowledgeable enough about it to read runC ◦ Container people may use it to learn Rust • Would you like to join us? 28
  24. Summary • Advantages of Rust 🤝 Container Runtime ◦ Performance

    ◦ Easy to handle system calls ◦ A Good fit between low layers and Rust community • The problems that youki wants to solve ◦ There are no libraries or other assets ◦ Little knowledge in the Rust community 29
  25. Youki in the future • Aim for the first release

    • Contributing to the container community ◦ Testing tools for generic container runtimes • Consideration of unique features as container runtime ◦ Asynchronous processing using io_uring ◦ Features using wasm or kernel modules... 🤔 • We'll have fun developing :) 30