系統環境: node節點 操作系統: CentOS-7-x86_64-DVD-1908.iso node節點 IP地址: 192.168.1.204 node節點 hostname(主機名, 請和保持node節點主機名 和master不同):k8s.node03 目標: 在該機器安裝k8s node ...
系統環境:
node節點 操作系統: CentOS-7-x86_64-DVD-1908.iso
node節點 IP地址: 192.168.1.204
node節點 hostname(主機名, 請和保持node節點主機名 和master不同):k8s.node03
目標: 在該機器安裝k8s node節點,並加入指定集群
步驟如下:
1. 安裝基礎工具
yum install vim yum install lrzsz yum install docker
systemctl start docker
systemctl enable docker
2. 檢查node節點所在系統時間,若和master節點時間不同,請修改node節點和master節點保持一致(我這裡時間和master基本一致,故不修改),修改時間的方式請 參考這裡
[root@k8s ~]# date Sun Oct 20 03:08:01 EDT 2019 [root@k8s ~]#
3. 關閉防火牆, 如果是公網主機請設置網路安全組,開放必要埠
systemctl stop firewalld
systemctl disable firewalld
4. 關閉SELINUX
setenforce 0
編輯文件 vim /etc/selinux/config 如下
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
5. 創建k8s配置文件 /etc/sysctl.d/k8s.conf
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
6. 執行以下命令使修改生效.
modprobe br_netfilter sysctl -p /etc/sysctl.d/k8s.conf
7.添加k8s yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [k8s] 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
yum makecache
8.安裝kubelet, kubectl kubeadm (指定版本號(1.13.1)安裝時 這三個東西請按照以下順序安裝)
yum install -y kubelet-1.13.1 yum install kubectl-1.13.1 yum install kubeadm-1.13.1
9.檢查已安裝的kubelet kubectl kubeadm 版本號
[root@k8s ~]# yum list installed|grep kube kubeadm.x86_64 1.13.1-0 @k8s kubectl.x86_64 1.13.1-0 @k8s kubelet.x86_64 1.13.1-0 @k8s kubernetes-cni.x86_64 0.6.0-0 @k8s
10.拉取必要docker 鏡像. 因為網路(需要梯子),如果node節點所在網路有梯子(可以直接訪問到功能變數名稱 k8s.gcr.io),那麼這個步驟可以忽略。
10.1,我這裡的master節點的這些基礎docker 鏡像的獲取方式如下。當然這些命令可以在node節點重新執行一遍,為了節約下載鏡像時間,我直接從master節點打包發送到node節點
docker pull docker.io/mirrorgooglecontainers/kube-apiserver-amd64:v1.13.1 docker tag docker.io/mirrorgooglecontainers/kube-apiserver-amd64:v1.13.1 k8s.gcr.io/kube-apiserver:v1.13.1 docker pull docker.io/mirrorgooglecontainers/kube-controller-manager-amd64:v1.13.1 docker tag docker.io/mirrorgooglecontainers/kube-controller-manager-amd64:v1.13.1 k8s.gcr.io/kube-controller-manager:v1.13.1 docker pull docker.io/mirrorgooglecontainers/kube-scheduler-amd64:v1.13.1 docker tag docker.io/mirrorgooglecontainers/kube-scheduler-amd64:v1.13.1 k8s.gcr.io/kube-scheduler:v1.13.1 docker pull docker.io/mirrorgooglecontainers/kube-proxy-amd64:v1.13.1 docker tag docker.io/mirrorgooglecontainers/kube-proxy-amd64:v1.13.1 k8s.gcr.io/kube-proxy:v1.13.1 docker pull docker.io/mirrorgooglecontainers/pause-amd64:3.1 docker tag docker.io/mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1 docker pull docker.io/mirrorgooglecontainers/etcd-amd64:3.2.24 docker tag docker.io/mirrorgooglecontainers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24 docker pull docker.io/coredns/coredns:1.2.6 docker tag docker.io/coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
10.2 , 【master節點】將master節點的所有必要docker 鏡像保存成壓縮包(如果你安裝的不是1.13.1,那麼save的時候這些tag請和 docker images 對照,切莫寫錯tag),並複製到node節點所在設備
docker save k8s.gcr.io/kube-proxy:v1.13.1 k8s.gcr.io/coredns:1.2.6 k8s.gcr.io/kube-controller-manager:v1.13.1 k8s.gcr.io/kube-apiserver:v1.13.1 k8s.gcr.io/kube-scheduler:v1.13.1 k8s.gcr.io/etcd:3.2.24 k8s.gcr.io/pause:3.1 -o k8s.1.13.1.tar scp k8s.1.13.1.tar 192.168.1.204:~/
10.3 , 【node節點】從壓縮包 恢復docker鏡像
cd ~ docker load -i k8s.1.13.1.tar
11. 關閉 swap
swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab echo "vm.swappiness=0">>/etc/sysctl.d/k8s.conf sysctl -p /etc/sysctl.d/k8s.conf echo 'Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --fail-swap-on=false"'>>/etc/systemd/system/kubelet.service.d/10-kubeadm.conf systemctl daemon-reload systemctl restart kubelet
12. 添加到集群
kubeadm join 192.168.1.201:6443 --token 6xnc86.n3ftiy9cu9wuyl5a --discovery-token-ca-cert-hash sha256:6dbcec4d2e20e8936e8d74714a194fa838cc6544f98bde41cd766b69b7a4fc12
13. 【master節點】檢查該節點是否部署成功,可以看到k8s.node03已添加成功
[root@localhost ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s.node01 Ready <none> 6h27m v1.13.1 k8s.node02 Ready <none> 6h38m v1.13.1 k8s.node03 Ready <none> 61s v1.13.1 localhost.localdomain Ready master 7h32m v1.13.1