kubernetes1.4新特性:支持Docker新特性

2023年 7月 10日 24.9k 0

(一)背景资料

  • 在Kubernetes1.2中这个第三方组件就是go-dockerclient,这是一个GO语言写的docker客户端,支持Dockerremote API,这个项目在https://github.com/fsouza/go-dockerclient中。
  • 在Kubernetes1.3中直接使用docker公司提供的client来实现,通过这个client可以实现同DockerDeamon之间的通讯,这个客户端项目在https://github.com/docker/engine-api/中,感兴趣的话可以去看看。
  • 在Kubernetes1.4中延用了1.3中的方式,直接使用docker公司提供的client来实现。

(二)支持Docker版本

  • 对于Kubernetes1.4需要使用Docker版本至少是1.9.x,Docker1.9.x对应的API版本是1.21。
  • 下面是Docker版本同API版本对应关系,其中红色字体的部分是Kubernetes1.4不支持的。

Docker版本

API版本

1.12x

1.24

1.11.x

1.23

1.10.x

1.22

1.9.x

1.21

1.8.x

1.20

1.7.x

1.19

1.6.x

1.18

1.5.x

1.17

1.4.x

1.16

1.3.x

1.15

1.2.x

1.14

(三)调用Docker API

下面表格展现了Docker最新版本所有的API列表,同时也展现了Kubernetes1.4版本和1.3版本都使用了哪些API。

  • 第一列是Docker 1.24版本API列表
  • 第二列是这些API使用方式
  • 第三列是Kubernetes1.4中使用到的API
  • 第四列是Kubernetes1.3中使用到的API
  • 红色字体部分为1.4版本比1.3版本增加的调用API,也就是说1.4版本比1.3版本增加的操作Docker的功能

Docker API 1.24

使用方式

Kubernetes1.4

Kubernetes1.3

Get Container stats based on resource usage

GET /containers/(id)/stats

 

 

Update a container

POST /containers/(id)/update

 

 

Rename a container

POST /containers/(id)/rename

 

 

Retrieving information about files and folders in a container

HEAD /containers/(id)/archive

 

 

List containers

GET /containers/json

Inspect a container

GET /containers/(id)/json

Inspect changes on a container’s filesystem

GET /containers/(id)/changes

Create a container

POST /containers/create

Start a container

POST /containers/(id)/start

Stop a container

POST /containers/(id)/stop

Restart a container

POST /containers/(id)/restart

 

 

Pause a container

POST /containers/(id)/pause

 

 

Unpause a container

POST /containers/(id)/unpause

 

 

List processes running inside a container

GET /containers/(id)/top

 

 

Kill a container

POST /containers/(id)/kill

Remove a container

DELETE /containers/(id)

Get an archive of a filesystem resource in a container

GET /containers/(id)/archive

 

 

Extract an archive of files or folders to a directory in a container

PUT /containers/(id)/archive

 

 

Copy files or folders from a container

POST /containers/(id)/copy,以后会被删除掉,使用archive代替

 

 

Wait a container

POST /containers/(id)/wait

 

 

Create a new image from a container’s changes

POST /commit

 

 

Attach to a container

POST /containers/(id)/attach

Attach to a container (websocket)

GET /containers/(id or name)/attach/ws    

Get container logs

GET /containers/(id)/logs

Resize a container TTY

POST /containers/(id)/resize

 

Export a container

GET /containers/(id)/export

 

 

List Images

GET /images/json

Inspect an image

GET /images/(name)/json

Get the history of an image

GET /images/(name)/history

Push an image on the registry

POST /images/(name)/push

 

 

Build image from a Dockerfile

POST /build

 

 

Create an image

POST /images/create

Load a tarball with a set of images and tags into docker

POST /images/load

 

 

Get a tarball containing all images in a repository

GET /images/(name)/get

 

 

Get a tarball containing all images

GET /images/get

 

 

Tag an image into a repository

