内网IP | 配置 | 节点角色 |
---|---|---|
172.17.0.9 | 2C4G | k8s-master |
172.17.0.8 | 2C2G | k8s-node1 |
172.17.0.17 | 2C2G | k8s-node2 |
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
ps: 以上两条命令2选1执行
sed -ri 's/.swap./#&/' /etc/fstab # 永久(需要重启机器才能生效)
swapoff -a # 临时
ps: 以上两条命令2选1执行,第一条命令需要重启机器生效!
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
cat >> /etc/hosts << EOF
172.17.0.9 k8s-master
172.17.0.8 k8s-node1
172.17.0.17 k8s-node2
EOF
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 执行该命令生效
yum install ntpdate -y
ntpdate time.windows.com
所有节点安装docker(略)
docker安装
修改docker配置,设置cgroup驱动
vim /etc/docker/daemon.json
{
// 添加以下内容
"exec-opts": ["native.cgroupdriver=systemd"],
}
systemctl daemon-reload //重新加载docker服务的配置文件
systemctl restart docker
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
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-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
systemctl start kubelet
systemctl enable kubelet
kubeadm config images list --image-repository registry.aliyuncs.com/google_containers
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers
kubeadm init \
--apiserver-advertise-address=172.17.0.9 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all
# –apiserver-advertise-address # k8s-master 机器 ip
# –image-repository # 指定阿里云镜像仓库地址
# –kubernetes-version # k8s版本,需要与安装版本一致
# –service-cidr #集群内部虚拟网络,pod统一访问入口
# –pod-network-cidr # k8s内部的pod节点之间网络可以使用的IP段
# eg: 形式如下
kubeadm join 172.16.0.9:6443 --token 3pzsx0.xys1k68ntvtpa58q \
--discovery-token-ca-cert-hash sha256:391515fc9c9f19651553afb2454e7797459c69d56f015559e694dc07a118f8ee
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
ps: 下载不下来, 通过网站https://tool.lu/ip/获取域名 raw.githubusercontent.com 最新的ip地址,写入hosts即可
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend"": {
"Type": "vxlan"
}
}
kubectl apply -f kube-flannel.yml
kubectl get pod --all-namespaces
ps: 需要所有的pod状态为running才可以
kubectl get cs
ps: 需要为Healthy才可以
kubectl get nodes
ps: 此时只有主节点,子节点尚未加入集群
kubeadm join 172.16.0.9:6443 --token 3pzsx0.xys1k68ntvtpa58q --discovery-token-ca-cert-hash sha256:391515fc9c9f19651553afb2454e7797459c69d56f015559e694dc07a118f8ee
kubectl get nodes
ps: 必须要都为Ready状态才算正常