操作系統(tǒng)centos7就可以了,由于是參考官方安裝噪奄,兼容性不做考慮死姚,系統(tǒng)配置都是虛擬機(jī),能大點(diǎn)就最好勤篮,最小安裝2C4G單臺都毒,酌情看著配置,磁盤存儲放NFS就好了碰缔,能大點(diǎn)最好
操作系統(tǒng) | 作用 | 配置 | 硬盤 |
---|---|---|---|
centos 7 | master | 4C8G | 50G |
centos 7 | node1 | 4C16G | 50G |
centos 7 | node2 | 4C16G | 50G |
centos 7 | nfs | 2C4G | 200G |
一账劲、準(zhǔn)備工作
- 每個主機(jī)必須安裝有部署container
- 一些可以用來在主機(jī)間復(fù)制文件的基礎(chǔ)設(shè)施。例如
ssh
和scp
就可以滿足需求
二金抡、安裝container
yum -y install yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install containerd wget
wget https://github.moeyy.xyz/https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.1/crictl-v1.27.1-linux-amd64.tar.gz
tar xf crictl-v1.27.1-linux-amd64.tar.gz -C /usr/local/bin
containerd config default > /etc/containerd/config.toml
sed -i 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml
sed -i 's@registry.k8s.io/pause:3.6@daocloud.io/daocloud/pause:3.9@' /etc/containerd/config.toml
systemctl daemon-reload
systemctl start containerd
systemctl enable containerd
cat >> /etc/crictl.yaml << EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 3
debug: true
EOF
三瀑焦、安裝k8s
修改hosts文件
以下步驟master和node都需要執(zhí)行一邊操作
cat <<EOF | tee /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.60 master
172.16.0.61 node-1
172.16.0.62 node-2
172.16.0.63 node-3
EOF
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile
yum -y install nfs-utils
打開內(nèi)置的橋功能,這個是借助于iptables來實(shí)現(xiàn)的
modprobe br_netfilter
echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables
echo "1" > /proc/sys/net/ipv4/ip_forward
cat <<EOF | tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
關(guān)閉swap
swapoff -a && sysctl -w vm.swappiness=0
sed -i '/swap/d' /etc/fstab
systemctl disable firewalld && systemctl stop firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
啟用ipvs
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
添加yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/repodata/repomd.xml.key
EOF
安裝k8s服務(wù)
#master安裝
yum -y install kubeadm-1.26.4-0 kubelet-1.26.4-0 kubectl-1.26.4-0
#node安裝
yum -y install kubeadm-1.26.4-0 kubelet-1.26.4-0
systemctl enable --now kubelet
cat <<EOF > kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.2.31
bindPort: 6443
nodeRegistration:
criSocket: unix:///var/run/containerd/containerd.sock
imagePullPolicy: IfNotPresent
name: master
taints: null
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: daocloud.io/daocloud
#imageRepository:registry.cn-hangzhou.aliyuncs.com/google_containers #阿里云鏡像
kind: ClusterConfiguration
kubernetesVersion: 1.26.2
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/24
serviceSubnet: 10.234.0.0/24
scheduler: {}
EOF
命令補(bǔ)全
yum install -y epel-release bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
部署網(wǎng)絡(luò)組件
四梗肝、部署node-dns-cache
- 下載文件
wget https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml
- 修改文件
#IPTABLES 模式
sed -i 's/__PILLAR__DNS__SERVER__/10.96.0.10/g;s/__PILLAR__LOCAL__DNS__/169.254.20.10/g;s/__PILLAR__DNS__DOMAIN__/cluster.local/g' nodelocaldns.yaml
#ipvs 模式
sed -i "s/__PILLAR__LOCAL__DNS__/169.254.20.10/g; s/__PILLAR__DNS__DOMAIN__/cluster.local/g; s/,__PILLAR__DNS__SERVER__//g; s/__PILLAR__CLUSTER__DNS__/10.96.0.10/g" nodelocaldns.yaml
sed -i 's/10.96.0.10/169.254.20.10/g' /var/lib/kubelet/config.yaml
sed -i 's/110/240/g' /var/lib/kubelet/config.yaml
systemctl daemon-reload
systemctl restart kubelet
kubectl apply -f nodelocaldns.yaml
需要修改所有節(jié)點(diǎn)的kubelet榛瓮,然后檢驗(yàn)結(jié)果