在昨天的笔记中波波记录了K8S的单机安装,通常情况下在稍微有些规模的企业基本上都是集群式的管理,因此本篇笔记通过模拟的形式来分享K8s单master多node模式安装。
环境概览:
操作系统:CentOS 7
master IP : 122.114.197.231 k8s-master01
node IP : 122.114.197.232 k8s-node01
122.114.197.233 k8s-node02
一、前期准备:
参考CentOS7安装K8s(单机安装)图文教程:https://www.zkii.net/system/infrastructure/4565.html 的第一步。
本篇笔记不再详述。
hosts记录如下:
- # vi /etc/hosts
- 122.114.197.231 k8s-master01
- 122.114.197.232 k8s-node01
- 122.114.197.233 k8s-node02
二、安装组件(所有服务器)
1、设置阿里镜像,建立repo文件。
- # vi /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
2、安装 kubeadm, kubelet 和 kubectl
- # yum install -y kubectl-1.12.10
- # yum install -y kubelet-1.12.10
- # yum install -y kubeadm-1.12.10
- # yum install -y ipvsadm
3、配置kubelet使用国内pause镜像,修改cgroup配置
- # vi /etc/sysconfig/kubelet
- 添加配置如下:
- KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs"
4、启动kubelet
- # systemctl daemon-reload
- # systemctl enable kubelet && systemctl start kubelet
三、kubernetes安装(master服务器)
1、拉取镜像
- # docker pull mirrorgooglecontainers/kube-apiserver:v1.12.10
- # docker pull mirrorgooglecontainers/kube-proxy:v1.12.10
- # docker pull mirrorgooglecontainers/kube-controller-manager:v1.12.10
- # docker pull mirrorgooglecontainers/kube-scheduler:v1.12.10
- # docker pull mirrorgooglecontainers/etcd:3.2.24
- # docker pull kuberneter/coredns:1.2.2
- # docker pull mirrorgooglecontainers/pause:3.1
- 给镜像打标签
- # docker tag mirrorgooglecontainers/kube-apiserver:v1.12.10 k8s.gcr.io/kube-apiserver:v1.12.10
- # docker tag mirrorgooglecontainers/kube-controller-manager:v1.12.10 k8s.gcr.io/kube-controller-manager:v1.12.10
- # docker tag mirrorgooglecontainers/kube-scheduler:v1.12.10 k8s.gcr.io/kube-scheduler:v1.12.10
- # docker tag mirrorgooglecontainers/kube-proxy:v1.12.10 k8s.gcr.io/kube-proxy:v1.12.10
- # docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
- # docker tag mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
- # docker tag kuberneter/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
2、安装
- # kubeadm init --kubernetes-version=v1.12.10 --pod-network-cidr=122.144.0.0/16
- 记录类似如下的结果串,用于后续节点添加
- kubeadm join 122.114.197.231:6443 --token 24cser.h747zmiipvikbgq8 --discovery-token-ca-cert-hash sha256:1b0b32be09c2ab5635da85eb9fcc23a67497a44b03a3072ae694ca07a884e7d6
3、配置环境变量
- # vi ~/.bash_profile
- 加入一行:export KUBECONFIG=/etc/kubernetes/admin.conf
- # source ~/.bash_profile
4、flannel安装
使用kube-flannel.yml文件
- # kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
5、验证安装
- # kubectl get pod -n kube-system
- # kubectl get node
四、node安装
1、执行之前记录下的串,例如:
- # kubeadm join 122.114.197.231:6443 --token 24cser.h747zmiipvikbgq8 --discovery-token-ca-cert-hash sha256:1b0b32be09c2ab5635da85eb9fcc23a67497a44b03a3072ae694ca07a884e7d6
2、在master上验证node
- # kubectl get node