POST /images/(name)/tag

 

 

Remove an image

DELETE /images/(name)

Search images

GET /images/search

 

 

Monitor Docker’s events

GET /events

 

 

Show the docker version information

GET /version

Display system-wide information

GET /info

Ping the docker server

GET /_ping

 

 

List volumes

GET /volumes

 

 

Create a volume

POST /volumes/create

 

 

Inspect a volume

GET /volumes/(name)

 

 

Remove a volume

DELETE /volumes/(name)

 

 

List networks

GET /networks

 

 

Inspect network

GET /networks/

 

 

Create a network

POST /networks/create

 

 

Remove a network

DELETE /networks/(id)

 

 

Connect a container to a network

POST /networks/(id)/connect

 

 

Disconnect a container from a network

POST /networks/(id)/disconnect

 

 

Check auth configuration

POST /auth

 

 

Exec Create

POST /containers/(id)/exec

Exec Start

POST /exec/(id)/start

Exec Resize

POST /exec/(id)/resize

 

Exec Inspect

GET /exec/(id)/json

List plugins

GET /plugins    

Install a plugin

POST /plugins/pull?name=    

Inspect a plugin

GET /plugins/(plugin name)    

Enable a plugin

POST /plugins/(plugin name)/enable    

Disable a plugin

POST /plugins/(plugin name)/disable    

Remove a plugin

DELETE /plugins/(plugin name)    

List nodes

GET /nodes    

Inspect a node

GET /nodes/    

Remove a node

DELETE /nodes/    

Update a node

POST /nodes//update    

Inspect swarm

GET /swarm    

Initialize a new swarm

POST /swarm/init    

Join an existing swarm

POST /swarm/join    

Leave a swarm

POST /swarm/leave    

Update a swarm

POST /swarm/update    

List services

GET /services    

Create a service

POST /services/create    

Remove a service

DELETE /services/(id or name)    

Inspect one or more services

GET /services/(id or name)    

Update a service

POST /services/(id or name)/update    

List tasks

GET /tasks    

Inspect a task

GET /tasks/(task id)    

1)       从表格中可以看到,Kubernetes1.4中调用了Docker的Resize a container TTY接口,用来配置Docker容器的虚拟终端(TTY),重新设置Docker容器的虚拟终端之后,需要重新启动容器才能生效。

HTTP请求例子:

POST/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1

返回响应例子:

HTTP/1.1 200 OK  

Content-Length: 0  

Content-Type: text/plain; charset=utf-8

请求参数:

h – 虚拟终端高度

w – 虚拟终端宽度

HTTP返回响应状态值:

200 – 设置成功

404 – 没有找到指定Docker容器

500 – 不能够重新设置虚拟终端参数

2)       从表格中还可以看到,Kubernetes1.4中调用了Docker的Exec Resize接口,如果在Docker容器中执行exec命令时指定了虚拟终端(tty),那么通过这个API接口就可以重新设置虚拟终端(tty)。

HTTP请求例子:

POST/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1  

Content-Type: text/plain

返回响应例子:

HTTP/1.1201 Created  

Content-Type: text/plain

请求参数:

h –虚拟终端高度

w –虚拟终端宽度

HTTP返回响应状态值:

201 –设置成功

404 –没有找到指定exec实例

3)       Kubernetes1.4新增加了上面两个接口调用,可以看看这两个接口调用在源代码中的位置:

func AttachContainer(client DockerInterface,containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderrio.WriteCloser, tty bool, resize 

相关文章

KubeSphere 部署向量数据库 Milvus 实战指南
探索 Kubernetes 持久化存储之 Longhorn 初窥门径
征服 Docker 镜像访问限制!KubeSphere v3.4.1 成功部署全攻略
那些年在 Terraform 上吃到的糖和踩过的坑
无需 Kubernetes 测试 Kubernetes 网络实现
Kubernetes v1.31 中的移除和主要变更

发布评论