使用ansible一键安装 k8s

Posted 明镜清玄子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用ansible一键安装 k8s相关的知识,希望对你有一定的参考价值。

使用ansible一键安装 k8s

环境需求:

centos7系统

ansible已安装

项目功能

1.准备工作

* ntp * chrony * disable selinux * set firewalld * set swap * set kernel

2.安装yum源

* install httpd * unzip rpm package

3.安装docker

* set config * install docker

4.安装docker镜像仓库

* unzip package * run registry service

5.安装k8s

* Install kubeadm/kubelet/kubectl * master init * add node * appply ingress * appply dashboard

6.安装ceph

* install ceph

安装步骤

1.导入所需要的包

Baidu cloud address:

leave a message in issue

把所有下载的包放入如下目录: \\ {{ projectname }}/artifacts/

containerd-selinux-v2.119.2.tar \\

docker-ce-stable-v20.10.7.tar \\

kubernetes-v1.21.2.tar \\

registry-1.21.2.tar.gz

百度网盘: 链接:https://pan.baidu.com/s/1XF-W3R-E6pWK2st-k1r3Qg 提取码:jsth

2.编写 hosts.ini

lombok.config
[all:vars]
ansible_connection=ssh
ansible_user=zhangsan
ansible_password=9876557
# same as `ansible_ssh_pass`
ansible_become_pass=9876557
[kubernetes:children]
kubernetes_master
kubernetes_master_slaves
kubernetes_slaves
[kubernetes_master_all:children]
kubernetes_master
kubernetes_master_slaves
[kubernetes_master]
172.16.<strong>.</strong>*
[kubernetes_master_slaves]
[kubernetes_slaves]
172.16.<strong>.</strong>*
172.16.<strong>.</strong>*
[docker:children]
kubernetes
registry
[registry]
172.16.<strong>.</strong>*
[repo]
172.16.<strong>.</strong>

3.编写 shared.yml


#---------------------------------
## Docker image repo
##---------------------------------
docker_repo_ip: "172.20.<strong>.</strong>*"
docker_repo_address: "*<strong>k8s-registry-address</strong>*:<strong>port</strong>"
docker_repo_domain_name: "*<strong>k8s-registry-address</strong>*"
master_ip: "172.20.<strong>.</strong>*"
kubernetes_api: "apiserver.***<strong>.local"
#---------------------------------
### package repo
###---------------------------------
#
repo: "172.20.</strong>.***

4.检查各个role目录下的参数配置是否正确 defult/main.yml file


check eack roles defult/main.yml file ,set paramete

5. 安装

{{projectname}} is project name ,is k8s-ansible/


cd {{projectname}}
执行如下指令:
ansible-playbook ./playbooks/01_prepare.yml
ansible-playbook ./playbooks/02_yum_repo.yml
ansible-playbook ./playbooks/03_docker_install.yml
ansible-playbook ./playbooks/04_install_docker_register.yml
ansible-playbook ./playbooks/05_install_k8s.yml
ansible-playbook ./playbooks/06_install_ceph.ym

f you want to test whether the configuration file is correct first, as in the above steps, add -C after the instruction, for example:


ansible-playbook ./playbooks/01_prepare.yml -

6. 问题:

1.When the running is interrupted, you want to repeat it.

2.ceph安装用简单的块设备就可以识别

版本列表

kubeadm v1.21.2 \\ cni:v3.20.2 \\ pod2daemon-flexvol:v3.20.2 \\ node:v3.20.2 \\ kube-controllers:v3.20.2 \\ ingress-nginx-controller:0.30.0 \\ metrics-scraper:v1.0.6 \\ dashboard:v2.2.0 \\ metrics-server:0.4.4 \\ \\ coredns:1.8.0 \\ etcd:3.4.13-0 \\ pause:3.4.1 \\ kube-proxy:v1.21.2 \\ kube-scheduler:v1.21.2 \\ kube-controller-manager:v1.21.2 \\ kube-apiserver:v1.21.2 \\ \\ \\ ceph:v1.6.7 \\ cephcsi:v3.3.1 \\ csi-node-driver-registrar:v2.2.0 \\ csi-resizer:v1.2.0 \\ csi-provisioner:v2.2.2 \\ csi-snapshotter:v4.1.1 \\ csi-attacher:v3.2.1 \\ ceph:v15.2.13

以上是关于使用ansible一键安装 k8s的主要内容,如果未能解决你的问题,请参考以下文章

Ansible搭建K8S说明

ansible 一键安装mysql

ansible一键安装GreatSQL并构建MGR集群

ansible调用一键安装lnmp包实现一键安装

ansible一键安装mysql8.0

ansible批量一键安装lnmp环境