kubernetes基于flanel开发的静态pod模型
环境配置:
- OS: Ubuntu 20.04.1
- Kubernetes:v1.24
- Container Runtime: Docker CE 20.10.17
- CRI:cri-dockerd v0.2.2
网络配置
node:172.29.1.0/24
pod:
services:
1.系统初始化
1.借助于chronyd服务(程序包名称chrony)设定各节点时间精确同步;
tzselect
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
apt install chrony
systemctl start chrony.service
2.通过DNS完成各节点的主机名称解析;
vim /etc/hosts
172.29.1.1 master01.magedu.com master01 kubeapi.magedu.com kubeapi
172.29.1.11 node01.magedu.com node01
172.29.1.12 node02.magedu.com node02
172.29.1.13 node03.magedu.com node03
3.各节点禁用所有的Swap设备;
swapoff -a && systemctl --type swap && systemctl mask SWAP_DEV
vim /etc/fstab
#swap #(禁用swap分区)
4.各节点禁用默认配置的iptables防火墙服务
systemctl mask firewalld
ufw disable && ufw status
#以上四步在master,和node节点上均要执行
2.安装docker环境
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install docker-ce
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://reg-mirror.qiniu.com",
"https://registry.docker-cn.com"
],
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload && systemctl start docker.service && systemctl enable docker.service
以上四步在master和nodeh上均操作或者复制一次
3.配置镜像代理服务 (master操作)
vim set-proxy.sh
#!/bin/bash
export HTTPS_PROXY="http://172.29.1.10:51854"
export HTTP_PROXY="http://172.29.1.10:51854"
export NO_PROXY="172.29.1.0/24,172.17.0.0/16,127.0.0.0/8,magedu.com"
exec bash
bash set-proxy.sh #以上过程在所有节点执行
vim /lib/systemd/system/docker.service
Environment="HTTP_PROXY=http://虚拟物理机网卡地址:代理端口"
Environment="HTTPS_PROXY=https://虚拟物理机网卡地址:代理端口"
Environment="NO PROXY=https://127.0.0.0/8,172.29.0.0/16:代理端口"
systemctl daemon-reload && systemctl restart docker.service #master执行
4.安装cri-dockerd
curl -LO https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.2/cri-dockerd_0.2.2.3-0.ubuntu-focal_amd64.deb
apt install ./cri-dockerd_0.2.2.3-0.ubuntu-focal_amd64.deb
apt update && apt install -y apt-transport-https curl
curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt update
apt install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl status kubelet
#以上操作均在其他三台机器上执行
4.调配kubelet和cri-dockerd协作
vim /usr/lib/systemd/system/cri-dockerd.service
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/cni/cache --cni-conf-dir=/etc/cni/net.d
systemctl daemon-reload && systemctl restart cri-docker.service && systemctl status cri-docker.service
mkdir /etc/sysconfig/ -p
vim kubelet
KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime-endpoint=/run/cri-dockerd.sock"
#scp到其他三台机器将修改的文件并加载重启
systemctl daemon-reload && systemctl restart docker.service
5.初始化master,node节点
#初始化master
kubeadm init --control-plane-endpoint kubeapi.magedu.com --kubernetes-version=v1.24.3 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --token-ttl=0 --cri-socket unix:///run/cri-dockerd.sock
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
cp /etc/kubernetes/admin.conf ~/.kube/config
kubectl apply -f kube-flannel.yaml
#node初始化
kubeadm join kubeapi.magedu.com:6443 --token o4p3b1.xdw7t4ztbibljuxo --discovery-token-ca-cert-hash sha256:06fd7243d057c27e2a1f865ea541f1bd0f417e28204e8d57fc1deab5ee5f51bf --cri-socket unix:///run/cri-dockerd.sock
6.测试编排工具
kubectl get pods -n kube-system
kubectl create deployment demoapp --image=ikubernetes/demoapp:v1.0 --replicas=3
kubectl create service nodeport demoapp --tcp=80:80
kubectl get svc -l app=demoapp
kubectl get pods