貔貅云原生

貔貅云原生

Kubez-Ansible快速部署

96
0
0
2024-05-15
Kubez-Ansible快速部署

使用 Kubez-Ansible 快速安装 Kubernetes

环境准备

需要部署节点与其他节点配置免密,并且配置 hosts

# 主机名: kube01 
# IP: 192.168.159.130
# 角色: Master

# 主机名:kube02
# IP: 192.168.159.131 
# 角色: Node

基础包安装

yum install git ansible python2-pip

pip install pbr

下载 kubez-ansible 代码并安装

# 用 git 下载相关代码,并切换与系统对应分支
git clone https://github.com/pixiu-io/kubez-ansible.git

cd kubez-ansible.git

# 切换分支,因为此分支对应的系统是 Centos7.9
git checkout stable/tiger

cd ..

# pip 安装 kubez-ansible 项目
pip install kubez-ansible/

复制配置文件

# 把 kubez 文件夹复制到 etc 目录
cp  -rf kubez-ansible/etc/kubez  /etc/

# 修改配置文件
vi /etc/kubez/globals.yml
# 把 eth0 改为 ens33,因为本机网卡为 ens33
network_interface: "ens33"

# 复制清单到当前路径,并修改内容
cp kubez-ansible/ansible/inventory/multinode  .

# 只修改了 docker-master 组跟 docker-node 组里主机清单
[root@kube01 ~]# cat multinode 
# When master nodes and woker nodes use different interfaces,
# you need to comment out "api_interface" from the globals.yml
# and specify like below:
#kube01  api_interface=ep66

# User local connection in the assign groups, such as:
#[docker-master]
#localhost       ansible_connection=local

# These hostname must be resolvable from your deployment host
[docker-master]
kube01

# The above can also be specified as follows:
#kube[01:02]

[docker-node]
kube02

[containerd-master]

[containerd-node]

[storage]
kube01


# Don't change the bellow groups
[kube-master:children]
docker-master
containerd-master

[kube-node:children]
docker-node
containerd-node

[baremetal:children]
kube-master
kube-node
storage

[kubernetes:children]
kube-master
kube-node

[nfs-server:children]
storage

[haproxy:children]
kube-master

安装

# 执行以下 3 步,可直接完成 Kubernetes 安装
# 注意需要免密与hosts
kubez-ansible -i multinode bootstrap-servers

kubez-ansible -i multinode deploy

kubez-ansible -i multinode post-deploy

验证

# 部署完成后,默认为flannel-cni、ingress、storageclass
# 如需修改cni或者安装别的插件,可以查看 /etc/kubez/global.yml 文件修改
[root@kube01 ~]# kubectl get node 
NAME     STATUS   ROLES                  AGE     VERSION
kube01   Ready    control-plane,master   5m31s   v1.23.6
kube02   Ready    <none>                 5m7s    v1.23.6