简体   繁体   中英

What is the difference between dockerService and DockerServer in the kubelet source code

When I read the k8s source code, I found that both dockerService located in pkg/kubelet/dockershim/docker_service.go and DockerServer located in pkg/kubelet/dockershim/remote/docker_server.go seem to implement the interface of the CRI shim server .

But I don't understand the difference between the two, why do I need to distinguish between the two?

k8s version is tag 1.23.1

  • DockerServer simply creates dockershim grpc server
// DockerServer is the grpc server of dockershim.
type DockerServer struct {
    // endpoint is the endpoint to serve on.
    endpoint string
    // service is the docker service which implements runtime and image services.
    service DockerService
    // server is the grpc server.
    server *grpc.Server
}
...
// Start starts the dockershim grpc server.
func (s *DockerServer) Start() error {
    glog.V(2).Infof("Start dockershim grpc server")
    l, err := util.CreateListener(s.endpoint)
    if err != nil {
        return fmt.Errorf("failed to listen on %q: %v", s.endpoint, err)
    }
    // Create the grpc server and register runtime and image services.
    s.server = grpc.NewServer()
    runtimeapi.RegisterRuntimeServiceServer(s.server, s.service)
    runtimeapi.RegisterImageServiceServer(s.server, s.service)
    go func() {
        // Use interrupt handler to make sure the server to be stopped properly.
        h := interrupt.New(nil, s.Stop)
        err := h.Run(func() error { return s.server.Serve(l) })
        if err != nil {
            glog.Errorf("Failed to serve connections: %v", err)
        }
    }()
    return nil
}
  • DockerService is the interface implement CRI remote service server
// DockerService is the interface implement CRI remote service server.
type DockerService interface {
    runtimeapi.RuntimeServiceServer
    runtimeapi.ImageServiceServer
}

// **dockerService uses dockershim service to implement DockerService**.

BTW, are you sure you will use in the future? From the latest (5 days ago) news: Kubernetes is Moving on From Dockershim: Commitments and Next Steps :

  • Kubernetes is removing dockershim in the upcoming v1.24 release.
  • If you use Docker Engine as a container runtime for your Kubernetes cluster, get ready to migrate in 1.24
  • Full removal is targeted in Kubernetes 1.24, in April 2022.
  • We'll support Kubernetes version 1.23, which includes dockershim, for another year in the Kubernetes project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM