Kubernetes of Docker Container management

Source: Internet
Author: User
Tags docker ps etcd value store

Kubernetes is Google's Open source container cluster management system. It is built on Docker technology and provides a whole set of functions, such as resource scheduling, deployment operation, service discovery, expansion and contraction capacity, for containerized applications, which can be regarded as Mini-paas platform based on container technology. The purpose of this article is to comb the architecture, concepts, and basic workflows of kubernetes, and to describe how to use kubernetes by running a simple sample application.

General overview

As shown in my preliminary reading of the document and the source code after the overall overview, basically can be from the following three dimensions to understand kubernetes.

650) this.width=650; "src=" Http://resource.docker.cn/kubernetes-zhangjun.png "alt=" alt "/>

manipulating Objects

Kubernetes opens the interface in a restful form, with three user-operable rest objects:

    • pod : Is the most basic deployment dispatch unit of Kubernetes, which can contain container, which logically represents an instance of an application. For example, a Web site application is built from the front end, back end, and database, and these three components will run in their own containers, so we can create pods with three container.

    • service : Is the route agent abstraction for Pod, which solves the service discovery problem between pods. Because the operating state of the pod can be changed dynamically (such as switching machines, terminating in the process of shrinking, etc.), the access terminal cannot access the service provided by the Pod by writing dead IP. The introduction of the service is designed to ensure that the dynamic changes to the pod are transparent to the access side, which only needs to know the address of the service to provide the proxy by service.

    • Replicationcontroller : Is the copy abstraction of Pod, which solves the problem of expansion and contraction of pod. In general, distributed applications need to replicate multiple resources for performance or high availability, and dynamically scale based on load conditions. With Replicationcontroller, we can specify that an application requires several copies, Kubernetes will create a pod for each copy, and ensure that the actual number of pods is always equal to the number of copies (for example, when a pod is currently down, Automatically creates a new pod to replace).

As you can see, the service and Replicationcontroller are just abstractions built on the pod, and ultimately in the pod, how do they relate to the pod? This introduces the concept of label: The label is a good understanding of the pod plus a set of key/value tags that can be used for search or association, and the service and Replicationcontroller are associated with the pod by label. As shown, there are three pods with the label "App=backend", and when creating service and Replicationcontroller you can specify the same label: "App=backend", and then through the label selector mechanism, They are associated with these three pods. For example, when another frontend pod accesses the service, it is automatically forwarded to one of the backend pods.

650) this.width=650; "src=" Http://resource.docker.cn/rest-objects.png "alt=" alt "/>

Functional Components

As shown in the official documentation for the cluster architecture diagram, a typical master/slave model.

650) this.width=650; "src=" Http://resource.docker.cn/architecture.png "alt=" alt "/>

Master runs three components:

    • Apiserver : As the entrance of the kubernetes system, it encapsulates the additions and deletions of the core objects, which are provided to external customers and internal component calls in the RESTful interface mode. The rest objects it maintains are persisted to ETCD, a distributed, strongly-consistent key/value store.

    • Scheduler : Responsible for the resource scheduling of the cluster, assigning the machine to the new pod. This part of the work is divided into a component, which means that it is easy to replace it with other schedulers.

    • Controller-manager : Responsible for executing various controllers, there are currently two types:

      • replication-controller: Periodic association Replicationcon Troller and pods ensure that the number of copies Replicationcontroller defined is always the same as the number of pods actually running.

Slave (called Minion) runs two components:

    • Kubelet: Responsible for the control of Docker containers, such as Start/stop, monitor operation status. It periodically obtains pods assigned to the native from Etcd, and starts or stops the appropriate containers based on pod information. It also receives Apiserver HTTP requests to report the status of the pod.

    • Proxy: Responsible for providing the agent for the pod. It periodically obtains all the service from ETCD and creates an agent based on the service information. When a customer pod accesses another pod, the access request is forwarded by the native proxy.

Work Flow

The three most basic operating objects in Kubernetes are mentioned above: Pod, Replicationcontroller, and service. The following separate from their object creation, through the time series diagram to describe the interaction between the various components of kubernetes and their workflow.

650) this.width=650; "src=" Http://resource.docker.cn/kubernetes-workflow.png "alt=" alt "/>

using the example

Finally, let's go into combat mode, where a simple stand-alone example (all components running on a single machine) is designed to get through the basic process.

Build the Environment

