14

大话Docker(五)普天同庆,Kubernetes决定弃用Docker

 3 years ago
source link: https://zhuanlan.zhihu.com/p/331765207
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

最近 K8s SIG 官方在 K8s 1.20 的 changelog 里提到,将在 v1.20 版本后取消 Docker 作为默认的容器运行时:

Kubernetes is deprecating Docker as a container runtime after v1.20.

Docker support in the kubelet is now deprecated and will be removed in a future release. The kubelet uses a module called "dockershim" which implements CRI support for Docker and it has seen maintenance issues in the Kubernetes community. We encourage you to evaluate moving to a container runtime that is a full-fledged implementation of CRI (v1alpha1 or v1 compliant) as they become available. ( #94624 , @dims ) [SIG Node]

天下苦 Docker 久矣,相信不出 2021 年,Docker 的使用率会逐步的降低。

很多人可能觉得这件事是 K8s 和 Swarm 恩怨的延续,但笔者认为并不全是这样,我抛砖引玉。先摆一下资历,作者看过很多 K8s 和 Docker 相关生态的源码,也做过一些小小的贡献:

AjqIZ3U.jpg!mobile

Docker 蹩脚的 API 版本管理

Docker 的 API 做了很复杂的版本,初衷是很好的,但实现得一塌糊涂,导致想要使用 Docker 的 API 要么用 Docker 的 Go client 中的 `client.WithAPIVersionNegotiation()` 要么自己搞清楚调用的时候应该用 v1.40 还是 v1.12 。例如,躲在 docker ps 后面的 API 可能是:

/v1.40/images/json?all=1 
或者
/v1.39/images/json?all=1
更或者
/v1.12/images/json?all=1

足够搞吐你

Docker 的蜜汁 API

我们常用 docker inspect xx 后面的 Docker client 实现是这样的:

func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) 
    (types.ImageInspect, []byte, error)

没错,它返回了 types.ImageInspect , []byte , error 三个值,注释里是这么写的

ImageInspectWithRaw returns the image information and its raw representation.

好的,三个就三个,当你以为第二个返回值 []byte 应该是个 json,把它请求回来。

啪啪打脸,它是一个 Base64 编码过的 json。

你以为这可能是个别沙雕程序员的脑抽设计?

不,有些接口是 Base64 编码过的,有些不是。Base64 就 Base64 吧,反正数据量也不大,是吧?

NO !!!!, docker cp 的文件传输接口也是 Base64 编码过的…… 我写的另外一篇文章: auxten:大话Docker(四)docker cp 的糟糕设计是如何坑了 k8s


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK