kubeadm installation Kubernetes 1.14 Best Practices

Kubernetes as a container layout tools to simplify container management, improve work efficiency popular. Domestic Ali cloud deployment is the simplest method Kubernetes.
A, Kubernetes Profile
Kubernetes (referred K8S) is an open source cluster management system container, the container can be achieved automated cluster deployment, automatic scaling capacity, maintenance and other functions. It is a container layout tool, but also a new distributed architecture based program leading container technology. On the basis of Docker technology, providing a container for the application of the deployment operation, resource scheduling, service discovery and dynamic stretching and other functions, improve the convenience of large-scale container cluster management.
K8S management node in the cluster is working with two types of nodes. Management is responsible for K8S node cluster management, cluster information exchange, task scheduling between nodes, it is also responsible for managing container, Pod, NameSpaces, PV and other life cycle. Pod working node container and provide computing resources mainly, Pod and containers all run on worker nodes, the nodes to work through kubelet service node to communicate with management in order to manage the life cycle of the container, and to communicate with other nodes in the cluster.
 
Second, prepare the environment
Kubernetes support running physical server or a virtual machine, virtual machine is ready to use this test environment, the hardware configuration information as shown below:
IP addresses
Node Role
CPU
Memory
Hostname
Disk
10.10.10.10
master
>=2c
>=2G
master
sda, sdb
10.10.10.11
worker
>=2c
>=2G
node1
sda, sdb
10.10.10.12
worker
>=2c
>=2G
node2
sda, sdb
Note: the following steps on all nodes
1. Set the hostname hostname, host name setting management node master.
hostnamectl set-hostname master
When you need to set a different host name, master can be replaced with the correct hostname node1, node2 can be.
2. Edit / etc / hosts file, add the domain name resolution.
cat <<EOF >>/etc/hosts 10.10.10.10 master 10.10.10.11 node1 10.10.10.12 node2 EOF
 
3.关闭防火墙、selinux和swap。
systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config swapoff -a sed -i 's/.*swap.*/#&/' /etc/fstab
 
4.配置内核参数,将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf <<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
 
5.配置国内yum源
yum install -y wget mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo yum clean all && yum makecache
 
配置国内Kubernetes源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
 
配置 docker 源
 
三、软件安装
注:在所有节点上进行如下操作
1.安装docker
yum install -y docker-ce-18.06.1.ce-3.el7 systemctl enable docker && systemctl start docker docker --version Docker version 18.06.1-ce, build e68fc7a
docker服务为容器运行提供计算资源,是所有容器运行的基本平台。
2.安装kubeadm、kubelet、kubectl
yum -y install docker-ce-18-09 kubelet-1.14.2 kubeadm-1.14.2 kubectl--1.14.2 --disableexcludes=kubernetes systemctl enable kubelet
Kubelet负责与其他节点集群通信,并进行本节点Pod和容器生命周期的管理。 Kubeadm是Kubernetes的自动化部署工具,降低了部署难度,提高效率。Kubectl是Kubernetes集群管理工具。
四、部署master 节点
注:在master节点上进行如下操作
1.在master进行Kubernetes集群初始化。
kubeadm init --kubernetes-version=1.14.2 \ --apiserver-advertise-address= 10.10.10.10 \ master ip --image-repository registry.aliyuncs.com/google_containers \ --service-cidr=10.1.0.0/16 \ --pod-network-cidr=10.244.0.0/16
 
添加开机自启(包括node)
systemctl enable kubelet.service
 
定义POD的网段为: 10.244.0.0/16, api server地址就是master本机IP地址。
这一步很关键,由于kubeadm 默认从官网k8s.grc.io下载所需镜像,国内无法访问,因此需要通过 –image-repository指定阿里云镜像仓库地址,很多新手初次部署都卡在此环节无法进行后续配置
记录生成的最后部分内容,此内容需要在其它节点加入Kubernetes集群时执行。
kubeadm join 10.10.10.10:6443 --token kekvgu.nw1n76h84f4camj6 \ --discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e
 
2.配置kubectl工具
mkdir -p /root/.kube cp /etc/kubernetes/admin.conf /root/.kube/config kubectl get nodes kubectl get cs
 
3.部署flannel网络
 
4.重置kubectl
kubeadm reset
 
五、部署node节点
注:在所有node节点上进行如下操作
执行如下命令,使所有node节点加入Kubernetes集群
kubeadm join 10.10.10.10:6443 --token kekvgu.nw1n76h84f4camj6 \ --discovery-token-ca-cert-hash sha256:4ee74205227c78ca62f2d641635afa4d50e6634acfaa8291f28582c7e3b0e30e
此命令为集群初始化时(kubeadm init)返回结果中的内容。
 
六、集群状态检测
注:在master节点上进行如下操作
1.在master节点输入命令检查集群状态,返回如下结果则集群状态正常。
kubectl get nodes NAME     STATUS   ROLES    AGE     VERSION master   Ready    master   26m     v1.14.2 node1    Ready    <none>   3m10s   v1.14.2 node2    Ready    <none>   3m      v1.14.2
重点查看STATUS内容为 Ready时,则说明集群状态正常。
2.创建Pod以验证集群是否正常。
kubectl create deployment nginx --image=nginx kubectl expose deployment nginx --port=80 --type=NodePort kubectl get pod,svc
七、部署Dashboard
注:在master节点上进行如下操作
1.创建Dashboard的yaml文件
sed -i 's/k8s.gcr.io/loveone/g' kubernetes-dashboard.yaml sed -i '/targetPort:/a\ \ \ \ \ \ nodePort: 30001\n\ \ type: NodePort' kubernetes-dashboard.yaml
 
2.部署Dashboard
kubectl create -f kubernetes-dashboard.yaml
3.创建完成后,检查相关服务运行状态
kubectl get deployment kubernetes-dashboard -n kube-system kubectl get pods -n kube-system -o wide kubectl get services -n kube-system netstat -ntlp|grep 30001
4.在Firefox浏览器输入Dashboard访问地址:https://10.10.10.10:30001
5.查看访问Dashboard的认证令牌
kubectl create serviceaccount dashboard-admin -n kube-system kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
6.使用输出的token登录Dashboard。
 
认证通过后,登录Dashboard首页如图
 

 

Guess you like

Origin www.cnblogs.com/carl007/p/11345173.html