安装k8s 1.18版

kubeadm 安装k8s 1.18版

1.环境要求(最低2C2G)

主机名ip地址cup及内存要求
master-01172.16.1.612c2g(关闭swap)
node-01172.16.1.622c2g(关闭swap)
node-02172.16.1.632c2g(关闭swap)

2.初始化环境

2.1.关闭防火墙和selinux

#所有节点
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

2.2.修改内核参数

#所有节点
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system

2.3.关闭系统swap交换分区

#所有节点
swapoff -a
#修改/etc/fstab,注释交换分区
vim /etc/fstab

2.4.修改主机名

#控制节点
hostnamectl set-hostname k8s01
#node节点
hostnamectl set-hostname k8s02
#node节点
hostnamectl set-hostname k8s03

2.5.配置host解析

#所有节点
echo 172.16.1.15 k8s01 >> /etc/hosts
echo 172.16.1.16 k8s02 >> /etc/hosts
echo 172.16.1.17 k8s03 >> /etc/hosts

2.6.配置repo源

#所有节点
yum install wget -y
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#查看docke-ce版本
yum list docker-ce --showduplicates | sort -r
#安装docker
yum install docker-ce -y
systemctl start docker && systemctl enable docker

3.安装kuberadm

#所有节点
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 install kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0 -y
systemctl start kubelet && systemctl enable kubelet

4.初始化k8s集群

kubeadm init --kubernetes-version=v1.18.0 --image-repository registry.aliyuncs.com/google_containers  --pod-network-cidr=10.244.0.0/16 --service-cidr=10.254.0.0/16

5.配置flannel网络

#控制节点执行
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sed -i 's/quay.io/quay-mirror.qiniu.com/' kube-flannel.yml
#在安装k8s过程中,执行kubectl apply -f kube-flannel.yml,会出现flannel Init:ImagePullBackOff错误,原因是quay.io镜像地址在国内访问不了,执行命令 修改镜像地址,而且coredns pod的pending会也变成Running。
#修改网段范围为
kubectl create -f kube-flannel.yml
kubectl get all -n kube-system
kubectl get nodes
kubectl -n kube-system get pod      #等一会都会变成running

7.命令补全

yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
kubectl completion bash >/etc/bash_completion.d/kubectl

8.新增node节点

#master
kubeadm token create --print-join-command	#master节点输出增加节点的命令
kubeadm token list                          #获取token信息

9.在需要新增的node节点上执行输出的内容

kubeadm join 10.0.0.61:6443 --token kgsqai.vsfb0615vyjyoios     --discovery-token-ca-cert-hash sha256:c26ab46250edba990615f252a4149122b8c71fb82abc83defa9484845edf69bb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值