Kubernetes集群搭建(centos7)
部署架构
ip | 域名 | 备注 | 安装软件 |
---|---|---|---|
192.168.2.246 | master | 主节点 | Docker Kubeadm kubelet kubectl flannel |
192.168.2.247 | node1 | 从节点 1 | Docker Kubeadm kubelet kubectl |
环境准备
- 2台虚拟机CentOS7.x-86_x64
- 硬件配置:2GB或更多RAM,2个CPU或更多CPU,硬盘30GB或更多
- 集群中所有机器之间网络互通
- 可以访问外网,需要拉取镜像
- 禁止swap分区
设置静态ip
vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.2.247
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=114.114.114.114
// 重启网络
systemctl restart network
修改yum源
yum install wget
rm -rf /etc/yum.repos.d/*
// 重新下载阿里云源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum list && yum clean all
Master节点安装 kubeadm, kubelet and kubectl
-
安装基本软件包
yum install net‐tools vim bash‐comp* ‐y
-
设置主机名,管理节点设置主机名为master
hostnamectl set‐hostname master su -
-
配置节点域名
vim /etc/hosts 192.168.2.246 master 192.168.2.247 node1
-
关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
-
关闭SeLinux
setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
-
关闭 swap
swapoff -a yes | cp /etc/fstab /etc/fstab_bak cat /etc/fstab_bak |grep -v swap > /etc/fstab
-
配置Docker, K8S的阿里云yum源
cat >>/etc/yum.repos.d/kubernetes.repo <<EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo yum clean all && yum repolist
-
安装指定版本kubeadm, kubelet and kubectl
yum install -y kubeadm-1.23.0-0 kubectl-1.23.0-0 kubelet-1.23.0-0 --disableexcludes=kubernetes vim /etc/sysconfig/kubelet # 添加下面的配置 KUBELET_CGROUP_ARGS="--cgroup-driver=systemd" KUBE_PROXY_MODE="ipvs # 设置开机启动 systemctl daemon-reload && systemctl enable kubelet systemctl restart kubelet kubeadm init --kubernetes-version=1.23.0 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
-
创建必要文件
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
-
修改Services的负载均衡模式为ipvs
kubectl edit configmap kube-proxy -n kube-system mode: "ipvs" # 删除现有的kube-proxy类型的pods
-
安装flannel网络插件
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml kubectl apply -f kube-flannel.yml
-
从节点join到master
kubeadm join 192.168.2.246:6443 --token 7lye11.tvmmnsdzrnexwh6c --discovery-token-ca-cert-hash sha256:5a20061b20b7de56aebcaea7f9903352ae23981377ca9cfe45dd01e24bcfe751 # 查看nodes kubectl get nodes