准备三台机器 一个master节点两个node节点
这里安装了三台虚拟机 虚拟机内存最低2g cpu最低双核
lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.3.1611 (Core)
Release: 7.3.1611
Codename: Core
vim /etc/hosts
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 设置开机禁用防火墙
setenforce 0 临时关闭selinux模式
sed -ri ‘s/(^SELINUX=).*/\1disabled/‘ /etc/selinux/config 永久关闭selinux模式
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
资源http://www.jeepyurongfu.net/blog/64.html
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io -y
docker --version
docker info |grep Cgroup
Cgroup Driver: cgroupfs
systemctl start docker.service
systemctl enable docker.service
[root@localhost yum.repos.d]# vim /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
yum install kubelet kubeadm kubectl –y
vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
说明:
--fail-swap-on:关闭交换分区,kubernetes不允许开启交换分区
vim /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.2"
#--cgroup-driver:指定Cgroup drivers用谁 k8s推荐使用systemd
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://fl791z1h.mirror.aliyuncs.com"]
,"insecure-registries":["https://hub.kumo.com"]
}
//保存上面信息
然后执行
#重启docker服务
systemctl daemon-reload
systemctl restart docker
查看docker Cgroup
docker info|grep Cgroup
Cgroup Driver: systemd //此时docker的cgroup是systemd
kubeadm init --kubernetes-version=1.18.2 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.10.0.0/16 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.136.100
E0317 17:02:15.077598 1 main.go:289] Error registering network: failed to acquire lease: node "k8s-master" pod cidr not assigned
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.136.100:6443 --token ga73u1.qw4c525xniinghrq \
--discovery-token-ca-cert-hash sha256:286b3d4b64bb3b535e9fea7efb95c4a0b1c6b563d55be3e40f1b51a8239e3ff6
如果初始化失败,可执行kubeadm reset后重新初始化
[root@master01 ~]# kubeadm reset
[root@master01 ~]# rm -rf $HOME/.kube/config
[root@master01 ~]# mkdir -p $HOME/.kube
[root@master01 ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
scp /etc/kubernetes/admin.conf [email protected]:/app
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
注意此文件需要 你可以先获得此yml文件然后上传到虚拟机去再去执行此文件我这里之前已经下载了文件直接执行此文件
kubectl get pods --all-namespaces
图中显示flannel 状态是镜像下载失败可能是网络的问题所以这里我 去其他集群中直接导出一份镜像再导入到此linux
通过docker save 和docker load
再次执行以下命令
kubectl delete -f kube-flannel.yml
kubectl apply -f kube-flannel.yml
kubectl get pods --all-namespaces
flannel启动正常
kubectl get -A pods -o wide
至此k8s集群搭建完毕
tail -f /var/log/messages 执行此命令查看日志查找错误
有时报错关于systemd的错误可能原因是systemd需要升级执行以下命令即可
后面有时间再去补充仪表盘的搭建...