[容器]Centos7 kubeadm 部署 k8s1.20
@Centos7 kubeadm 部署 k8s1.20基础环境1.确保每台机器上有dockerDocker部署2.关闭 每台机器上的swap,selinuxswapoff -asetenforce 0sed -i 's/^SELINUX=enforcing$/SELINUX=disable/' /etc/selinux/config3.注释swap的挂载vi /etc/fstab#/dev/map
·
基础环境
1.确保每台机器上有docker
Docker部署
2.关闭 每台机器上的swap,selinux
swapoff -a
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disable/' /etc/selinux/config
3.注释swap的挂载
vi /etc/fstab
#/dev/mapper/centos-swap swap swap defaults 0 0
4.配置k8s的路由参数(防止kubeadm报路由警告)
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
5.载入配置
sysctl --system
1.master节点
部署kubeadm、kubectl、kubelet
1.添加k8s阿里云源
cat <<EOF > /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
EOF
yum update
2.查看可以安装的版本
yum list kubeadm --showduplicates | sort -r
3.安装并启动
此时启动的kubelet状态为失败,集群初始化后正常
yum install -y kubelet-1.20.1-0 kubeadm-1.20.1-0 kubectl-1.20.1-0 --disableexcludes=kubernetes
systemctl start kubelet
systemctl enable kubelet
4.初始化集群
kubeadm init \
--apiserver-advertise-address=10.0.0.1 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.20.1 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.2.0.0/16 \
--service-dns-domain=cluster.local \
--ignore-preflight-errors=Swap \
--ignore-preflight-errors=NumCPU \
--v=6
参数说明:
apiserver-advertise-address 设置 apiserver 绑定的 IP
image-repository 指定阿里云镜像仓库
kubernetes-version 要安装的版本
service-cidr 指定service 的IP 范围
pod-network-cidr 指定pod网络
service-dns-domain 指定 service 的 dns 后缀
ignore-preflight-errors 忽略前置检查错误,被忽略的错误将被显示为警告
v=6 初始化过程显示详细内容,方便排错
5.添加节点
集群初始化后会生成token,添加节点时用
如果忘了token需要重新生成
kubeadm token create
查看状态
如果出现图上错误,执行以下操作即可
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile
支持命令补全
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
kubectl completion bash >/etc/bash_completion.d/kubectl
6.部署网络插件flannel
git clone --depth 1 https://github.com/flannel-io/flannel.git
/ 修改资源配置清单
cd flannel/Documentation/
vim kube-flannel.yml
egrep -n "10.2.0.0|mirror|eth0" kube-flannel.yml
128: "Network": "10.2.0.0/16",
172: image: quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
186: image: quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
192: - --iface=eth0
/ 应⽤资源配置清单
kubectl create -f kube-flannel.yml
过一会查看状态
node节点
1.安装kubeadm和kubelet并启动
yum install -y kubelet-1.20.1-0 kubeadm-1.20.1-0 kubectl-1.20.1-0 --disableexcludes=kubernetes
systemctl start kubelet
systemctl enable kubelet
2.加入k8s集群
kubeadm join 10.0.0.1:6443 --token ytu1a6.rkkd2f6s4cq26coz \
--discovery-token-ca-cert-hash sha256:6582807224c2ed7b276efc1755cc01fe3f53d2bef587c4d89bf1de5d386b1e43
master节点
查看集群
给节点打标签
kubectl label nodes node1 node-role.kubernetes.io/node=
kubectl label nodes node2 node-role.kubernetes.io/node=
kubectl label nodes node3 node-role.kubernetes.io/node=
更多推荐
已为社区贡献3条内容
所有评论(0)