Install a cluster combat deployment Kubernetes

kubernetes Overview:

Kubernetes is an open source, cloud management platform for application of the container on multiple hosts, Kubernetes goal is to make application deployment container of simple and effective (powerful), Kubernetes provides application deployment, planning, updates, maintenance a mechanism.
Kubernetes is Google 2014 founded management is the open source version of Google 10 years of large-scale container management technology Borg.

By kubernetes function can be achieved:

  • Rapid deployment of applications
  • Rapid expansion application
  • Seamless connection of new application functionality
  • Save resources, optimize the use of hardware resources

Our goal is to promote the improvement of the ecosystem components and tools, in order to reduce the burden on the application running in the public cloud or private cloud.

kubernetes features:

  • Portable: support for public cloud, private cloud, hybrid cloud, multi-cloud (multi-cloud)
  • Scalable : modular, plug-in, then it can mount, may be combined
  • Automation: automatic deployment, automatic restart, automatic replication, automatic retractable / expansion

Why use container? Container benefits summed up:

  • Quickly create / deploy applications: Compared with VM virtual machine, create a mirror container easier.
  • Continued development, integration and deployment: provide reliable and frequent container mirroring build / deploy, and use quick and simple rollback (due mirror immutability).
  • Development and operation of phase separation: Create a container mirror build or release stage, so that applications and infrastructure decoupling.
  • Development, test and production environments Consistency: consistency (production) running in local or external network.
  • Cloud platform or other operating systems: Engine, or you can run any other environment in Ubuntu, RHEL, CoreOS, on-prem, Google Container.
  • Loosely coupled, distributed, flexible, micro-services of: application into smaller, separate components may be dynamically deployed and managed.
  • Resource isolation
  • Use of resources: more efficient

What kubernetes do?
Container applications can run on a cluster Kubernetes physical or virtual machine, Kubernetes able to provide a "container-centric infrastructure" to meet the needs of some of the common applications running in a production environment, such as:

  • Multiple processes (running as a container) to work together. (Pod)
  • Storage system mounts
  • Distributing secrets
  • Application Health Check
  • Copy of application examples
  • Pod automatic retractable / extension
  • Naming and discovering
  • Load Balancing
  • Rolling updates
  • Resource Monitoring
  • Log visits
  • Debugging Applications
  • Provide authentication and authorization

kubernetes Chinese official website:
https://kubernetes.io/zh/
kubernetes Chinese community:
https://www.kubernetes.org.cn/doc-11

Clusters built kubernetes

Preparing the environment:

Three dockerhost host (centos7)
Master: 172.16.1.30
node01: 172.16.1.31
node02: 172.16.1.32
Note : Each virtual machine memory at least 2GB, the lowest dual core cpu, each host must install docker environment, turn off the firewall (usually kubernetes is run within the company), disable selinux, to ensure time synchronization.

We are now installing kubernetes, use is kubernetes official developed automated deployment software (kubeadm), since for faster installation kubernetes.

Empty iptables rules, and reload docker:

[root@master ~]# iptables -F
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl restart docker

(1) modify the host name:

[root@sqm-docker01 ~]# hostnamectl  set-hostname  master
[root@sqm-docker01 ~]# bash
[root@sqm-docker02 ~]# hostnamectl  set-hostname  node01
[root@sqm-docker02 ~]# bash
[root@sqm-docker03 ~]# hostnamectl set-hostname node02
[root@sqm-docker03 ~]# bash

(2) ssh, DNS, free secret login:

配置域名解析:
[root@master ~]# vim /etc/hosts

Install a cluster combat deployment Kubernetes
## copy files to other nodes hosts:

[root@master ~]# scp /etc/hosts  [email protected]:/etc/hosts
[root@master ~]# scp /etc/hosts  [email protected]:/etc/hosts
免密登录:
[root@master ~]# ssh-keygen -t rsa  #生成密钥

Install a cluster combat deployment Kubernetes
Copy to another node keys:
[the root Master @ ~] # SSH-Copy-ID amdha01
[the root Master @ ~] # SSH-Copy-ID amdha02

(3) Disable swap (kubernetes characteristics)
Note: All nodes must be disabled, or can not join the cluster.
[root@master ~]# swapoff -a #临时生效
Install a cluster combat deployment Kubernetes

永久禁用swap:(修改开机加载配置文件)
[root@master ~]# vim /etc/fstab

Install a cluster combat deployment Kubernetes

可以重新加载使其生效:
[root@master ~]# mount -a

Installation kubernetes:

Log in Alibaba open mirror sites, download source yum:
Install a cluster combat deployment Kubernetes
Install a cluster combat deployment Kubernetes
Writing custom repo file :( three nodes need to be deployed)

[root@master yum.repos.d]# pwd
/etc/yum.repos.d
[root@master yum.repos.d]# vim kubernetes.repo

Install a cluster combat deployment Kubernetes

查看可用的repo源:
[root@master yum.repos.d]# yum repolist

Install a cluster combat deployment Kubernetes
## is generated in the local cache:
[root@master yum.repos.d]# yum makecache
Install a cluster combat deployment Kubernetes
## repo copy files to node01 and node02:

[root@master yum.repos.d]# scp kubernetes.repo  node01:/etc/yum.repos.d/
[root@master yum.repos.d]# scp kubernetes.repo  node02:/etc/yum.repos.d/

Next perform the same operation on both nodes.

(2) Open iptables bridging function (three nodes are to be deployed)

[root@master ~]# vim /etc/sysctl.d/k8s.conf    #在该目录下自定义conf文件
//添加以下配置项:
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
//重新加载文件使其生效:
[root@master ~]#  sysctl -p /etc/sysctl.d/k8s.conf 
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1

