I鈥檝e recently been experimenting with various ways to construct Linux VM images, but for these images to be practical, they need to interact with the outside world. At a minimum, they need to communicate with the host machine. vsock is a technology specifically designed with VMs in mind. It eliminates the need for a TCP/IP stack or network virtualization to enable communication with or between VMs. At the API level, it behaves like a standard socket but utilizes a specialized addressing scheme. In the experiment below, we鈥檒l explore using vsock as the transport mechanism for a gRPC service running on a VM. We鈥檒l build this project with Bazel for easy reproducibility. Check out this post if you need an intro to Bazel. Table of contents Open Table of contents Motivation There are many use cases for efficient communication between a VM and its host (or between multiple VMs). One simple reason is to create a hermetic environment within the VM and issue commands via RPC from the host. This is the primary driver for using gRPC in this example, but you can easily generalize the approach shown here to build far more complex systems. GitHub repo The complete repository is hosted here and serves as the source of truth for this experiment. While there may be minor inconsistencies between the code blocks below and the repository, please rely on GitHub as the definitive source. Code breakdown Let鈥檚 break down the code step by step: External dependencies Here are the external dependencies listed as Bazel modules: bazel_dep(name = "rules_proto", version = "7.1.0") bazel_dep(name = "rules_cc", version = "0.2.14") bazel_dep(name = "protobuf", version = "33.1", repo_name = "com_google_protobuf") bazel_dep(name = "grpc", version = "1.76.0.bcr.1") This is largely self-explanatory. The protobuf repository is used for C++ proto-generation rules, and grpc provides the monorepo for Bazel rules to generate gRPC code for the C++ family of languages. gRPC library generation The following Baze...
First seen: 2025-11-28 08:40
Last seen: 2025-11-28 16:41