kubeadm 安裝k8s 1.18版
1.環境要求(最低2C2G)
主機名 | ip地址 | cup及記憶體要求 |
---|
master-01 | 172.16.1.61 | 2c2g(關閉swap) |
node-01 | 172.16.1.62 | 2c2g(關閉swap) |
node-02 | 172.16.1.63 | 2c2g(關閉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