kubeasz简介

kubeasz 致力于提供快速部署高可用k8s集群的工具, 同时也努力成为k8s实践、使用的参考书;基于二进制方式部署和利用ansible-playbook实现自动化;既提供一键安装脚本, 也可以根据安装指南分步执行安装各个组件。

部署步骤

前置准备

i.规划集群

角色数量描述
部署节点1运行ansible/ezctl命令,一般复用第一个master节点
etcd节点3注意etcd集群需要1,3,5,...奇数个节点,一般复用master节点
master节点2高可用集群至少2个master节点
node节点n运行应用负载的节点,可根据需要提升机器配置/增加节点数

ii.部署节点需和其他节点ssh打通

下载ezdown

推荐版本对照

Kubernetes version1.221.231.241.251.261.271.281.29
kubeasz version3.1.13.2.03.6.23.6.23.6.23.6.23.6.23.6.3

 i.下载kubeasz

export release=3.6.2
wget https://github.com/easzlab/kubeasz/releases/download/${release}/ezdown

ii.为如下域名配置加速或者代理

x.x.x.x github.com objects.githubusercontent.com docker.io registry-1.docker.io production.cloudflare.docker.com dl.k8s.io cdn.dl.k8s.io

在部署节点编排k8s安装

chmod +x ezdown
#初始化
./ezdown -D -k v1.27.3

#容器化运行kubeasz
./ezdown -S

#创建新集群 k8s-01
#docker exec -it kubeasz ezctl new k8s-01
2024-05-16 11:21:35 DEBUG generate custom cluster files in /etc/kubeasz/clusters/k8s-01
2024-05-16 11:21:35 DEBUG set versions
2024-05-16 11:21:35 DEBUG cluster k8s-01: files successfully created.
2024-05-16 11:21:35 INFO next steps 1: to config '/etc/kubeasz/clusters/k8s-01/hosts'
2024-05-16 11:21:35 INFO next steps 2: to config '/etc/kubeasz/clusters/k8s-01/config.yml'

根据实际情况修改配置文件

vim  /etc/kubeasz/clusters/k8s-01/config.yml

...
CLUSTER_NAME: "k8s-edge-cluster"
K8S_VER: "1.27.3"
#master节点证书配置
MASTER_CERT_HOSTS:
  - "10.x.5.122"
  - "10.x.1.213"
  - "10.x.35.13"
  - "域名"
...

vim /etc/kubeasz/clusters/k8s-01/hosts 

...
[etcd]
10.x.5.122
10.x.1.213
10.x.35.13

[kube_master]
10.x.5.122 k8s_nodename='master-01'
10.x.1.213 k8s_nodename='master-02'
10.x.35.13 k8s_nodename='master-03'

[kube_node]
10.x.34.249 k8s_nodename='worker-01'
...

分步安装

#建议使用alias命令
#查看~/.bashrc 文件应该包含:alias dk='docker exec -it kubeasz'
source ~/.bashrc

初始化

#dk ezctl setup k8s-01 01
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/01.prepare.yml
...

部署etcd

i.执行安装

#dk ezctl setup k8s-01 02
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/02.etcd.yml
...

ii.集群状态

#export NODE_IPS="10.x.5.122 10.x.1.213 10.x.35.13"
for ip in ${NODE_IPS}; do ETCDCTL_API=3 /opt/kube/bin/etcdctl --endpoints=https://${ip}:2379 --cacert=/etc/kubernetes/ssl/ca.pem --cert=/etc/kubernetes/ssl/etcd.pem --key=/etc/kubernetes/ssl/etcd-key.pem endpoint health; done

#输出内容
...
https://10.x.5.122:2379 is healthy: successfully committed proposal: took = 15.96023ms
https://10.x.1.213:2379 is healthy: successfully committed proposal: took = 16.849881ms
https://10.x.35.13:2379 is healthy: successfully committed proposal: took = 20.668937ms
...

iii.证书有效期

#openssl x509 -in /etc/kubernetes/ssl/etcd.pem -noout -text |egrep 'Not After'
...
            Not After : May  3 09:09:00 2074 GMT
...

部署runtime

#dk ezctl setup k8s-01 03
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/03.runtime.yml
...

部署master节点

#dk ezctl setup k8s-01 04
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/04.kube-master.yml
...

部署node节点

#dk ezctl setup k8s-01 05
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/05.kube-node.yml
...

部署network

#dk ezctl setup k8s-01 06
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/06.network.yml
...

安装其他应用插件

#dk ezctl setup k8s-01 07
...
ansible-playbook -i clusters/k8s-01/hosts -e @clusters/k8s-01/config.yml  playbooks/07.cluster-addon.yml
...

配置kubectl

i. 配置/root/.kube/config

#从部机拷贝该文件 & 修改server配置
/etc/kubeasz/clusters/k8s-01/kubectl.kubeconfig

ii.配置系统PATH

#vim /etc/profile
...
export PATH=/opt/kube/bin/:$PATH
...

iii.测试下

#kubectl cluster-info
Kubernetes control plane is running at https://10.x.1.213:6443

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

参考

kubeasz/docs/setup/00-planning_and_overall_intro.md at master · easzlab/kubeasz · GitHub

https://blog.51cto.com/flyfish225/6324517

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