Note: If the message "File not found", we need to load a module:
[root @ Master ~] # modprobe br_netfilter

The configuration file copy to node01 and node02 deployment.

(3) Open routing and forwarding (three nodes are to be deployed)

[root@master ~]# echo net.ipv4.ip_forward = 1 > /etc/sysctl.conf 
[root@master ~]# sysctl -p   #加载该文件,使其生效
net.ipv4.ip_forward = 1

The same copy configuration files to node01 and node02 deployment.


(4) operating in the master node:

#修改yum的配置文件,缓存下面要下载的rpm包:
[root@master ~]# vim /etc/yum.conf 

Install a cluster combat deployment Kubernetes
Download:
[root@master ~]# yum -y install kubelet-1.15.0-0 kubeadm-1.15.0-0 kubectl-1.15.0-0

下载完成后查看是否缓存了rpm包:
[root@master ~]#  cd /var/cache/yum/x86_64/7/kubernetes/packages

Install a cluster combat deployment Kubernetes

##将服务加入开机自启:
[root@master ~]# systemctl enable kubelet.service
Install a cluster combat deployment Kubernetes
初始化集群(下载镜像):
可是由于国内网络环境限制,我们不能直接从谷歌的镜像站下载镜像,这时,需要我们手工从docker镜像站下载镜像,然后重新命名,这里用脚本来实现。
脚本部分内容如下:
#可以参考这样的格式进行下载:
[root@master ~]# cat k8s.sh
#!/bin/bash
docker pull mirrorgooglecontainers/kube-apiserver:v1.14.1
docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.1
docker pull mirrorgooglecontainers/kube-scheduler:v1.14.1
docker pull mirrorgooglecontainers/kube-proxy:v1.14.1
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd:3.3.10
docker pull coredns/coredns:1.3.1

这里我是已经下载好了,只需要导入形影的镜像即可:
[root@master ~]# mkdir images
[root@master ~]# cd images/
Install a cluster combat deployment Kubernetes
导入镜像命令:docker load --input
Install a cluster combat deployment Kubernetes

##初始化集群:
[root@master images]# kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap

参数解释:
--kubernetes-version:指定当前kubernetes版本号(查看版本:kubelet --version)
--pod-network: 指定pod网段,kubernetes默认指定网络。
--ignore:忽略所有报错

Install a cluster combat deployment Kubernetes

注意:如果初始化成功后的信息信息被覆盖了想要重新初始化,可以先执行kubeadm reset命令重置一下,再重新初始化。
而当你执行完重置命令后,初始化时,可能会报以下错误:
Install a cluster combat deployment Kubernetes
报错指的是数据库的一个error,所以我们需要将该目录该删除掉,就可以重新初始化了:
[root@master ~]# rm -rf /var/lib/etcd

##根据上面的提示创建目录并授予权限:

[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config

##查看节点:
Install a cluster combat deployment Kubernetes
可以看出master的状态是未就绪(NotReady),之所以是这种状态是因为还缺少一个附件flannel,没有网络各Pod是无法通信的。

#部署docker容器的跨主机网络:

//将该yml文件下载到本地:
[root@master ~]# wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Install a cluster combat deployment Kubernetes

//执行该yml文件:
[root@master ~]# kubectl apply -f kube-flannel.yml 

Install a cluster combat deployment Kubernetes

//查看配置好的yml文件:
Install a cluster combat deployment Kubernetes

(5)以上是主节点的安装部署,然后个node几点的安装
####node01和node02分别进行下载(无需安装kubectl):
[root@node01 ~]# yum -y install kubelet-1.15.0-0 kubeadm-1.15.0-0
[root@node02 ~]# yum -y install kubelet-1.15.0-0 kubeadm-1.15.0-0

###下载完成后将该服务加入开机自启:
[root@node01 ~]# systemctl enable kubelet.service 
[root@node02 ~]# systemctl enable kubelet.service 

node01:(导入本地镜像)

[root@node01 ~]# mkdir images
[root@node01 ~]# cd images/

Install a cluster combat deployment Kubernetes
Install a cluster combat deployment Kubernetes

These mirror copy ## to node02, installation:
[@ amdha01 the root Images] * amdha02 SCP #: / the root / Images

## After importing node02 View Mirror:
Install a cluster combat deployment Kubernetes

(6) to join the cluster nodes node01 and node02:
Execute the following command to the cluster (cluster initialization is generated, and each value is different)
kubeadm the Join 172.16.1.30:6443 --token 6udpmi.u4msx9vgkqfr1i1l --discovery -token-ca-cert-hash sha256 : 4fdbbb94d5d7087a6c27d441df2f89d21e9ca035f0386ed963a195656794619a
Install a cluster combat deployment Kubernetes

node02 nodes perform similar operations.

## When node01 and node02 to the cluster or to view information on the master node:
Install a cluster combat deployment Kubernetes
ensure that the information to other nodes, and the state are ready.

Note: If the status is NotReady, that is the problem of the network, the host is not deployed across the network, you need to perform a host of network deployment across the top docker container.

So far kubernetes cluster has been set up is completed ---------------------

Then to optimize the operation:

(1)更改tab距离:
[root@master ~]# vim .vimrc
set tabstop=2
[root@master ~]# source .vimrc
(2)//kubect命令自动补全:
[root@master ~]# yum install -y bash-completion
[root@master ~]# source /usr/share/bash-completion/bash_completion 
[root@master ~]# source <(kubectl completion bash)
[root@master ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
(3)//查看运行中的pod资源(资源对象中的一种),-n:namespace  kube-system(kubernetes自带的命名空间)
[root@master ~]# kubectl get pods -n kube-system

Install a cluster combat deployment Kubernetes
Kubernetes cluster content deployment is now complete. . .

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/13972012/2447791