版本
docker版本:20.10.25
k8s版本(kubeadm,kubelet和kubectl):1.20.10-0
初始化
bash
# 禁用 SELinux
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# 关闭防火墙
sudo systemctl stop firewalld
sudo systemctl disable firewalld
# 关闭 swap
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
准备环境
角色 | IP |
---|---|
master | 192.168.11.139 |
node1 | 192.168.11.140 |
node2 | 192.168.11.141 |
bash
每台机器都要添加
$ vi /etc/hosts
192.168.11.139 master
192.168.11.140 node1
192.168.11.141 node2
安装docker
安装的版本20.10.25-1.amzn2023.0.1
bash
$ sudo yum install -y docker-20.10.25-1.amzn2023.0.1
启动docker
$ systemctl start docker
安装K8S
- 添加 Kubernetes 仓库
bash
$ vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
- 安装 kubeadm, kubelet, 和 kubectl,三台机器都要安装
bash
$ sudo yum install -y kubelet-1.20.10-0 kubeadm-1.20.10-0 kubectl-1.20.10-0
- 初始化master节点
bash
$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16
- 安装成功
- 设置kubectl配置文件
bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- 安装 Pod 网络插件
bash
$ sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- 加入node工作节点
在node1和node2运行
bash
从主节点复制 kubeadm join 命令
$ kubeadm join 192.168.11.139:6443 --token 8u9xi5.eaffhbpk6yrsr52f \
--discovery-token-ca-cert-hash sha256:883c0637ffc0825b79f6fb40c1c9473775b564b3532f5f3a64332cdxxxxx
bash
master节点查看
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 118m v1.20.10
node1 Ready <none> 69m v1.20.10