host规划

/bin/cp -arf /etc/hosts /etc/hosts_bak
:> /etc/hosts
cat <<EOF | tee  /etc/hosts
127.0.0.1    localhost
172.16.0.10 master
172.16.0.11 node1
172.16.0.17 node2
172.16.0.3 edge
172.16.0.120 bare
172.16.0.13 nfs
172.16.0.13     hub.my.com
172.16.0.2      jenkins.my.com
EOF
cat /etc/hosts

准备环境

#clean
timedatectl set-timezone Asia/Shanghai
kubeadm reset 
yum remove -y kubelet kubeadm kubectl
rm -rf /root/.kube /etc/kubernetes

#打开内置的桥功能
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
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

# swap SELINUX
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

docker安装

https://sre.ink/centos-quickly-docker/

aliyun kubernetes repo

rm -rf /etc/yum.repos.d/kubernetes.repo

cat <<EOF | tee /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 -y kubelet kubeadm kubectl
systemctl enable --now kubelet

镜像拉取 初始化master

kubeadm config images pull --config kubeadm.yaml
kubeadm init   --apiserver-advertise-address=172.16.0.10   --image-repository registry.aliyuncs.com/google_containers   --kubernetes-version v1.20.4   --service-cidr=10.96.0.0/12   --pod-network-cidr=10.244.0.0/16

calico cni

# https://kubernetes.io/docs/concepts/cluster-administration/addons/
# https://docs.projectcalico.org/getting-started/kubernetes/self-managed-onprem/onpremises
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
kubectl -n kube-system get pods |grep calico

kubectl profile

mkdir -p HOME/.kube
cp -i /etc/kubernetes/admin.confHOME/.kube/config
chown (id -u):(id -g) $HOME/.kube/config

or:

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile

ipvs mode

kubernetes修改为ipvs模式

worker kubeadm join

kubeadm token create --print-join-command
kubeadm join 172.16.0.10:6443 --token znd5ff.y2b9bo2h40fero7x \
    --discovery-token-ca-cert-hash sha256:4899a66e66216d9315107ac79fabe868f64bc97b0ca19803756fff586e10d187 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code