Detailed installation Kubernetes platform

1. Overview
Kubernetes is a Google open source container orchestration engine, which supports automated deployment, large-scale scalable application container management. When deploying an application in a production environment, typically deploy multiple instances of the application in order to load balance the application request.

In Kubernetes, we can create multiple containers, each instance of an application running inside, and then through the built-in load balancing strategy, manage the application examples in this group, found that access to, and operation and maintenance of these details are not required personnel to carry out complex manual configuration and processing, this article describes the installation process Kubernetes platform.
1.1. Environmental preparation
Kubernetes installed on Ubuntu, CentOS both more stable environment, this will install Ubuntu environment as an example (CentOS environment similar), prepare two Ubuntu virtual machine or a cloud server, version 16.04 can be.

2. Install & Kubernetes Docker
2.1 installation Docker.
2.1.1 official source added Docker
1) Update Package Index:

apt-get update

2) Download docker official source of public and added to the public database apt:

curl-fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
Detailed installation Kubernetes platform

3) Add warehouse docker official sources:

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Detailed installation Kubernetes platform

4) After completion of the commands above, add the following in the file /etc/apt/sources.list

Detailed installation Kubernetes platform

5) Update Package Index again:

apt-get update

2.1.1 Installation Docker
here to install the docker-ce-17.03.2 version, for example:
1) execute:

apt-get install docker-ce=17.03.2~ce-0~ubuntu-xenial,安装Docker;

2) Verify Docker installation:

dockerversion

3) view the situation docker background service running:

systemctl status docker

At this point, Docker installation is complete.
2.2 Installation Kubernetes
2.2.1 describes Kubernetes associated components
need to download kubeadm, kubelet, kubectl components such as
1) kubeadm: boot as mounted to the cluster tool, kubeadm kubernetes the core assembly of the container and attached boot operation;

2) kubelet: Node assembly

kubelet still running on all nodes of the cluster in the form of kubernetes host back-end services, is the primary node from the node with the key components to interact;
3) kubectl: after the installation of the cluster command-line tool, at least mounted on the master, of the cluster management.

2.2.2 Adding Kubernetes apt sources (google official source)
will be added directly google the official source (if your server can not access google official source, please refer to 2.2.3)
1) add the public key file kubernetes apt sources:

curl-s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

2) The official source added to the list of local source list configuration directory:

vi /etc/apt/sources.list.d/kubernetes.list, was added in the following document:

Detailed installation Kubernetes platform

3) update the local package cache: apt-get update

2.2.3 Add Kubernetes apt sources (domestic sources)
1) Update && apt apt-GET-GET -y install apt-Transport-HTTPS

2) curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

3) vi /etc/apt/sources.list.d/kubernetes.list, added to the file: the deb https://mirrors.aliyun.com/kubernetes/apt/ Kubernetes main-xenial

4) update the local package cache:

apt-get update

2.2.4 installation kubeadm, kubelet, kubectl tool
1) apt-get install -y kubelet kubeadm kubectl

2) apt-get install kubeadm 1.10.2-00 kubectl = = = 1.10.2-00 omelet 1.10.2-00

(To install the specified version)
3)

Check installation:
View version: kubeadm version
View version: kubectl version
to check the status: systemctl status kubelet, this time to see the state, not the running of the state, is active, in regular restart state, which is required because the kubelet the configuration has not been provided, only in the implementation of kubeadm init or perform kubeadm join in the work node node master node, kubelet configuration required in order to be satisfied, kubelet will be up and running properly.
2.2.5 Download core component image
by default during the installation guide kubeadm cluster kubernetes automatically downloaded from the network core components, such as: apiserver, scheduler, controller manager, kubeproxy the like, but the default is from k8s.gcr.io ( google
container mirrored platform download), the domestic can not connect. Master node needs now following core components:
Detailed installation Kubernetes platform

1) start with the domestic source (can be found from the dockerhub) above downloaded to the local core components, for example: docker pull gcrxio / kube-apiserver-amd64: v1.14.1

2) Re-labeling, for example: docker tag gcrxio / kube-apiserver-amd64: v1.14.1 k8s.gcr.io/kube-apiserver-amd64:v1.14.1

3) In the Worker node only needs to download pause, and the mirror can kube-proxy.

2.2.6 Initialization Master Node
1) performs kubeadm init command to initialize: kubeadm init --apiserver-advertise-address = 172.16.154.177 --pod-network-cidr = 192.168.16.0 / 20,

As shown below:

Detailed installation Kubernetes platform

2)设置kubectl访问控制平面,设置环境变量:export

KUBECONFIG=/etc/kubernetes/admin.conf

3)查看安装情况:kubectl get pods -n kube-system

Detailed installation Kubernetes platform

以上除了dns,其他的组件都是running状态,dns要等到安装了网络插件之后才正常。
2.2.7 安装网络插件
Kubernetes的网络插件很多,这里以安装Weave为例:

1)安装Weave Net

kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')

2)创建weave.yaml文件,如下:

Detailed installation Kubernetes platform

3)执行命令进行安装:Kubectl apply -f weave.yaml

4)验证安装结果:kubectl get pods -n kube-system
Detailed installation Kubernetes platform

2.2.8 安装worker节点
1)按照前面的步骤,在worker节点上(比如是k8s2)安装docker环境

2)按照前面的步骤,在k8s2节点上安装kubeadm、kubelet

3)按照前面的步骤,在k8s2节点上下载pause和kube-proxy镜像

2.2.9 将worker节点加入集群
1)在k8s2节点上执行kubeadm join命令:kubeadm join

172.16.154.178:6443 --token ab7j9d.rxopqtvyv7qf6488 --discovery-token-ca-cert-hash

sha256:c0d784704724ea4be3b7bb31a61404aa05a591b596405699e7c36fe3a500bec9

自此,Kubernetes集群已经安装完成。
2.3. 安装Dashboard
2.3.1 下载dashboard镜像文件
1) docker pull gcrxio/kubernetes-dashboard-amd64:v1.10.1

2) docker tag gcrxio/kubernetes-dashboard-amd64:v1.10.1

k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1

2.3.2 安装dashboard
1)下载dashboard配置文件,执行如下命令:

curl-L https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml > kubernetes-dashboard.yaml
2)修改dashboard配置文件kubernetes-dashboard.yaml,并在此文件中的Service部分下添加

type: NodePort和nodePort: 31233,这里的31233端口可以根据实际情况进行设置,如下图:
Detailed installation Kubernetes platform

3)创建Pod,执行命令:

kubectl create -f {path}/kubernetes-dashboard.yaml

2.3.3 Access dashboard
download dashboard profile, run the following command: L-curl
. 1) access address: https://47.97.249.8:31233
Detailed installation Kubernetes platform

This article is my product of the entrepreneurial team MadPecker technical team to write, reproduced, please indicate the source.

Guess you like

Origin blog.51cto.com/14322715/2404231