0

Introduction

There is a CLI tool to interact with containerd called ctr. However I would like to achieve the same results without it using curl, after searching on google it can't be done with curl but grpcurl instead.

How can I do basic gRPC calls to containerd?

What I have tried

First I downloaded both grpcurl and api.proto.

Then I listed available services:

vagrant@ubuntu-focal:~/containerd/api/grpc/types$ grpcurl -import-path . -proto api.proto list
types.API

vagrant@ubuntu-focal:~/containerd/api/grpc/types$ grpcurl -import-path . -proto api.proto list types.API
types.API.AddProcess
types.API.CreateCheckpoint
types.API.CreateContainer
types.API.DeleteCheckpoint
types.API.Events
types.API.GetServerVersion
types.API.ListCheckpoint
types.API.Signal
types.API.State
types.API.Stats
types.API.UpdateContainer
types.API.UpdateProcess

Used protoc to create a compiled version instead but didnt seem to change anything.

Finally tried making a request to the method Stats (including containerd's UNIX socket path and -plaintext). However it seems I am messing something up, here is the error (both using --proto and --protoset:

sudo grpcurl -plaintext -protoset myservice.protoset -unix /run/containerd/containerd.sock types.API/Stats
ERROR:
  Code: Unimplemented
  Message: unknown service types.API

sudo grpcurl -plaintext -proto api.proto -unix /run/containerd/containerd.sock types.API.Stats
ERROR:
  Code: Unimplemented
  Message: unknown service types.API

Also tried with:

  • API/Stats
  • API.Stats
  • types.API.Stats
itasahobby
  • 301
  • 4
  • 15
  • I assuming the first `grpcurl ... list types.API` worked. Did you try the same (i.e. `list types.API` against the UNIX socket? using `-proto` rather than `-protoset`? You should always need to include the package (`types`) and `types.API.Stats` should work. I tend to delineate methods from services with a `/` i.e. `types.API/Stats` but I think both forms are equivalent. – DazWilkin Jun 25 '22 at 17:00
  • @DazWilkin Yeah also tried that, updated the question to include full command outputs – itasahobby Jun 25 '22 at 22:17
  • I assume the service doesn't support reflection. You could try dropping the `-proto` and `-protoset` and using `list` to see whether you can enumerate whatever service(s) are there – DazWilkin Jun 25 '22 at 22:23
  • @DazWilkin No,It does not support reflection. Already tried that out – itasahobby Jun 26 '22 at 08:40
  • I think that `api.proto` is incorrect. I have `containerd` for MicroK8s and Docker and using [this](https://github.com/containerd/containerd/tree/main/api/services) set of protos, I was able to e.g. `Namespaces.List`: `grpcurl -plaintext -proto namespace.proto -unix /var/snap/microk8s/common/run/containerd.sock containerd.services.namespaces.v1.Namespaces.List` – DazWilkin Jun 26 '22 at 15:24

1 Answers1

0

I cloned the wrong repo instead of containerd.

To check it working use the following request:

vagrant@ubuntu-focal:~/containerd/api/services/version/v1$ sudo grpcurl -plaintext -proto version.proto -unix /run/containerd/containerd.sock containerd.services.version.v1.Version/Version
{
  "version": "1.5.5-0ubuntu3~20.04.2"
}
itasahobby
  • 301
  • 4
  • 15