Kubernetes 安裝
系統分層
就像Linux擁有內核(kernel)、核心系統類庫、和可選的用戶級工具,kubernetes也擁有功能和工具的層次。對於開發者來說,理解這些層次是非常重要的。kubernetes APIs、概念和功能都在下面的層級圖中得到體現。
環境配置
增加節點DNS 別名
cat <<EOF >>/etc/hosts
192.168.209.160 k8a
192.168.209.172 k8b
192.168.209.173 k8c
EOF
驗證下ping k8b && ping k8c
復制hosts到其他節點
scp /etc/hosts root@k8b:/etc/hosts
scp /etc/hosts root@k8c:/etc/hosts
添加kube-master到kube-node的秘鑰認證
ssh-keygen
ssh-copy-id hostname
在k8a上驗證下ssh key
ssh k8b
ssh k8c
關閉SELinux sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config setenforce 0
關閉系統防火墻
systemctl stop firewalld
systemctl disable firewalld
關閉sawp分區 swapoff -a vi /etc/fstab 註釋掉swap分區 #/dev/mapper/cl-swap swap swap defaults 0 0
腳本
swapoff -a && sysctl -w vm.swappiness=0
添加配置內核參數/etc/sysctl.d/k8s.conf文件
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.all.forwarding = 1
vm.swappiness = 0
EOF
sysctl -p /etc/sysctl.d/k8s.conf
更新依賴庫
yum install -y device-mapper-persistent-data lvm2 yum-utils
增加淘寶docker源
yum-config-manager --add-repo? http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install -y docker-ce
啟動docker
systemctl enable docker && systemctl start docker
增加淘寶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
安裝k8s 組件
yum install -y kubeadm kubectl kubelet
master節點啟動組件
systemctl enable kubelet && systemctl start kubelet
驗證版本
kubeadm version
Kubernetes 安裝