Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Docker Cluster based on kubernetes

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to build a Docker cluster based on kubernetes. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. Environment description

Component version Notes:

System version: ceontos 7

Kubernetes version: 0.17.1

Etcd version: 2.1.1

Docker version: 1.6.2

Environment description

Etcd:172.16.0.3

Master:172.16.0.2 kubernetes+docker

Minion1:172.16.0.4 kubernetes+docker

Minion2:172.16.0.5 kubernetes+docker

2. System environment configuration

Update yum Feed

# yum-y install wget ntpdate bind-utils

# wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/epel-release-7-2.noarch.rpm

# yum update

Firewall settings (configured on a personal basis, not required)

Close firewall

# systemctl stop firewalld.service # stop firewall

# systemctl disable firewalld.service # disable firewall boot

Install iptalbles

# yum install iptables-services # installation

# systemctl start iptables.service # finally restart the firewall to make the configuration effective

# systemctl enable iptables.service # set the firewall to boot

2. Install and configure etcd

2.1, installation

# yum install etcd

2.2, configuration

[root@etcd ~] # grep-Ev "^ # | ^ $" / etc/etcd/etcd.conf

ETCD_NAME=default

ETCD_DATA_DIR= "/ var/lib/etcd/default.etcd"

ETCD_LISTEN_CLIENT_URLS= "http://0.0.0.0:4001"

ETCD_ADVERTISE_CLIENT_URLS= "http://0.0.0.0:4001"

2.3, start

[root@etcd ~] # systemctl start etcd.service

2.4, validation

[root@etcd ~] # etcd-version

Etcd Version: 2.0.13

Git SHA: 92e3895

Go Version: go1.4.2

Go OS/Arch: linux/amd64

# on master

[root@master ~] # telnet 172.16.0.3 4001

2.5, configure flannel

[root@etcd ~] # etcdctl mk / coreos.com/network/config'{"Network": "172.17.0.0Univer 16"}'

{"Network": "172.17.0.0plus 16"}

[root@etcd ~] # etcdctl get / coreos.com/network/config

{"Network": "172.17.0.0plus 16"}

3, install k8s

Servers: all server

# yum install kubernetes

Upgrade method:

# mkdir-p / home/install & & cd / home/install

# wget https://github.com/GoogleCloudPlatform/kubernetes/releases/download/v0.6.2/kubernetes.tar.gz

# tar-zxvf kubernetes.tar.gz

# tar-zxvf kubernetes/server/kubernetes-server-linux-amd64.tar.gz

# cp kubernetes/server/bin/kube* / usr/bin

3.1pint master configuration k8s

Master runs three components, including apiserver, scheduler, and controller-manager, which are only involved in the relevant configuration items.

[/ etc/kubernetes/config]

