SlideShare a Scribd company logo
1 of 20
Download to read offline
An API Intro:
Driving containerd
operations with
gRPC
WHO AM I?
Phil Estes
Senior Technical Staff, Office of the CTO, IBM Cloud
Maintainer, Docker engine
Maintainer, containerd
Contributor, OCI/runc
Docker Captains program member
Blog: https://integratedcode.us
Twitter: @estesp
1.
What is gRPC?
YOU PROBABLY ALREADY HAVE AN IDEA OF WHAT A CLIENT IS
▸ Command-line client (e.g. runc)
▸ REST/HTTP client (e.g. docker -> dockerd)
▸ Web/HTTP client (e.g. curl, your web browser)
gRPC is simply a client-server method execution model
built on the long-standing “remote procedure call”
(RPC) style interface.
gRPC is an open source project created by Google and a
full toolkit is available for many platforms:
https://github.com/grpc/grpc | https://grpc.io
“In gRPC a client application can directly call methods
on a server application on a different machine as if it
was a local object, making it easier for you to create
distributed applications and services. As in many RPC
systems, gRPC is based around the idea of defining a
service, specifying the methods that can be called
remotely with their parameters and return types.
FROM: http://www.grpc.io/docs/guides/ :
IMPORTANT CONCEPTS: SERVICES & PROTOCOL BUFFERS
▸ A gRPC API has service definitions.
▸ These service definitions have rpc methods.
▸ These rpc methods have “protobuf” defined
message content (request & response)
“Protocol buffers are a flexible, efficient, automated
mechanism for serializing structured data – think XML,
but smaller, faster, and simpler. You define how you
want your data to be structured once, then you can use
special generated source code to easily write and read
your structured data to and from a variety of data
streams and using a variety of languages. You can even
update your data structure without breaking deployed
programs that are compiled against the "old" format.
FROM:
https://developers.google.com/protocol-buffers/docs/overview :
OK, FINE, BUT WHY gRPC+PROTOBUFS OVER JSON+HTTP/etc?
Code Generation
No more writing
clients by hand!
Generators convert
.proto files into
language-specific
bindings for client
and server.
Speed & Size
Protobuf binary
packed format
marshalled from
clients<-->servers is
smaller than JSON or
XML and better
performing for
serialization &
deserialization.
Commonality
gRPC and protobufs
are growing in
popularity. gRPC is
used in Docker
Swarm, Kubernetes,
etcd, and adopted by
companies like
CoreOS, Netflix,
Square and others.
MORE gRPC BENEFITS
▸ gRPC Connection support & options are rich and
completely built-in to the implementation
▹ Less time writing or finding server code to
handle special socket options, HTTP2,
authentication, streaming, etc.
gRPC Connect Example:
2.
How is
containerd
using gRPC?
MAJOR API COMPONENTS
▸ Current gRPC services:
▹ Execution, Shim, and Content
▸ Go 1.8 provides plugin support
▹ Expect gRPC services to be pluggable
Execution
- Create
- Start
- Delete
- List
- Events
Shim
- Create
- Start
- Delete
- Exec
- Pty
- Events
- State
- Pause
- Resume
- Exit
Content
- Info
- Read
- Status
- Write
SERVICE API/PROTOBUF DEFINITIONS
▸ Each service has a .proto file with all definitions
▸ Common definitions (e.g. types) can be included
▸ Protobuf compiler generates appropriate
language binding (e.g. Go code)
api/services/shim/shim.proto
CODE GENERATION: FROM PROTO -> GO SOURCES
*WARNING: NOT FOR THE FAINT OF HEART!
commit 83e7610194170c794752088d54b0c3673b311811
Author: Stephen J Day <stephen.day@docker.com>
Date: Tue Feb 14 16:48:36 2017 -0800
cmd/ctrd-protobuild: create proper command for building protos
After trying to explain the complexities of developing with protobuf, I
have now created a command that correctly calculates the import paths
for each package and runs the protobuf command.
▸ make protos uses go generate tooling*
▸ <service>.pb.go files are created with the Go bindings
▸ Only required when changing (add/remove/modify) API
or message/type definitions
3.
Create your own
gRPC service
and/or client
`CTR LIST` AS AN EXAMPLE: SERVER SIDE (GENERATED)
▸ Generated execution.pb.go has interface for
server as well as handler which calls List method
func _ContainerService_List_Handler(srv interface{}, ctx context.Context, dec
func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
…
return srv.(ContainerServiceServer).List(ctx, in)
…
}
api/services/execution/execution.pb.go
`CTR LIST` AS AN EXAMPLE: SERVER SIDE (IMPLEMENTED)
▸ We implement the ContainerServiceServer.List
method to perform the operation and return the
appropriate gRPC message response:
`CTR LIST` AS AN EXAMPLE: CLIENT SIDE
▸ The client code to call the gRPC method is already
created for us during protobuf generation
▸ We only need to connect our client command to this
generated client stub:
var listCommand = cli.Command{
Name: "list",
Action: func(context *cli.Context) error {
containers, err := getExecutionService(context)
response, err := containers.List(gocontext.Background(),
&execution.ListRequest{})
for _, c := range response.Containers {
// print container information
}
return nil
},
}
cmd/ctr/list.go
TAKING THE
NEXT STEP
CONSUME CONTAINERD VIA gRPC CLIENT
HELP IMPROVE/DEFINE NEW AREAS OF
CORE CONTAINERD API
ADD SERVICE VIA GO 1.8 PLUGINS + gRPC
PROTO SERVICE DEFINITION
4.
Summary
Expected that consumers of containerd
will use the gRPC API. The ctr tool is a
development/admin resource.
gRPC benefits outweigh any added
complexity with protobufs for defining and
implementing the API layer.
The API is under heavy development
and will stabilize leading up to the
1.0 release of containerd. Post 1.0,
gRPC versioning will allow us to
retain backwards compatibility.
CREDITS
Special thanks to all the people who made and released these
awesome resources for free:
▸ Simple line icons by Mirko Monti
▸ E-commerce icons by Virgil Pana
▸ Streamline iconset by Webalys
▸ Presentation template by SlidesCarnival

