目录
- 前言
- 1、安装docker
- 2、安装Kubernetes
- 1、基本环境
- 2、安装kubelet、kubeadm、kubectl(三台机器全部都要设置)
- 3、初始化master节点
- 3、安装Calico网络插件
- 4、加入worker节点
- 5、验证
- 总结
前言
安装前请准备
选择4核8G(master)、8核16G(node1)、8核16G(node2) 三台机器,按量付费进行实验,CentOS7.9这里的机器默认都是干净的,建议租云上的机器,差不多一个小时3块钱,自己搭虚拟机也行
云上机器
vpc网络: 172.31.0.0/16私有网络:172.31.0.0/24安全组端口开放:22、30000~32767
1、安装Docker
请在三台机器上安装docker,执行下面的命令即可
sudo yum remove docker* sudo yum install -y yum-utils #配置docker的yum地址 sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #安装指定版本 sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6 # 启动&开机启动docker systemctl enable docker --now # docker加速配置 sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "s开发者_自动化torage-driver": "overlay2" } EOF sudo systemctl daemon-reload sudo systemctl restart docker
2、安装Kubernetes
1、基本环境
每个机器使用内网ip互通
每个机器配置自己的hostname,不能用localhost
三台机器设置hostname
#设置每个机器自己的hostname hostnamectl set-hostname xxx 例如: hostnamectl set-hostname master hostnamectl set-hostname node1 hostnamectl set-hostname node2
基础设置(三台机器全部都要设置)
# 将 SELinux 设置为 permissive 模式(相当于将其禁用) sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config #关闭swap关闭分区 swapoff -a sed -ri 's/.*swap.*/#&/' /etc/fstab #允许 iptables 检查桥编程客栈接流量 cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf br_netfilter EOF cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sudo sysctl --system
2、安装kubelet、kubeadm、kubectl(三台机器全部都要设置)
#配置k8s的yum源地址 cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF #安装 kubelet,kubeadm,kubectl sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 #启动kubelet sudo编程客栈 systemctl enable --now kubelet
⚠️ 注意⚠️ : 三台机器同时写一个域名来配置master节点的ip地址
#所有机器配置master域名 echo "172.31.0.4 k8s-master" >> /etc/hosts
3、初始化master节点
1、初始化
⚠️ - apiserver-advertise-address = 你master节点的ip
⚠️ - control-plane-endpoint = 你上面配置的域名kubeadm init \ --apiserver-advertise-address=172.31.0.4 \ --control-plane-endpoint=k8s-master \ --image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \ --kubernetes-version v1.20.9 \ --service-cidr=10.96.0.0/16 \ --pod-network-cidr=192.168.0.0/16
2、记录关键信息
当前初始化完成之后将会输出下面的信息,记得保存到本地哦
⚠️下面的操作将用到这个输出的内容,下面的操作请不要复制我这里的命令,以自己的实际输出为准
Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf 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/clhttp://www.devze.comuster-administration/addons/ You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root: kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \ --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240 \ --control-plane Then you can join any number of worker nodes by running the following on each as root: kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \ --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff编程客栈77907240
保存后执行输出中的内容
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
3、安装Calico网络插件
先下载calico.yaml ,然后使用kubectl来部署
curl https://docs.projectcalico.org/manifests/calico.yaml -O kubectl apply -f calico.yaml
4、加入worker节点
上面成功部署之后输出的内容注意,最后面
Then you can join any number of worker nodes by running the following on each as root: kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \ --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240
将命令复制到其他的node节点上执行,如果master上也执行了,则master也当作成一个工作节点了
扩展:加入master节点(多个master节点)
上面成功部署之后输出的内容注意,最后面
You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root: kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \ --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240 \ --control-plane
在其他你需要成为master节点的机器上执行即可
5、验证
kubectl get node
至此安装成功
总结
到此这篇关于centos系统安装Kubernetes集群步骤的文章就介绍到这了,更多相关centos安装Kubernetes内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
精彩评论