2 min read

[k8s系列篇之2] 用kubespray快速部署k8s

前言

前文介绍了如何部署虚拟机节点, 本文主要介绍如何通过kubespray部署k8s环境

步骤

启动虚拟机节点

在操作机上安装必要依赖程序

release页面 下载最新的kubespray源码包并上传解压, cd 过去, 执行以下命令

yum install -y python3

# 更改pip镜像源
pip3 install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U
pip3 config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple 

pip3 install ansible netaddr
pip3 install -r contrib/inventory_builder/requirements.txt

执行以下命令进行安装, 信息酌情修改

# Copy ``inventory/sample`` as ``inventory/mycluster``
cp -rfp inventory/sample inventory/mycluster

# Update Ansible inventory file with inventory builder
declare -a IPS=(10.1.3.51 10.1.3.52 10.1.3.53)
CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}

# Review and change parameters under ``inventory/mycluster/group_vars``
cat inventory/mycluster/group_vars/all/all.yml
cat inventory/mycluster/group_vars/k8s_cluster/k8s-cluster.yml

# Deploy Kubespray with Ansible Playbook - run the playbook as root
# The option `--become` is required, as for example writing SSL keys in /etc/,
# installing packages and interacting with various systemd daemons.
# Without --become the playbook will fail to run!
ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml

都跑完后, 就安装成功了, 耗时大约15分钟, 今天网速还好.

可以ssh远程到节点上去 kubectl get pods -A 查看状态

参考文档