Kubeadm部署Kubernetes1、环境准备主机名IP说明宿主机系统k8s-master10.0.0.101Kubernetes集群的master节点Ubuntu2004k8s-node110.0.0.102Kubernetes集群的node节点Ubuntu20041-1、关闭防火墙、iptables、centos系列需要关闭selinux #所有节点执行: [root@ubuntu2004 ~]#systemctl stop ufw [root@ubuntu2004 ~]#iptables -nvL
1-2、各节点主机名相互解析 #所有节点执行: [root@ubuntu2004 ~]#hostnamectl set-hostname k8s-master [root@ubuntu2004 ~]#vim /etc/hosts 10.0.0.101 master 10.0.0.102 node ?
1-3、时间同步 #所有节点执行: [root@master ~]#apt install -y chrony [root@master ~]#vim /etc/chrony/chrony.conf server ntp.aliyun.com iburst [root@master ~]#systemctl enable --now chrony [root@master ~]#chronyc sources
1-4、禁用swap #所有节点执行: [root@master ~]#swapoff -a [root@master ~]#vim /etc/fstab #/swap.imgnone swap sw0 0
1-5、修改网桥内核参数 #所有节点执行: #允许 iptables 检查桥接流量 [root@master ~]#apt install -y bridge-utils #默认没有该模块,需要安装 [root@master ~]#cat <<EOF | tee /etc/modules-load.d/modules.conf br_netfilter EOF [root@master ~]#modprobe br_netfilter [root@master ~]#lsmod | grep br_netfilter ? [root@master ~]#cat > /etc/sysctl.d/kubernetes.conf <<EOF net.bridge.bridge-nf-call-arptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1 user.max_user_namespaces=28633 EOF ? [root@master ~]#sysctl -p /etc/sysctl.d/kubernetes.conf
2、安装docker #所有节点执行: [root@master ~]#apt install docker.io -y #ubuntu默认自动启动并开机启动,如果未设置请手动设置 ? #配置加速器,使用 systemd 来管理容器的 cgroup [root@master ~]#mkdir -p /etc/docker [root@master ~]#vim /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ], "experimental": false, "debug": false, "max-concurrent-downloads": 10, "registry-mirrors": ["https://pgavrk5n.mirror.aliyuncs.com"] } [root@master ~]#systemctl daemon-reload [root@master ~]#systemctl restart docker ?
3、部署k8sMaster节点【Kubeadm部署Kubernetes】 # 所有节点执行: # 可参考阿里云官网:https://developer.aliyun.com/mirror/kubernetes # 使apt支持ssl传输 并安装kubelet kubeadm kubectl [root@master ~]#apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl [root@master ~]#apt-get update && apt-get install -y apt-transport-https curl 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-get update apt-get install -y kubelet=1.23.1-00 kubeadm=1.23.1-00 kubectl=1.23.1-00 ? # 阻止自动更新(apt upgrade时忽略) 。所以更新的时候先unhold,更新完再hold 。 apt-mark hold kubelet kubeadm kubectl # 先不要启动,如果启动会报错
#master上执行(10.0.0.101): [root@master ~]#vim kubeadm-config.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: 10.0.0.101 #当前机器的局域网地址 bindPort: 6443 nodeRegistration: criSocket: /var/run/dockershim.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: registry.cn-hangzhou.aliyuncs.com/google_containers kind: ClusterConfiguration kubernetesVersion: 1.23.1 networking: dnsDomain: cluster.local serviceSubnet: 10.96.0.0/12 scheduler: {} --- kind: KubeletConfiguration apiVersion: kubelet.config.k8s.io/v1beta1 #cgroupDriver: systemd cgroupDriver: cgroupfs ?
推荐阅读
- 含源码 【YOLOv5】手把手教你使用LabVIEW ONNX Runtime部署 TensorRT加速,实现YOLOv5实时物体识别
- 云原生之旅 - 6)不能错过的一款 Kubernetes 应用编排管理神器 Kustomize
- 云原生之旅 - 5)Kubernetes时代的包管理工具 Helm
- 云原生之旅 - 4)基础设施即代码 使用 Terraform 创建 Kubernetes
- 二 Istio:在Kubernetes(k8s)集群上安装部署istio1.14
- .NET6打包部署到Windows Service
- docker swarm快速部署redis分布式集群
- 7 步保障 Kubernetes 集群安全
- 使用 etcdadm 快速、弹性部署 etcd 集群
- Cenots7 离线安装部署PostgreSQL