ubantu 24,使用kubekey v3.x部署 k8s v1.26.15 及 kubesphere v3.4.0
三个节点:
master节点:k8s-master-01,ip:172.29.128.1
工作节点1: k8s-worker-01,ip:172.29.132.68
工作节点2: k8s-worker-02,ip:172.29.132.69
【前期准备】
切换 root,更新系统
sudo -i apt update && apt upgrade -y
设置主机名(分别对应每台机器执行)
#master节点01 hostnamectl set-hostname k8s-master-01 #工作节点01 hostnamectl set-hostname k8s-worker-01 #工作节点02 hostnamectl set-hostname k8s-worker-02
所有节点写入 hosts 解析
cat >> /etc/hosts << EOF 172.29.128.1 k8s-master-01 172.29.132.68 k8s-worker-01 172.29.132.69 k8s-worker-02 EOF
关闭防火墙、禁用 swap
# 关闭ufw systemctl stop ufw systemctl disable ufw # 永久关闭swap swapoff -a sed -i '/swap/s/^/#/' /etc/fstab
加载内核模块、开启 ip 转发(k8s 必需)
modprobe overlay modprobe br_netfilter cat >> /etc/sysctl.conf << EOF net.bridge.bridge-nf-call-iptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1 EOF sysctl -p
安装依赖工具
apt install -y curl wget openssh-server sshpass tar unzip ipset ipvsadm
【SSH免密登录,仅在master节点做】
# 生成免密密钥 ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa # 分发公钥到各节点 ssh-copy-id root@172.29.128.1 ssh-copy-id root@172.29.132.68 ssh-copy-id root@172.29.132.69 # 验证免密连通 ssh root@172.29.128.1 hostname ssh root@172.29.132.68 hostname ssh root@172.29.132.69 hostname
步骤 3:验证免密(master 执行)
ssh root@172.29.132.68 ssh root@172.29.132.69
设置KKZONE为国源内,永久生效(所有节点执行)
先查看一下如果/etc/profile 里有 export KKZONE=cn 这一句配置,就勿需再执行了。
echo "export KKZONE=cn" >> /etc/profile source /etc/profile
【安装kubekey 3.1.9】 仅在 master 节点 k8s-master-01
【方式一:在线安装】kubekey 3.1.9是目前kubekey 3.x里最新版,最稳定,长期版本。
export KKZONE=cn curl -sfL https://get-kk.kubesphere.io | VERSION=v3.1.9 sh - mv kk /usr/local/bin/ kk version
【方式二:手动二进制包下载】kubekey 3.1.9
wget https://github.com/kubesphere/kubekey/releases/download/v3.1.9/kubekey-v3.1.9-linux-amd64.tar.gz tar -zxvf kubekey-v3.1.9-linux-amd64.tar.gz chmod +x kk mv kk /usr/local/bin/ kk version
查看当前版本kubekey支持哪些k8s版本
kk version --show-supported-k8s
生成集群配置文件(指定 k8s v1.26.15)
mkdir -p /data/kubekey cd /data/kubekey kk create config --with-kubernetes v1.26.15 --with-kubesphere -f k8s-cluster.yaml
编辑 k8s-cluaster.yaml 的k8s配置,kubesphere 配置用默认的就可以了
vim k8s-cluster.yaml
apiVersion: kubekey.kubesphere.io/v1alpha2 kind: Cluster metadata: name: sample spec: hosts: - {name: k8s-master-01, address: 172.29.128.1, internalAddress: 172.29.128.1, user: root, password: "yihan@123"} - {name: k8s-worker-01, address: 172.29.132.68, internalAddress: 172.29.132.68, user: root, password: "yihan@123"} - {name: k8s-worker-02, address: 172.29.132.69, internalAddress: 172.29.132.69, user: root, password: "yihan@123"} roleGroups: etcd: - k8s-master-01 control-plane: - k8s-master-01 worker: - k8s-worker-01 - k8s-worker-02 - k8s-master-01 #master节点也可以用作工作节点,也可以不用作工作节点, controlPlaneEndpoint: ## Internal loadbalancer for apiservers # internalLoadbalancer: haproxy domain: lb.kubesphere.local address: "" port: 6443 kubernetes: version: v1.26.15 clusterName: cluster.local autoRenewCerts: true containerManager: containerd etcd: type: kubekey network: plugin: calico kubePodsCIDR: 10.233.64.0/18 kubeServiceCIDR: 10.233.0.0/18 ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni multusCNI: enabled: false registry: privateRegistry: "" namespaceOverride: "" registryMirrors: [] insecureRegistries: [] addons: [] --- #kubesphere配置省略,用默认生成的即可
验证yaml文件是否有语法错误
python3 -c "import yaml; yaml.safe_load(open('k8s-cluster.yaml')); print('YAML语法正常')"
输出 YAML语法正常表示语法正确。
一条命令安装k8s + kubesphere
kk create cluster -f k8s-cluster.yaml
如果生成k8s-cluster.yaml配置文件的时候没有带参数 --with-kubesphere,可以指定同时安装 kubesphere:
kk create cluster -f k8s-cluster.yaml --with-local-storage --with-kubesphere

浙公网安备 33010602011771号