More Related Content

What's hot

Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF Superpowers
Brendan Gregg
 

What's hot (20)

Building microservices with grpc
Building microservices with grpcBuilding microservices with grpc
Building microservices with grpc
 
gRPC Overview
gRPC OverviewgRPC Overview
gRPC Overview
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
Kubernetes fundamentals
Kubernetes fundamentalsKubernetes fundamentals
Kubernetes fundamentals
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF Superpowers
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
Disaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoFDisaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoF
 
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
 
gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and Implementation
 
Kubernetes CRI containerd integration by Lantao Liu (Google)
Kubernetes CRI containerd integration by Lantao Liu (Google)Kubernetes CRI containerd integration by Lantao Liu (Google)
Kubernetes CRI containerd integration by Lantao Liu (Google)
 
Kubernetes Security
Kubernetes SecurityKubernetes Security
Kubernetes Security
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
 
GitOps - Operation By Pull Request
GitOps - Operation By Pull RequestGitOps - Operation By Pull Request
GitOps - Operation By Pull Request
 
Observability with HAProxy
Observability with HAProxyObservability with HAProxy
Observability with HAProxy
 
Integrating Apache Kafka and Elastic Using the Connect Framework
Integrating Apache Kafka and Elastic Using the Connect FrameworkIntegrating Apache Kafka and Elastic Using the Connect Framework
Integrating Apache Kafka and Elastic Using the Connect Framework
 
Inter-Process Communication in Microservices using gRPC
Inter-Process Communication in Microservices using gRPCInter-Process Communication in Microservices using gRPC
Inter-Process Communication in Microservices using gRPC
 
eBPF - Observability In Deep
eBPF - Observability In DeepeBPF - Observability In Deep
eBPF - Observability In Deep
 
Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記
 

