Deploy Kubernetes in Docker

Source: Internet
Author: User
Tags docker ps etcd kubernetes docker kubernetes deployment

Deploy Kubernetes in Docker

Kubernetes is an open-source container management framework of Google. It provides a series of functions such as host, cluster management, container deployment, high availability, and auto scaling of Docker containers; kubernetes's design goals include putting the container cluster in the desired state at any time. Therefore, a complete cluster management mechanism is established: automatic container restart, automatic backup, and automatic container scaling; kubernetes designs components for pod, replication controller, and service to manage containers, and provides RESTful interfaces for operations; because this article is mainly about Kubernetes, I will not introduce too much about the theory;
This article deploys Kubernetes to Docker and uses three nodes 192.168.2.143 to both Master and minion nodes. In addition, there are two minion nodes, 192.168.2.144 and 192.168.2.145;

1. The master node starts the etcd container.
Start the etcd container

-- Bind docker run-d -- net = host -- restart = always -- name = etcd-v/var/etcd/data:/var/etcd/data kubernetes/etcd: 2.0.5/usr/local/bin/etcd -- addr = 192.168.2.143: 4001 -- bind-addr = 0.0.0.0: 4001 -- data-dir =/var/etcd/data

Insert the flannel configuration information in etcd and specify that the flannel uses the 10.0.0.0/8 interval.

 docker exec -it etcd etcdctl set /solinx.co/network/config '{"Network":"10.0.0.0/8"}'  

2. Configure flanneld on master, minion1, and minion2 nodes.

Start flanneld, wget-c https://github.com/coreos/flannel/releases/download/v0.5.5/flannel-0.5.5-linux-amd64.tar.gz. /flanneld -- etcd-endpoints = http: // 192.168.2.143: 4001 -- etcd-prefix =/solinx. co/network -- iface = ens33> flannel. log 2> & 1 &

After flannel is started, the IP address set that can be allocated is obtained and stored in/run/flannel/subnet. env. You need to configure available and allocated IP addresses for docker.

Modify the Docker configuration file in Ubuntu

In/lib/systemd/system/docker. added EnvironmentFile =-/etc/default/docker to change ExecStart =/usr/bin/docker-d-H fd: //: execStart =/usr/bin/docker-d-H fd: // $ DOCKER_OPTS source/run/flannel/subnet. env sh-c "echo DOCKER_OPTS =\\" -- bip = $ FLANNEL_SUBNET -- mtu = $ FLANNEL_MTU \\\ ">/etc/default/docker" service docker restart

3. Kubernetes deployment
Download kubernetes.tar.gz to master and minion nodes.

 wget -c https://github.com/kubernetes/kubernetes/releases/download/v1.2.5/kubernetes.tar.gz

Decompress the kubernetes.tar.gz file and find kubernetes-server-linux-amd64.tar.gz in the kubernetes/serverdirectory to decompress the file. In the kubernetes/server/bin directory, find: release;
Import the kubernetes Docker image file to the master node

 docker load -i kube-apiserver.tar docker load -i kube-controller-manager.tar docker load -i kube-scheduler.tar

Here, flannel and kubernetes use the same etcd

Start apiServer on the master node

 docker run -d --name=apiserver --net=host gcr.io/google_containers/kube-apiserver:7bf05b2d35172296e4fbd2604362456f kube-apiserver --insecure-bind-address=192.168.2.143 --service-cluster-ip-range=10.0.0.0/16 --etcd-servers=http://192.168.2.143:4001  

Master node starts ControllerManager

 docker run -d --name=ControllerM gcr.io/google_containers/kube-controller-manager:6c95ef0b57ac9deda34ae1a4a40baa0a kube-controller-manager --master=192.168.2.143:8080

Start Scheduler on the master node.

 docker run -d --name=scheduler gcr.io/google_containers/kube-scheduler:e5342c3d8ced06850af97347daf6ae4b kube-scheduler --master=192.168.2.143:8080

Server startup completed

. /Kubectl-s 192.168.2.143: 8080 version view kubernetes Version information Client version: version. info {Major: "1", Minor: "2", GitVersion: "v1.2.5", GitCommit: "25eb53b54e08877d3789455964b3e97bdd3f3bce", GitTreeState: "clean"} Server Version: version. info {Major: "1", Minor: "2", GitVersion: "v1.2.5", GitCommit: "25eb53b54e08877d3789455964b3e97bdd3f3bce", GitTreeState: "clean "}

View the startup status of the Service Container on the Master node:

 docker ps  

Start kubelet on 143, 144, and 145 minion nodes

Obtain the minion node IP address.

 NODE_IP=`ifconfig ens33 | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f1` ./kubelet --api-servers=192.168.2.143:8080 --node-ip=$NODE_IP --hostname_override=192.168.2.144 > kubelet.log 2>&1 &

Note: If the two host names are the same, you must use the hostname_override parameter. Otherwise, you must change the host names to different ones;

View node information on the master node

 ./kubectl -s 192.168.2.143:8080 get no

Start kube-proxy on 143, 144, and 145 nodes

 ./kube-proxy --master=192.168.2.143:8080 > proxy.log 2>&1 &

Run the following command to view the pod, replication controller, service, and endpoint:

 ./kubectl -s 192.168.1.143:8080 get po ./kubectl -s 192.168.1.143:8080 get rc ./kubectl -s 192.168.1.143:8080 get svc ./kubectl -s 192.168.1.143:8080 get ep  

References:
Http://kubernetes.io/docs/user-guide/

Kubernetes cluster deployment

OpenStack, Kubernetes, and Mesos

Problems encountered during Kubernetes cluster construction and Solutions

For details about Kubernetes, click here
Kubernetes: click here

This article permanently updates the link address:

Related Article

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.