Openshift 简明教程

OpenShift - Docker and Kubernetes

OpenShift 建立在 Docker 和 Kubernetes 之上。所有容器都建立在 Docker 集群之上,Docker 集群本质上是基于 Linux 机器、使用 Kubernetes 编排特性的 Kubernetes 服务。

OpenShift is built on top of Docker and Kubernetes. All the containers are built on top of Docker cluster, which is basically Kubernetes service on top of Linux machines, using Kubernetes orchestrations feature.

在此过程中,我们构建控制所有节点并将容器部署到所有节点的 Kubernetes master。Kubernetes 的主要功能是使用不同种类的配置文件来控制 OpenShift 集群和部署流程。与 Kubernetes 一样,我们以与使用 OC 命令行实用工具在集群节点上构建和部署容器相同的方式使用 kubctl。

In this process, we build Kubernetes master which controls all the nodes and deploys the containers to all the nodes. The main function of Kubernetes is to control OpenShift cluster and deployment flow using a different kind of configuration file. As in Kubernetes, we use kubctl in the same way we use OC command line utility to build and deploy containers on cluster nodes.

以下是用于在集群中创建不同种类对象的不同种类配置文件。

Following are the different kinds of config files used for creation of different kind of objects in the cluster.

  1. Images

  2. POD

  3. Service

  4. Replication Controller

  5. Replica set

  6. Deployment

Images

Kubernetes (Docker) 镜像是容器化基础设施的关键构建模块。截至目前,Kubernetes 仅支持 Docker 镜像。豆荚中的每个容器内部都运行着其 Docker 镜像。

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

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”] -------------------> 5

POD

豆荚是 Kubernetes 集群节点内的一组容器及其存储。可以在豆荚内部创建包含多个容器的豆荚。以下是在同一个豆荚中保留数据库容器和 Web 界面容器的示例。

A pod is collection of containers and its storage inside a node of a Kubernetes cluster. It is possible to create a pod with multiple containers inside it. Following is an example of keeping a database container and web interface container in the same pod.

apiVersion: v1
kind: Pod
metadata:
   name: Tomcat
spec:
   containers:
   - name: Tomcat
      image: tomcat: 8.0
      ports:
- containerPort: 7500
imagePullPolicy: Always

Service

一项服务可以定义为一组逻辑豆荚。可以将其定义为豆荚之上的抽象,该抽象提供一个单一的 IP 地址和 DNS 名称,豆荚可以通过它进行访问。使用 Service,可以非常轻松地管理负载平衡配置。它帮助 POOD 非常容易地进行扩展。

A service can be defined as a logical set of pods. It can be defined as an abstraction on top of the pod that provides a single IP address and DNS name by which pods can be accessed. With Service, it is very easy to manage load balancing configuration. It helps PODs to scale very easily.

apiVersion: v1
kind: Service
metadata:
   name: Tutorial_point_service
spec:
   ports:
   - port: 8080
      targetPort: 31999

Replication Controller

Replication Controller 是 Kubernetes 的一项关键功能,它负责管理 pod 生命周期。它负责确保在任何时间点都运行指定数量的 Pod 副本。

Replication Controller is one of the key features of Kubernetes, which is responsible for managing the pod lifecycle. It is responsible for making sure that specified numbers of pod replicas are running at any point of time.

apiVersion: v1
kind: ReplicationController
metadata:
   name: Tomcat-ReplicationController
spec:
   replicas: 3
   template:
   metadata:
      name: Tomcat-ReplicationController
   labels:
      app: App
      component: neo4j
   spec:
      containers:
      - name: Tomcat
      image: tomcat: 8.0
      ports:
      - containerPort: 7474

Replica Set

副本集确保应运行多少 Pod 副本。它可以被视为 Replication Controller 的替代品。

The replica set ensures how many replica of pod should be running. It can be considered as a replacement of the replication controller.

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
   name: Tomcat-ReplicaSet
spec:
   replicas: 3
   selector:
      matchLables:
      tier: Backend
   matchExpression:
      - { key: tier, operation: In, values: [Backend]}

   app: App
   component: neo4j
spec:
   containers:
   - name: Tomcat-
image: tomcat: 8.0
   ports:
containerPort: 7474

Deployment

Deployment 是 Replication Controller 的升级和更高版本。它们管理副本集的部署,副本集也是 Replication Controller 的升级版本。它们有能力更新副本集,并且也有能力回滚到之前的版本。

Deployments are upgraded and higher versions of the replication controller. They manage the deployment of replica sets, which is also an upgraded version of the replication controller. They have the capability to update the replica set and they are also capable of rolling back to the previous version.

apiVersion: extensions/v1beta1 --------------------->1
kind: Deployment --------------------------> 2
metadata:
   name: Tomcat-ReplicaSet
spec:
   replicas: 3
   template:
      metadata:
lables:
   app: Tomcat-ReplicaSet
   tier: Backend
spec:
   containers:
name: Tomcat-
   image: tomcat: 8.0
   ports:
   - containerPort: 7474

所有配置文件可以用来创建各自的 Kubernetes 对象。

All config files can be used to create their respective Kubernetes objects.

$ Kubectl create –f <file name>.yaml

可以使用以下命令来了解 Kubernetes 对象的详细信息和说明。

Following commands can be used to know the details and description of the Kubernetes objects.

For POD

For POD

$ Kubectl get pod <pod name>
$ kubectl delete pod <pod name>
$ kubectl describe pod <pod name>

For Replication Controller

For Replication Controller

$ Kubectl get rc <rc name>
$ kubectl delete rc <rc name>
$ kubectl describe rc <rc name>

For Service

For Service

$ Kubectl get svc <svc name>
$ kubectl delete svc <svc name>
$ kubectl describe svc <svc name>

有关如何使用 Docker 和 Kubernetes 的更多详情,请访问使用以下链接的 Kubernetes 教程 kubernetes

For more details on how to work with Docker and Kubernetes, please visit our Kubernetes tutorial using the following link kubernetes.