Similar to Driving containerd operations with gRPC

Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
Sungwon Lee
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
Dvir Volk
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
QAware GmbH
 

Similar to Driving containerd operations with gRPC (20)

Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
 
The new (is it really ) api stack
The new (is it really ) api stackThe new (is it really ) api stack
The new (is it really ) api stack
 
Ingress overview
Ingress overviewIngress overview
Ingress overview
 
Microservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCMicroservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPC
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and Microservices
 
202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP
 
KrakenD API Gateway
KrakenD API GatewayKrakenD API Gateway
KrakenD API Gateway
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
What is gRPC introduction gRPC Explained
What is gRPC introduction gRPC ExplainedWhat is gRPC introduction gRPC Explained
What is gRPC introduction gRPC Explained
 
Kubernetes: The Next Research Platform
Kubernetes: The Next Research PlatformKubernetes: The Next Research Platform
Kubernetes: The Next Research Platform
 
Modern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in GolangModern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in Golang
 
Cloud native IPC for Microservices Workshop @ Containerdays 2022
Cloud native IPC for Microservices Workshop @ Containerdays 2022Cloud native IPC for Microservices Workshop @ Containerdays 2022
Cloud native IPC for Microservices Workshop @ Containerdays 2022
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and Kubernetes
 
ASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep DiveASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep Dive
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
 
Apa itu gRPC_.pptx
Apa itu gRPC_.pptxApa itu gRPC_.pptx
Apa itu gRPC_.pptx
 

More from Docker, Inc.

Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 

More from Docker, Inc. (20)

Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker Build
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
Securing Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXSecuring Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINX
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and Compose
 
Hands-on Helm
Hands-on Helm Hands-on Helm
Hands-on Helm
 
Distributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDistributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at Salesforce
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker Hub
 
Monitoring in a Microservices World
Monitoring in a Microservices WorldMonitoring in a Microservices World
Monitoring in a Microservices World
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
 
Predicting Space Weather with Docker
Predicting Space Weather with DockerPredicting Space Weather with Docker
Predicting Space Weather with Docker
 
Become a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeBecome a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio Code
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container Registry
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!
 
Kubernetes at Datadog Scale
Kubernetes at Datadog ScaleKubernetes at Datadog Scale
Kubernetes at Datadog Scale
 
Labels, Labels, Labels
Labels, Labels, Labels Labels, Labels, Labels
Labels, Labels, Labels
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm Architecture
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 

