Kubernetes 简明教程

Kubernetes - Images

Kubernetes(Docker)镜像是容器化基础设施的关键构建模块。到目前为止,我们仅支持 Kubernetes 来支持 Docker 镜像。容器中的每个容器都有在其中运行其 Docker 镜像。

Kubernetes (Docker) images are the key building blocks of Containerized Infrastructure. As of now, we are only supporting Kubernetes to support Docker images. Each container in a pod has its Docker image running inside it.

当配置一个 Pod 时,配置文件中图像的属性与 Docker 命令具有相同的语法。该配置文件中有一个用于定义图像名称的字段,我们准备从注册表中提取此名称。

When we are configuring a pod, the image property in the configuration file has the same syntax as the Docker command does. The configuration file has a field to define the image name, which we are planning to pull from the registry.

以下是从 Docker 注册中提取图像并将图像部署到 Kubernetes 容器的常见配置文件结构。

Following is the common configuration structure which will pull image from Docker registry and deploy in to Kubernetes container.

apiVersion: v1
kind: pod
metadata:
   name: Tesing_for_Image_pull -----------> 1
   spec:
      containers:
         - name: neo4j-server ------------------------> 2
         image: <Name of the Docker image>----------> 3
         imagePullPolicy: Always ------------->4
         command: ["echo", "SUCCESS"] ------------------->

在以上的代码中,我们已经定义了 −

In the above code, we have defined −

  1. name: Tesing_for_Image_pull − This name is given to identify and check what is the name of the container that would get created after pulling the images from Docker registry.

  2. name: neo4j-server − This is the name given to the container that we are trying to create. Like we have given neo4j-server.

  3. image: <Name of the Docker image> − This is the name of the image which we are trying to pull from the Docker or internal registry of images. We need to define a complete registry path along with the image name that we are trying to pull.

  4. imagePullPolicy − Always - This image pull policy defines that whenever we run this file to create the container, it will pull the same name again.

  5. command: [“echo”, “SUCCESS”] − With this, when we create the container and if everything goes fine, it will display a message when we will access the container.

为了提取图像并创建容器,我们将运行以下命令。

In order to pull the image and create a container, we will run the following command.

$ kubectl create –f Tesing_for_Image_pull

一旦获取日志,我们将得到一个成功输出。

Once we fetch the log, we will get the output as successful.

$ kubectl log Tesing_for_Image_pull

上述命令将生成一个成功的输出,或者我们将得到一个失败的输出。

The above command will produce an output of success or we will get an output as failure.

Note - 建议您亲自尝试所有命令。

Note − It is recommended that you try all the commands yourself.