[root@master ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/config

KUBE_LOGTOSTDERR= "--logtostderr=true"

KUBE_LOG_LEVEL= "--vault 0"

KUBE_ALLOW_PRIV= "--allow_privileged=false"

KUBE_MASTER= "--master=http:://172.16.0.2:8080"

[/ etc/kubernetes/apiserver]

[root@master ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/apiserver

KUBE_API_ADDRESS= "--address=0.0.0.0"

KUBE_API_PORT= "--port=8080"

KUBELET_PORT= "--kubelet_port=10250"

KUBE_ETCD_SERVERS= "--etcd_servers= http://127.0.0.1:4001"

KUBE_SERVICE_ADDRESSES= "--portal_net=10.254.0.0/16"

KUBE_ADMISSION_CONTROL= "--admission_control=NamespaceAutoProvision,LimitRanger,ResourceQuota"

KUBE_API_ARGS= ""

[/ etc/kubernetes/controller-manager]

[root@master ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/controller-manager

KUBELET_ADDRESSES= "--machines=127.0.0.1172.16.0.4172.16.0.5"

KUBE_CONTROLLER_MANAGER_ARGS= ""

[/ etc/kubernetes/scheduler]

[root@master ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/scheduler

KUBE_SCHEDULER_ARGS= ""

3.2Boot k8s service on the Personnal master

# systemctl start kube-apiserver.service kube-controller-manager.service kube-scheduler.service

# systemctl enable kube-apiserver.service kube-controller-manager.service kube-scheduler.service

3.3, check the k8s version

[root@master ~] # kubectl version

Client Version: version.Info {Major: "1", Minor: "0 +", GitVersion: "v1.0.0-290-gb2dafdaef5acea", GitCommit: "b2dafdaef5aceafad503ab56254b60f80da9e980", GitTreeState: "clean"}

Server Version: version.Info {Major: "1", Minor: "0 +", GitVersion: "v1.0.0-290-gb2dafdaef5acea", GitCommit: "b2dafdaef5aceafad503ab56254b60f80da9e980", GitTreeState: "clean"}

Error report:

[root@master ~] # kubectl version

Client Version: version.Info {Major: "1", Minor: "0 +", GitVersion: "v1.0.0-290-gb2dafdaef5acea", GitCommit: "b2dafdaef5aceafad503ab56254b60f80da9e980", GitTreeState: "clean"}

Error: couldn't read version from server: Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused

Resolve:

Need to configure k8s, see above!

3.4Gen minion configuration k8s

Minion runs two components, kubelet proxy, and the corresponding configurations are config and kubelet

You also need to configure docker on minion, see 3.5

[/ etc/kubernetes/config]

[root@minion1 ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/config

KUBE_LOGTOSTDERR= "--logtostderr=true"

KUBE_LOG_LEVEL= "--vault 0"

KUBE_ALLOW_PRIV= "--allow_privileged=false"

KUBE_MASTER= "--master= http://172.16.0.2:8080"

[root@localhost ~] # grep-Ev "^ $| ^ #" / etc/kubernetes/kubelet

KUBELET_ADDRESS= "--address=0.0.0.0"

KUBELET_HOSTNAME= "--hostname_override=172.16.0.4"

KUBELET_API_SERVER= "--api_servers= http://172.16.0.2:8080"

KUBELET_ARGS= ""

3.5 configure docker on the minute minion

Configure docker for remote administration.

[root@minion1 ~] # grep-Ev "^ $| ^ #" / etc/sysconfig/docker

OPTIONS='--selinux-enabled-H tcp://0.0.0.0:2375-H fd://'

DOCKER_CERT_PATH=/etc/docker

# there may be an error when starting docker. You can leave it unconfigured.

3.6Configuring flanneld

[root@minion1 ~] # grep-Ev "^ $| ^ #" / etc/sysconfig/flanneld

FLANNEL_ETCD= "http://172.16.0.3:4001"

FLANNEL_ETCD_KEY= "/ coreos.com/network"

Launch k8srec dockerflanneld on 3.7 dwelling minion.

[root@minion1 ~] # systemctl start docker.service flanneld.service

[root@minion1 ~] # systemctl start kubelet.service kube-proxy.service

If the ip addresses set by docker0 and flannel are different, you can modify them in the following ways

# systemctl stop docker

# ifconfig docker0 down

# brctl delbr docker0

# systemctl start docker

3.8 daiocker starts reporting an error

[root@localhost sysconfig] # systemctl start docker

Job for docker.service failed. See 'systemctl status docker.service' and' journalctl-xn' for details.

[root@localhost sysconfig] # systemctl status docker.service

Docker.service-Docker Application Container Engine

Loaded: loaded (/ usr/lib/systemd/system/docker.service; disabled)

Drop-In: / usr/lib/systemd/system/docker.service.d

└─ flannel.conf

Active: failed (Result: exit-code) since three 2015-09-16 14:18:47 CST; 11s ago

Docs: http://docs.docker.com

Process: 9150 ExecStart=/usr/bin/docker-d $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)

Main PID: 9150 (code=exited, status=1/FAILURE)

September 16 14:18:47 localhost.localdomain systemd [1]: Starting Docker Application Container Engine...

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.842291856+08:00" level=info msg= "Listening for...sock)"

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.861153138+08:00" level=error msg= "WARNING: No... n use"

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.889459632+08:00" level=info msg= "[graphdriver]... per\"

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.902509183+08:00" level=warning msg= "Running mo...tus 1"

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.907255506+08:00" level=info msg= "Firewalld run...false"

September 16 14:18:47 localhost.localdomain docker [9150]: time= "2015-09-16T14:18:47.949811560+08:00" level=fatal msg= "Error starti....61.1"

September 16 14:18:47 localhost.localdomain systemd [1]: docker.service: main process exited, code=exited, status=1/FAILURE

September 16 14:18:47 localhost.localdomain systemd [1]: Failed to start Docker Application Container Engine.

September 16 14:18:47 localhost.localdomain systemd [1]: Unit docker.service entered failed state.

Hint: Some lines were ellipsized, use-l to show in full.

[root@localhost sysconfig] # docker-d

INFO [0000] Listening for HTTP on unix (/ var/run/docker.sock)

ERRO [0000] WARNING: No-- storage-opt dm.thinpooldev specified, using loopback; this configuration is strongly discouraged for production use

INFO [0000] [graphdriver] using prior storage driver "devicemapper"

WARN [0000] Running modprobe bridge nf_nat br_netfilter failed with message:, error: exit status 1

INFO [0000] Firewalld running: false

INFO [0000] Loading containers: start.

INFO [0000] Loading containers: done.

INFO [0000] Daemon has completed initialization

INFO [0000] Docker daemon commit=3043001/1.7.1 execdriver=native-0.2 graphdriver=devicemapper version=1.7.1

Solution:

If the ip addresses set by docker0 and flannel are different, you can modify them in the following ways

# systemctl stop docker

# ifconfig docker0 down

# brctl delbr docker0

# systemctl start docker

Note: when testing with a virtual machine, if the minion virtual machine is cloned, the docker0 and flannel network segment addresses of the two ninion virtual machines will be the same, resulting in a NotReady state. Therefore, you need to clone the master virtual host and configure it to the minion state.

4. Cluster operation

View node information

[root@master ~] # kubectl get nodes

Error 1:

Error from server: 501: All the given peers are not reachable (failed to propose on members [http://172.16.0.3:4001] twice [last error: Get http://172.16.0.3:4001/v2/keys/registry/minions?quorum=false&recursive=true&sorted=true: dial tcp 172.16.0.3 All the given peers are not reachable 4001: iUnip o timeout]) [0]

Reason:

Docker is not registered with etcd, check that docker is not started.

Error 2:

[root@localhost ~] # kubectl get nodes

NAME LABELS STATUS

127.0.0.1 kubernetes.io/hostname=127.0.0.1 NotReady

172.16.0.2 kubernetes.io/hostname=172.16.0.2 NotReady

172.16.0.4 kubernetes.io/hostname=172.16.0.4 NotReady

172.16.0.5 kubernetes.io/hostname=172.16.0.5 NotReady

Reason:

There is a problem with minion registering etcd. You need to check whether the port of etcd service is 2379 (etcd Version: 2.0.13)

), is it possible to telnet port 2379 on minion

This is the end of this article on "how to build a Docker cluster based on kubernetes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report