2017-11-26 18:46:02 +08:00
|
|
|
|
## 快速指南
|
|
|
|
|
|
2018-03-17 17:00:42 +08:00
|
|
|
|
以下为快速体验k8s集群的测试、开发环境--allinone部署,国内环境下觉得比官方的minikube方便、简单很多。
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
### 1.基础系统配置
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
+ 推荐内存2G/硬盘30G以上
|
2017-12-18 22:56:59 +08:00
|
|
|
|
+ 最小化安装`Ubuntu 16.04 server`或者`CentOS 7 Minimal`
|
|
|
|
|
+ 配置基础网络、更新源、SSH登陆等
|
|
|
|
|
|
|
|
|
|
### 2.安装依赖工具
|
|
|
|
|
|
|
|
|
|
Ubuntu 16.04 请执行以下脚本:
|
2017-11-26 18:46:02 +08:00
|
|
|
|
|
|
|
|
|
``` bash
|
2017-11-28 21:13:21 +08:00
|
|
|
|
# 文档中脚本默认均以root用户执行
|
2017-11-26 18:46:02 +08:00
|
|
|
|
# 安装依赖工具
|
|
|
|
|
apt-get install python2.7 git python-pip
|
2017-11-28 21:13:21 +08:00
|
|
|
|
# Ubuntu16.04可能需要配置以下软连接
|
|
|
|
|
ln -s /usr/bin/python2.7 /usr/bin/python
|
2017-12-18 22:56:59 +08:00
|
|
|
|
```
|
|
|
|
|
CentOS 7 请执行以下脚本:
|
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
# 文档中脚本默认均以root用户执行
|
2018-06-29 18:14:59 +08:00
|
|
|
|
# 安装 epel 源
|
2017-12-18 22:56:59 +08:00
|
|
|
|
yum install epel-release -y
|
|
|
|
|
# 安装依赖工具
|
|
|
|
|
yum install git python python-pip -y
|
|
|
|
|
```
|
|
|
|
|
### 3.ansible安装及准备
|
|
|
|
|
|
|
|
|
|
``` bash
|
2017-11-28 21:13:21 +08:00
|
|
|
|
# 安装ansible (国内如果安装太慢可以直接用pip阿里云加速)
|
|
|
|
|
#pip install pip --upgrade
|
|
|
|
|
#pip install ansible
|
2017-11-26 18:46:02 +08:00
|
|
|
|
pip install pip --upgrade -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
|
pip install --no-cache-dir ansible -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
|
|
|
|
|
# 配置ansible ssh密钥登陆
|
|
|
|
|
ssh-keygen -t rsa -b 2048 回车 回车 回车
|
2017-11-28 21:13:21 +08:00
|
|
|
|
ssh-copy-id $IP #$IP为本虚机地址,按照提示输入yes 和root密码
|
2017-11-26 18:46:02 +08:00
|
|
|
|
```
|
2018-05-25 16:08:48 +08:00
|
|
|
|
|
2018-05-25 16:23:37 +08:00
|
|
|
|
在`Ubuntu 16.04`中,如果出现以下错误:
|
2018-05-25 16:08:48 +08:00
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
|
File "/usr/bin/pip", line 9, in <module>
|
|
|
|
|
from pip import main
|
|
|
|
|
ImportError: cannot import name main
|
|
|
|
|
```
|
2018-06-14 00:20:16 +08:00
|
|
|
|
将`/usr/bin/pip`做以下修改:
|
2018-05-25 16:08:48 +08:00
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
#原代码
|
|
|
|
|
from pip import main
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
#修改后
|
|
|
|
|
from pip import __main__
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
sys.exit(__main__._main())
|
|
|
|
|
```
|
|
|
|
|
|
2017-12-18 22:56:59 +08:00
|
|
|
|
### 4.安装kubernetes集群
|
2018-06-29 18:14:59 +08:00
|
|
|
|
|
2018-06-29 18:59:26 +08:00
|
|
|
|
- 4.1 下载项目源码
|
|
|
|
|
|
2017-11-26 18:46:02 +08:00
|
|
|
|
``` bash
|
2018-06-29 18:14:59 +08:00
|
|
|
|
# 方式一:使用git clone
|
2017-11-28 21:13:21 +08:00
|
|
|
|
git clone https://github.com/gjmzj/kubeasz.git
|
2018-03-20 15:52:13 +08:00
|
|
|
|
mkdir -p /etc/ansible
|
|
|
|
|
mv kubeasz/* /etc/ansible
|
2018-06-29 18:14:59 +08:00
|
|
|
|
# 方式二:从发布页面 https://github.com/gjmzj/kubeasz/releases 下载源码解压到同样目录
|
|
|
|
|
```
|
|
|
|
|
- 4.2a 下载二进制文件
|
2018-06-29 18:59:26 +08:00
|
|
|
|
请从分享的[百度云链接](https://pan.baidu.com/s/1c4RFaA),下载解压到/etc/ansible/bin目录,如果你有合适网络环境也可以按照/down/download.sh自行从官网下载各种tar包
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
``` bash
|
|
|
|
|
tar zxvf k8s.1-9-8.tar.gz # 以安装k8s v1.9.8为例
|
2017-11-28 21:13:21 +08:00
|
|
|
|
mv bin/* /etc/ansible/bin
|
2018-06-29 18:14:59 +08:00
|
|
|
|
```
|
|
|
|
|
- 4.2b [可选]下载离线docker镜像
|
2018-06-29 18:59:26 +08:00
|
|
|
|
服务器使用内部yum源/apt源,但是无法访问公网情况下,请下载离线docker镜像完成集群安装;从百度云盘把`basic_images_kubeasz_x.y.tar.gz` 下载解压到`/etc/ansible/down` 目录
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
``` bash
|
|
|
|
|
tar zxvf basic_images_kubeasz_0.2.tar.gz -C /etc/ansible/down
|
|
|
|
|
```
|
2018-06-29 18:59:26 +08:00
|
|
|
|
- 4.3 配置集群参数
|
2018-08-10 15:58:08 +08:00
|
|
|
|
- 4.3.1 必要配置:`cd /etc/ansible && cp example/hosts.allinone.example hosts`, 然后实际情况修改此hosts文件
|
|
|
|
|
- 4.3.2 可选配置,初次使用可以不做修改,详见[配置指南](config_guide.md)
|
|
|
|
|
- 4.3.3 验证ansible 安装:`ansible all -m ping` 正常能看到节点返回 SUCCESS
|
2018-06-29 18:59:26 +08:00
|
|
|
|
|
|
|
|
|
- 4.4 开始安装
|
|
|
|
|
如果你对集群安装流程不熟悉,请阅读项目首页 **安装步骤** 讲解后分步安装,并对 **每步都进行验证**
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
``` bash
|
2018-03-17 17:00:42 +08:00
|
|
|
|
# 分步安装
|
|
|
|
|
ansible-playbook 01.prepare.yml
|
|
|
|
|
ansible-playbook 02.etcd.yml
|
|
|
|
|
ansible-playbook 03.docker.yml
|
|
|
|
|
ansible-playbook 04.kube-master.yml
|
|
|
|
|
ansible-playbook 05.kube-node.yml
|
|
|
|
|
ansible-playbook 06.network.yml
|
2018-06-19 21:45:17 +08:00
|
|
|
|
ansible-playbook 07.cluster-addon.yml
|
2018-03-17 17:00:42 +08:00
|
|
|
|
# 一步安装
|
|
|
|
|
#ansible-playbook 90.setup.yml
|
2017-11-26 18:46:02 +08:00
|
|
|
|
```
|
|
|
|
|
|
2018-06-29 18:14:59 +08:00
|
|
|
|
+ [可选]对集群节点进行操作系统层面的安全加固 `ansible-playbook roles/os-harden/os-harden.yml`,详情请参考[os-harden项目](https://github.com/dev-sec/ansible-os-hardening)
|
2018-05-29 11:32:53 +08:00
|
|
|
|
|
2017-12-18 22:56:59 +08:00
|
|
|
|
### 5.验证安装
|
2018-06-29 18:59:26 +08:00
|
|
|
|
如果提示kubectl: command not found,退出重新ssh登陆一下,环境变量生效即可
|
|
|
|
|
|
2017-11-26 18:46:02 +08:00
|
|
|
|
``` bash
|
|
|
|
|
kubectl version
|
|
|
|
|
kubectl get componentstatus # 可以看到scheduler/controller-manager/etcd等组件 Healthy
|
2017-12-02 22:30:34 +08:00
|
|
|
|
kubectl cluster-info # 可以看到kubernetes master(apiserver)组件 running
|
2017-11-26 18:46:02 +08:00
|
|
|
|
kubectl get node # 可以看到单 node Ready状态
|
2018-06-19 21:45:17 +08:00
|
|
|
|
kubectl get pod --all-namespaces # 可以查看所有集群pod状态,默认已安装网络插件、coredns、metrics-server等
|
2017-11-26 18:46:02 +08:00
|
|
|
|
kubectl get svc --all-namespaces # 可以查看所有集群服务状态
|
|
|
|
|
```
|
2017-12-18 22:56:59 +08:00
|
|
|
|
### 6.安装主要组件
|
2018-06-29 18:59:26 +08:00
|
|
|
|
|
2017-11-28 21:13:21 +08:00
|
|
|
|
``` bash
|
2018-06-19 21:45:17 +08:00
|
|
|
|
# 安装kubedns,默认已集成安装
|
|
|
|
|
#kubectl create -f /etc/ansible/manifests/kubedns
|
|
|
|
|
# 安装dashboard,默认已集成安装
|
|
|
|
|
#kubectl create -f /etc/ansible/manifests/dashboard
|
2017-11-28 21:13:21 +08:00
|
|
|
|
```
|
2018-03-17 17:00:42 +08:00
|
|
|
|
+ 登陆 `dashboard`可以查看和管理集群,更多内容请查阅[dashboard文档](guide/dashboard.md)
|
2017-12-18 22:56:59 +08:00
|
|
|
|
|
|
|
|
|
### 7.清理集群
|
|
|
|
|
|
|
|
|
|
以上步骤创建的K8S开发测试环境请尽情折腾,碰到错误尽量通过查看日志、上网搜索、提交`issues`等方式解决;当然如果是彻底奔溃了,可以清理集群后重新创建。
|
|
|
|
|
|
2018-06-29 18:59:26 +08:00
|
|
|
|
``` bash
|
|
|
|
|
ansible-playbook 99.clean.yml
|
|
|
|
|
```
|
|
|
|
|
|
2018-10-13 21:41:09 +08:00
|
|
|
|
如果出现清理失败,类似报错:`... Device or resource busy: '/var/run/docker/netns/xxxxxxxxxx'`,需要手动umount该目录后清理
|
2018-06-29 18:59:26 +08:00
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
$ umount /var/run/docker/netns/xxxxxxxxxx
|
2018-10-13 21:41:09 +08:00
|
|
|
|
$ rm -rf /var/run/docker/netns/xxxxxxxxxx
|
2018-06-29 18:59:26 +08:00
|
|
|
|
```
|