Skip to content

Commit

Permalink
upgrade ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
kubeop committed Aug 27, 2024
1 parent a777e20 commit a42a42a
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 145 deletions.
57 changes: 33 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## 支持的发型版

- CentOS/RHEL 7,8,9
- AlmaLinux 8,9
- RockyLinux 8,9
- Ubuntu Server 20.04,22.04
Expand All @@ -20,7 +19,6 @@
- [cilium](https://github.com/cilium/cilium)
- [flanneld](https://github.com/flannel-io/flannel)
- [kube-router](https://github.com/cloudnativelabs/kube-router)
- [macvlan](https://github.com/containernetworking/plugins)
- Application
- [coredns](https://github.com/coredns/coredns)
- [node-local-dns](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns/nodelocaldns)
Expand All @@ -29,28 +27,38 @@



## 前期配置
## 开始配置

### 安装Ansible
### 配置Ansible控制端

建议根据下表安装合适的Python版本和Ansible版本

| Python | Ansible |
| ------ | --------- |
| >=3.9 | >=2.11.12 |
| 组件 | 版本 |
| -------------------- | -------- |
| AlmaLinux/RockyLinux | >=8 |
| Python | >=3.9 |
| Ansible | >=2.14.0 |



安装Ansible示例
安装Ansible

```shell
pip3 install ansible -i https://mirrors.ustc.edu.cn/pypi/web/simple
pip3 install netaddr -i https://mirrors.ustc.edu.cn/pypi/web/simple
# 安装ansible
yum -y install ansible

# 查看ansible使用的python版本
ansible --version

# 查看netaddr网络模块版本
dnf list | grep netaddr

# 根据前面查询的版本信息,选择跟ansible匹配的python版本的netaddr
dnf -y install python3-netaddr
```

- 请使用对应Python版本的pip安装ansible和netaddr。
- 控制节点和被控节点Python版本尽量保持一致,否则执行可能出现问题。
- 更详细的版本支持矩阵,请参考:https://docs.ansible.com/ansible-core/devel/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
- 不同Python版本Anisble支持矩阵详情,请参考:https://docs.ansible.com/ansible-core/devel/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix



Expand All @@ -71,10 +79,10 @@ pip3 install netaddr -i https://mirrors.ustc.edu.cn/pypi/web/simple
- **Kubernetes** 的最低版本要求为 v1.26

- 请尽量将etcd安装在独立的服务器上,不建议跟master安装在一起。数据盘尽量使用SSD盘。
- Pod 和Service IP网段建议使用保留私有IP段,建议(Pod IP不与Service IP重复,也不要与主机IP段重复,同时也避免与docker0网卡的网段冲突。)
- Pod 和Service IP网段建议使用保留私有IP段,建议(Pod IP不与Service IP重复,也不要与主机IP段重复,同时也避免与docker0网卡的网段冲突)从以下网段及子网选择
- Pod 网段
- A类地址:10.0.0.0/8
- B类地址:172.16-31.0.0/12-16
- B类地址:172.16.0.0/12
- C类地址:192.168.0.0/16
- Service网段
- A类地址:10.0.0.0/16-24
Expand All @@ -93,37 +101,39 @@ pip3 install netaddr -i https://mirrors.ustc.edu.cn/pypi/web/simple
ansible-playbook fdisk.yml -i inventory -e "disk=sdb dir=/data"
```

- 可选变量`-e "disk=sdb dir=/data num=1"`

如果是NVME的磁盘,请使用以下方式:

```shell
ansible-playbook fdisk.yml -i inventory -e "disk=sdb dir=/data type=nvme"
ansible-playbook fdisk.yml -i inventory -e "disk=nvme0n1 dir=/data num=p1"
```

⚠️:

- 此脚本会格式化{{disk}}指定的硬盘,并挂载到{{dir}}目录。
- 会将`/var/lib/etcd``/var/lib/containerd``/var/lib/kubelet``/var/log/pods`数据目录绑定到此数据盘`{{dir}}/containers/etcd``{{dir}}/containers/containerd``{{dir}}/containers/kubelet``{{dir}}/containers/pods`目录,以达到多个数据目录共用一个数据盘,而无需修改kubernetes相关数据目录。
- 同时会将`/var/lib/etcd``/var/lib/containerd``/var/lib/kubelet``/var/log/pods`数据目录绑定到此数据盘`{{dir}}/containers/etcd``{{dir}}/containers/containerd``{{dir}}/containers/kubelet``{{dir}}/containers/pods`目录,以达到多个数据目录共用一个数据盘,而无需修改kubernetes相关数据目录。



如需不同目录挂载不同数据盘,可以使用以下命令单独挂载

```shell
ansible-playbook fdisk.yml -i inventory -l master -e "disk=sdb dir=/var/lib/etcd" --skip-tags=bind_dir
ansible-playbook fdisk.yml -i inventory -l etcd -e "disk=sdb dir=/var/lib/etcd" --skip-tags=bind_dir
```

如已经格式化并挂载过数据盘,可以使用以下命令将数据目录绑定到数据盘

```shell
ansible-playbook fdisk.yml -i inventory -l master -e "disk=sdb dir=/data" -t bind_dir
ansible-playbook fdisk.yml -i inventory -l master,worker -e "disk=sdb dir=/data" -t bind_dir
```



### 下载离线包

```shell
# 如从自建文件服务器下载,请修改roles/download/defaults/main.yml文件中的默认下载地址
# 如从自建文件服务器下载,请修改group_vars/all.yml文件中的默认下载地址
ansible-playbook download.yml
```

Expand All @@ -135,9 +145,8 @@ ansible-playbook download.yml
### 同步镜像

```shell
# 如集群节点可以连接公网,可以跳过此步骤。
# 如不能连接公网或需使用私有镜像仓库,请自行同步group_vars/all.yml中定义的镜像至私有镜像仓库。
# 也可以使用 https://github.com/AliyunContainerService/image-syncer/releases 同步
# 建议将group_vars/all.yml中定义的镜像自行同步至私有镜像仓库中,官网或代理可能不稳定或失效。
# 建议使用 https://github.com/AliyunContainerService/image-syncer/releases 同步
```


Expand Down Expand Up @@ -206,7 +215,7 @@ yum -y install nvidia-container-runtime nvidia-container-toolkit

```shell
# 执行之前,请确认已经进行过磁盘分区
# 执行之前,请确认已经执行`ansible-playbook download.yml`完成安装包下载
# 执行之前,请确认已经执行ansible-playbook download.yml完成安装包下载
ansible-playbook cluster.yml -i inventory
```

Expand Down Expand Up @@ -311,7 +320,7 @@ etcdctl endpoint health \
--cacert=/etc/etcd/pki/etcd-ca.pem \
--cert=/etc/etcd/pki/etcd-healthcheck-client.pem \
--key=/etc/etcd/pki/etcd-healthcheck-client.key \
--endpoints=https://172.16.90.101:2379,https://172.16.90.102:2379,https://172.16.90.103:2379
--endpoints=https://10.43.75.201:2379,https://10.43.75.202:2379,https://10.43.75.203:2379
```

逐个删除旧的kubelet证书
Expand Down
6 changes: 3 additions & 3 deletions ansible_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
hosts: localhost
gather_facts: false
become: no
run_once: true
vars:
minimal_ansible_version: 2.11.12
minimal_ansible_version: 2.14.0
maximal_ansible_version: 2.17.0
ansible_connection: local
tags: always
tasks:
- name: "Check {{ minimal_ansible_version }} <= Ansible version < {{ maximal_ansible_version }}"
Expand All @@ -21,7 +21,7 @@
- name: "Check that python netaddr is installed"
assert:
msg: "Python netaddr is not present"
that: "'127.0.0.1' | ipaddr"
that: "'127.0.0.1' | ansible.utils.ipaddr"
tags:
- check

Expand Down
2 changes: 1 addition & 1 deletion cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: "Check ansible version"
import_playbook: ansible_version.yml

- name: "Verify Settings"
- name: "Check Configs"
hosts: haproxy etcd master worker
roles:
- role: verify
Expand Down
2 changes: 1 addition & 1 deletion download.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: "Download Offline Package"
hosts: localhost
connection: local
run_once: true
roles:
- role: download
tags: download
12 changes: 4 additions & 8 deletions fdisk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
- name: "格式化挂载磁盘"
hosts: all
vars:
type: disk
disk: sdb
dir: /data
num: 1
tasks:
- name: set disk variable
when: type == "disk"
- name: set partation variable
set_fact:
partation: "{{ disk }}1"
- name: set nvme variable
when: type == "nvme"
set_fact:
partation: "{{ disk }}p1"
partation: "{{ disk }}{{ num }}"
- stat:
path: "/dev/{{ partation }}"
register: disk_stat
Expand Down Expand Up @@ -62,6 +57,7 @@
opts: defaults,noatime,nodiratime,pquota
state: mounted
tags: fdisk

- name: "创建etcd目录"
file:
path: "{{ item.line }}"
Expand Down
73 changes: 48 additions & 25 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Download offline package
download:
# 离线包保存目录,节点安装包从该目录拷贝
dest: /data/web/mirrors/k8s/
dest: /data/mirrors/k8s/
# 下载超时时间
timeout: 60
# 重试次数
Expand Down Expand Up @@ -36,8 +36,11 @@ cert:

# https://github.com/etcd-io/etcd
etcd:
# etcd 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为:{{etcd.download_url}}/{{etcd.version}}/etcd-{{etcd.version}}-linux-amd64.tar.gz
download_url: https://mirror.ghproxy.com/https://github.com/etcd-io/etcd/releases/download
# etcd 版本
version: v3.5.13
version: v3.5.15
# etcd 数据目录,如使用多个目录映射同一块数据盘的方式,请勿修改默认目录
data_dir: "/var/lib/etcd"

Expand All @@ -48,18 +51,23 @@ etcd:
# 如使用域名,需提前配置解析。不使用域名时,请注释掉
# 如使用haproxy + keepalived ,并且跟master节点部署在一起时,请修改port以避免端口冲突
loadbalance:
ip: 172.16.90.100
ip: 10.43.75.200
port: 6443
# domain_name: apiserver.kubeop.com
# access_ip:
# - 172.16.90.100
# - 10.43.75.200

# https://github.com/kubernetes/kubernetes
kubernetes:
# kubernetes 二进制安装包下载地址,默认为阿里云从Google同步过来的镜像,更新较慢,最新版本可能未同步过来。
# 官方下载源,下载较慢。 https://storage.googleapis.com/kubernetes-release/release
# 阿里云下载源,可能更新不及时,无法下载最新版本。https://kubernetes.oss-cn-hangzhou.aliyuncs.com/kubernetes-release/release
# 如使用自建文件服务器,请保证下载路径为:{{kubernetes.download_url}}/{{kubernetes.version}}/bin/linux/amd64/kube-apiserver。
download_url: https://storage.googleapis.com/kubernetes-release/release
# kubernetes 版本
version: v1.30.1
version: v1.30.4
# 集群Pod网段
pods_subnet: 10.64.0.0/12
pods_subnet: 172.16.0.0/12
# 集群Service网段
service_addresses: 192.168.0.0/16
# 节点Pod网段掩码大小
Expand All @@ -77,23 +85,35 @@ kubernetes:

# https://github.com/opencontainers/runc
runc:
# runc 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为:{{runc.download_url}}/{{runc.version}}/runc.amd64
download_url: https://mirror.ghproxy.com/https://github.com/opencontainers/runc/releases/download
# runc 版本
version: v1.1.12
version: v1.1.13

# https://github.com/containernetworking/plugins
cniplugins:
# cni-plugins 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为:{{cniplugins.download_url}}/{{cniplugins.version}}/cni-plugins-linux-amd64-{{cniplugins.version}}.tgz
download_url: https://mirror.ghproxy.com/https://github.com/containernetworking/plugins/releases/download
# cni-plugins 版本
version: v1.4.1
version: v1.5.1

# https://github.com/kubernetes-sigs/cri-tools
critools:
# cri-tools 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为:{{critools.download_url}}/{{critools.version}}/crictl-{{critools.version}}-linux-amd64.tar.gz
download_url: https://mirror.ghproxy.com/https://github.com/kubernetes-sigs/cri-tools/releases/download
# cri-tools 版本
version: v1.30.0
version: v1.31.1

# https://github.com/containerd/containerd
containerd:
# containerd 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为:{{containerd.download_url}}/v{{containerd.version}}/containerd-{{containerd.version}}-linux-amd64.tar.gz
download_url: https://mirror.ghproxy.com/https://github.com/containerd/containerd/releases/download
# containerd 版本,建议使用1.6.x版本(1.6.x当前为长期稳定版本)
version: 1.6.33
version: 1.6.35
# containerd 持久化数据目录,如使用多个目录映射同一块数据盘的方式,请勿修改默认目录
root: "/var/lib/containerd"
# containerd 临时数据目录
Expand Down Expand Up @@ -125,20 +145,20 @@ network_plugin: calico
# cilium need linux kernel >= 4.9.17
cilium:
# https://github.com/cilium/cilium
version: v1.15.4
version: v1.16.1
# {{cilium.registry}}/operator-generic:{{cilium.version}}
# {{cilium.registry}}/cilium:{{cilium.version}}
registry: m.daocloud.io/docker.io/cilium
registry: docker.mrxn.net/cilium
# "disabled" or "vxlan" or "geneve"
network_mode: vxlan

flannel:
# https://github.com/flannel-io/flannel
version: v0.25.1
plugin_version: v1.4.1-flannel1
version: v0.25.5
plugin_version: v1.5.1-flannel1
# {{flannel.registry}}/flannel-cni-plugin:{{flannel.plugin_version}}
# {{flannel.registry}}/flannel:{{flannel.version}}
registry: m.daocloud.io/docker.io/flannel
registry: docker.mrxn.net/flannel
# "vxlan" or "host-gw"
network_mode: vxlan
# 运行参数
Expand All @@ -151,12 +171,15 @@ flannel:
# mtu: 1500

calico:
# calicoctl 安装包下载地址
# 如使用自建文件服务器,请保证下载路径为: {{calico.download_url}}/calico/{{ calico.version }}/calicoctl-linux-amd64
download_url: https://mirror.ghproxy.com/https://github.com/projectcalico/calico/releases/download
# https://github.com/projectcalico/calico
version: v3.27.3
version: v3.28.1
# {{calico.registry}}/kube-controllers:{{calico.version}}
# {{calico.registry}}/node:{{calico.version}}
# {{calico.registry}}/cni:{{calico.version}}
registry: m.daocloud.io/docker.io/calico
registry: docker.mrxn.net/calico
# "ipip" or "bgp" or "mix"
network_mode: ipip
# mtu 默认为0,表示自动自动检测
Expand All @@ -168,7 +191,7 @@ kuberouter:
# https://github.com/cloudnativelabs/kube-router
version: v1.6.1
# {{kube-router.registry}}/kube-router
registry: m.daocloud.io/docker.io/cloudnativelabs
registry: docker.mrxn.net/cloudnativelabs
# Setups node CNI to allow hairpin mode, requires node reboots, see
# https://github.com/cloudnativelabs/kube-router/blob/master/docs/user-guide.md#hairpin-mode
# 即让Pod可以通过Service访问自己
Expand All @@ -184,25 +207,25 @@ kuberouter:
coredns:
version: 1.11.1
# {{coredns.registry}}/coredns:{{coredns.version}}
registry: m.daocloud.io/docker.io/coredns
registry: docker.mrxn.net/coredns
nodelocaldns:
enabled: true
version: 1.23.0
version: 1.23.1
# {{nodelocaldns.registry}}/k8s-dns-node-cache:{{nodelocaldns.version}}
registry: m.daocloud.io/registry.k8s.io/dns
registry: k8s.mrxn.net/dns
ip: 169.254.20.10
metrics_server:
enabled: true
version: v0.7.1
# {{metrics_server.registry}}/metrics-server:{{metrics_server.version}}
registry: m.daocloud.io/registry.k8s.io/metrics-server
registry: k8s.mrxn.net/metrics-server
npd:
enabled: false
version: v0.8.18
version: v0.8.19
# {{npd.registry}}/node-problem-detector:{{npd.version}}
registry: m.daocloud.io/registry.k8s.io/node-problem-detector
registry: k8s.mrxn.net/node-problem-detector
nvidia_device_plugin:
enabled: false
version: v0.15.0
version: v0.16.2
# {{nvidia_device_plugin.registry}}/k8s-device-plugin:{{nvidia_device_plugin.version}}
registry: nvcr.io/nvidia
Loading

0 comments on commit a42a42a

Please sign in to comment.