In the first step, we need to kuberntes the binary executables of each component. There are two ways to get:-Download the source code to build it yourself:

git clone https://github.com/GoogleCloudPlatform/kubernetes.git
CD Kubernetes/build
./release.sh

    • Directly download the tar file that has been compiled and packaged:

wget https://storage.googleapis.com/kubernetes/binaries.tar.gz

Compile your own source code needs to install the Golang, after compiling in the Kubernetes/_output/release-tars folder can be packaged files. The direct download does not require the installation of additional software, but may not have the latest version.

In the second step, we also need the ETCD binary executable file, which is obtained by the following way:

wget https://github.com/coreos/etcd/releases/download/v0.4.6/etcd-v0.4.6-linux-amd64.tar.gz
Tar xvf etcd-v0.4.6-linux-amd64.tar.gz

In the third step, you can start each component:

Etcd

CD ETCD-V0.4.6-LINUX-AMD64
./etcd

Apiserver

./apiserver \
-address=127.0.0.1 \
-port=8080 \
-portal_net= "172.0.0.0/16" \
-ETCD_SERVERS=HTTP://127.0.0.1:4001 \
-machines=127.0.0.1 \
-v=3 \
-logtostderr=false \


Scheduler

./scheduler-master 127.0.0.1:8080 \
-v=3 \
-logtostderr=false \
-log_dir=./log

Controller-manager

./controller-manager-master 127.0.0.1:8080 \
-v=3 \
-logtostderr=false \
-log_dir=./log

Kubelet

./kubelet \
-address=127.0.0.1 \
-PORT=10250 \
-hostname_override=127.0.0.1 \
-ETCD_SERVERS=HTTP://127.0.0.1:4001 \
-v=3 \
-logtostderr=false \
-log_dir=./log

Create pod

Once you've set up your environment, you're ready to submit the pod. First, the pod description file is written and saved as Redis.json:


  "id": "Redis",  
  " Desiredstate ": { 
   " manifest ": { 
     " version ":" V1beta1 ",  
&nb Sp     "id": "Redis",  ,
      "containers": [{ 
        ' name ': "Redis",  
        "image": "Dockerfile/redis",  
        "IMAGEP Ullpolicy ":" Pullifnotpresent ",  
       " ports ": [{ 
        & nbsp; " Containerport ": 6379,  
         " Hostport ": 6379  
        }]  
     }]  
   }  
 }  
  "labels": { 
    "name": "Redis"  
 }  
}  

Then, through the command-line tool, Kubecfg commits:

./kubecfg-c Redis.json Create/pods

After submission, check the pod status via kubecfg:

#./kubecfg List/pods
ID Image (s) Host Labels Status
----------          ----------          ----------          ----------          ----------
Redis Dockerfile/redis 127.0.0.1/name=redis Running

Status is running that the pod is already running in the container, and you can use the Docker PS command to view the container information:

# docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Ae83d1e4b1ec dockerfile/redis:latest "redis-server/etc/r seconds ago up seconds K8s_redis.caa18858_redis.default.etcd_1414684622_1b43fe35

# # #创建replicationController

{
"id": "Rediscontroller",
"Apiversion": "V1beta1",
"Kind": "Replicationcontroller",
"Desiredstate": {
"Replicas": 1,
"Replicaselector": {"name": "Redis"},
"Podtemplate": {
"Desiredstate": {
"Manifest": {
"Version": "V1beta1",
"id": "Rediscontroller",
"Containers": [{
"Name": "Redis",
"Image": "Dockerfile/redis",
"Imagepullpolicy": "Pullifnotpresent",
"Ports": [{
"Containerport": 6379,
"Hostport": 6379
}]
}]
}
},
"Labels": {"name": "Redis"}
}},
"Labels": {"name": "Redis"}
}

Then, through the command-line tool, Kubecfg commits:



After submission, check the Replicationcontroller status via kubecfg:

#./kubecfg List/replicationcontrollers
ID Image (s) Selector replicas
----------          ----------          ----------          ----------
Rediscontroller Dockerfile/redis Name=redis 1

At the same time, 1 pods will be created automatically, even if we deliberately delete the Pod,replicationcontroller will also guarantee the creation of 1 new pods.


This article is from the "life is an Attitude" blog, please be sure to keep this source http://sangh.blog.51cto.com/6892345/1573975

Kubernetes of Docker Container management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.