Driving containerd operations with gRPC

  • 1. An API Intro: Driving containerd operations with gRPC
  • 2. WHO AM I? Phil Estes Senior Technical Staff, Office of the CTO, IBM Cloud Maintainer, Docker engine Maintainer, containerd Contributor, OCI/runc Docker Captains program member Blog: https://integratedcode.us Twitter: @estesp
  • 4. YOU PROBABLY ALREADY HAVE AN IDEA OF WHAT A CLIENT IS ▸ Command-line client (e.g. runc) ▸ REST/HTTP client (e.g. docker -> dockerd) ▸ Web/HTTP client (e.g. curl, your web browser) gRPC is simply a client-server method execution model built on the long-standing “remote procedure call” (RPC) style interface. gRPC is an open source project created by Google and a full toolkit is available for many platforms: https://github.com/grpc/grpc | https://grpc.io
  • 5. “In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. FROM: http://www.grpc.io/docs/guides/ :
  • 6. IMPORTANT CONCEPTS: SERVICES & PROTOCOL BUFFERS ▸ A gRPC API has service definitions. ▸ These service definitions have rpc methods. ▸ These rpc methods have “protobuf” defined message content (request & response)
  • 7. “Protocol buffers are a flexible, efficient, automated mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages. You can even update your data structure without breaking deployed programs that are compiled against the "old" format. FROM: https://developers.google.com/protocol-buffers/docs/overview :
  • 8. OK, FINE, BUT WHY gRPC+PROTOBUFS OVER JSON+HTTP/etc? Code Generation No more writing clients by hand! Generators convert .proto files into language-specific bindings for client and server. Speed & Size Protobuf binary packed format marshalled from clients<-->servers is smaller than JSON or XML and better performing for serialization & deserialization. Commonality gRPC and protobufs are growing in popularity. gRPC is used in Docker Swarm, Kubernetes, etcd, and adopted by companies like CoreOS, Netflix, Square and others.
  • 9. MORE gRPC BENEFITS ▸ gRPC Connection support & options are rich and completely built-in to the implementation ▹ Less time writing or finding server code to handle special socket options, HTTP2, authentication, streaming, etc. gRPC Connect Example:
  • 11. MAJOR API COMPONENTS ▸ Current gRPC services: ▹ Execution, Shim, and Content ▸ Go 1.8 provides plugin support ▹ Expect gRPC services to be pluggable Execution - Create - Start - Delete - List - Events Shim - Create - Start - Delete - Exec - Pty - Events - State - Pause - Resume - Exit Content - Info - Read - Status - Write
  • 12. SERVICE API/PROTOBUF DEFINITIONS ▸ Each service has a .proto file with all definitions ▸ Common definitions (e.g. types) can be included ▸ Protobuf compiler generates appropriate language binding (e.g. Go code) api/services/shim/shim.proto
  • 13. CODE GENERATION: FROM PROTO -> GO SOURCES *WARNING: NOT FOR THE FAINT OF HEART! commit 83e7610194170c794752088d54b0c3673b311811 Author: Stephen J Day <stephen.day@docker.com> Date: Tue Feb 14 16:48:36 2017 -0800 cmd/ctrd-protobuild: create proper command for building protos After trying to explain the complexities of developing with protobuf, I have now created a command that correctly calculates the import paths for each package and runs the protobuf command. ▸ make protos uses go generate tooling* ▸ <service>.pb.go files are created with the Go bindings ▸ Only required when changing (add/remove/modify) API or message/type definitions
  • 14. 3. Create your own gRPC service and/or client
  • 15. `CTR LIST` AS AN EXAMPLE: SERVER SIDE (GENERATED) ▸ Generated execution.pb.go has interface for server as well as handler which calls List method func _ContainerService_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { … return srv.(ContainerServiceServer).List(ctx, in) … } api/services/execution/execution.pb.go
  • 16. `CTR LIST` AS AN EXAMPLE: SERVER SIDE (IMPLEMENTED) ▸ We implement the ContainerServiceServer.List method to perform the operation and return the appropriate gRPC message response:
  • 17. `CTR LIST` AS AN EXAMPLE: CLIENT SIDE ▸ The client code to call the gRPC method is already created for us during protobuf generation ▸ We only need to connect our client command to this generated client stub: var listCommand = cli.Command{ Name: "list", Action: func(context *cli.Context) error { containers, err := getExecutionService(context) response, err := containers.List(gocontext.Background(), &execution.ListRequest{}) for _, c := range response.Containers { // print container information } return nil }, } cmd/ctr/list.go
  • 18. TAKING THE NEXT STEP CONSUME CONTAINERD VIA gRPC CLIENT HELP IMPROVE/DEFINE NEW AREAS OF CORE CONTAINERD API ADD SERVICE VIA GO 1.8 PLUGINS + gRPC PROTO SERVICE DEFINITION
  • 19. 4. Summary Expected that consumers of containerd will use the gRPC API. The ctr tool is a development/admin resource. gRPC benefits outweigh any added complexity with protobufs for defining and implementing the API layer. The API is under heavy development and will stabilize leading up to the 1.0 release of containerd. Post 1.0, gRPC versioning will allow us to retain backwards compatibility.
  • 20. CREDITS Special thanks to all the people who made and released these awesome resources for free: ▸ Simple line icons by Mirko Monti ▸ E-commerce icons by Virgil Pana ▸ Streamline iconset by Webalys ▸ Presentation template by SlidesCarnival