From 2c8d59abcdf056bd87e0af6cefd6f680044a04f8 Mon Sep 17 00:00:00 2001 From: jmgao Date: Thu, 14 Dec 2017 23:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CentOS=207=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01.prepare.yml | 1 + 04.docker.yml | 1 + README.md | 2 +- docs/quickStart.md | 2 +- docs/quickStartCentOS7.md | 70 ++++++++++++++++++++++++++++++++++++ roles/docker/tasks/main.yml | 8 +++-- roles/lb/tasks/main.yml | 17 +++++++-- roles/prepare/tasks/main.yml | 2 +- 8 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 docs/quickStartCentOS7.md diff --git a/01.prepare.yml b/01.prepare.yml index 321dd29..efc01e4 100644 --- a/01.prepare.yml +++ b/01.prepare.yml @@ -13,5 +13,6 @@ # [可选]多master部署时的负载均衡配置 - hosts: lb + gather_facts: True roles: - lb diff --git a/04.docker.yml b/04.docker.yml index 7d5b2ed..740e340 100644 --- a/04.docker.yml +++ b/04.docker.yml @@ -1,3 +1,4 @@ - hosts: kube-cluster + gather_facts: True roles: - docker diff --git a/README.md b/README.md index a8648cb..d66e2df 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ **二进制方式部署优势:有助于理解系统各组件的交互原理和熟悉组件启动参数,有助于快速排查解决实际问题** -文档基于`Ubuntu 16.04`,其他系统如`CentOS 7`需要读者自行替换部分命令;由于使用经验有限和简化脚本考虑,已经尽量避免`ansible-playbook`的高级特性和复杂逻辑。 +文档基于`Ubuntu 16.04/CentOS 7`,其他系统需要读者自行替换部分命令;由于使用经验有限和简化脚本考虑,已经尽量避免`ansible-playbook`的高级特性和复杂逻辑。 你可能需要掌握基本`kubernetes` `docker` `linux shell` 知识,关于`ansible`建议阅读 [ansible超快入门](http://weiweidefeng.blog.51cto.com/1957995/1895261) 基本够用。 diff --git a/docs/quickStart.md b/docs/quickStart.md index 66b0e91..e25d4fd 100644 --- a/docs/quickStart.md +++ b/docs/quickStart.md @@ -1,6 +1,6 @@ ## 快速指南 -以下为快速体验k8s集群的测试、开发环境--AllinOne部署,觉得比官方的minikube方便、简单很多。 +以下为基于Ubuntu16.04 快速体验k8s集群的测试、开发环境--AllinOne部署,觉得比官方的minikube方便、简单很多。CentOS7 指南请点[这里](quickStartCentOS7.md) ### 1.准备一台虚机(推荐内存3G,硬盘20G以上),最小化安装Ubuntu16.04 server,配置基础网络、更新源、SSH登陆等。 ### 2.安装python2/git/python-pip/ansible diff --git a/docs/quickStartCentOS7.md b/docs/quickStartCentOS7.md new file mode 100644 index 0000000..b649eea --- /dev/null +++ b/docs/quickStartCentOS7.md @@ -0,0 +1,70 @@ +## 快速指南 + +### 1.准备一台虚机(推荐内存3G,硬盘20G以上),最小化安装最新 CentOS7,配置基础网络、更新源、SSH登陆等。 + ++ 关闭selinux: `echo SELINUX=disabled > /etc/selinux/config` + +### 2.安装python2/git/python-pip/ansible +``` bash +# 文档中脚本默认均以root用户执行 +# 安装 epel 源并更新 +yum install epel-release -y +yum update +# 删除不要的默认安装 +yum erase firewalld firewalld-filesystem python-firewall -y +# 安装依赖工具 +yum install git python python-pip -y +# 安装ansible (国内如果安装太慢可以直接用pip阿里云加速) +#pip install pip --upgrade +#pip install ansible +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 回车 回车 回车 +ssh-copy-id $IP #$IP为本虚机地址,按照提示输入yes 和root密码 +``` +### 3.安装kubernetes集群 +``` bash +git clone https://github.com/gjmzj/kubeasz.git +mv kubeasz /etc/ansible +# 下载已打包好的binaries,并且解压缩到/etc/ansible/bin目录 +# 国内请从我分享的百度云链接下载 https://pan.baidu.com/s/1eSetFSA +# 如果你有合适网络环境也可以按照/down/download.sh自行从官网下载各种tar包到 ./down目录,并执行download.sh +tar zxvf k8s.184.tar.gz +mv bin/* /etc/ansible/bin +# 配置ansible的hosts文件 +cd /etc/ansible +cp example/hosts.allinone.example hosts +然后根据实际情况修改此hosts文件,所有节点都是本虚机IP +# 采用一步安装或者分步安装 +ansible-playbook 90.setup.yml # 一步安装 +#ansible-playbook 01.prepare.yml +#ansible-playbook 02.etcd.yml +#ansible-playbook 03.kubectl.yml +#ansible-playbook 04.docker.yml +#ansible-playbook 05.calico.yml +#ansible-playbook 06.kube-master.yml +#ansible-playbook 07.kube-node.yml +``` +如果执行成功,k8s集群就安装好了。 + +### 4.验证安装 +``` bash +# 如果提示kubectl: command not found,退出重新ssh登陆一下,环境变量生效即可 +kubectl version +kubectl get componentstatus # 可以看到scheduler/controller-manager/etcd等组件 Healthy +kubectl cluster-info # 可以看到kubernetes master(apiserver)组件 running +kubectl get node # 可以看到单 node Ready状态 +kubectl get pod --all-namespaces # 可以查看所有集群pod状态 +kubectl get svc --all-namespaces # 可以查看所有集群服务状态 +calicoctl node status # 可以在master或者node节点上查看calico网络状态 +``` +### 5.安装主要组件 +``` bash +# 安装kubedns +kubectl create -f manifests/kubedns +# 安装heapster +kubectl create -f manifests/heapster +# 安装dashboard +kubectl create -f manifests/dashboard +``` diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 355b98b..74ffbaf 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -30,12 +30,14 @@ shell: systemctl daemon-reload && systemctl enable docker && systemctl restart docker ## 可选 ------安装docker查询镜像 tag的小工具---- -- name: apt更新缓存刷新 - apt: update_cache=yes cache_valid_time=72000 +- name: 安装轻量JSON处理程序 + apt: name=jq state=latest + when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version = "16" tags: docker-tag - name: 安装轻量JSON处理程序 - apt: name=jq state=latest + yum: name=jq state=latest + when: ansible_distribution == "CentOS" and ansible_distribution_major_version = "7" tags: docker-tag - name: 下载 docker-tag diff --git a/roles/lb/tasks/main.yml b/roles/lb/tasks/main.yml index 2717589..2c531e6 100644 --- a/roles/lb/tasks/main.yml +++ b/roles/lb/tasks/main.yml @@ -1,9 +1,15 @@ - +# - name: apt更新缓存刷新 apt: update_cache=yes cache_valid_time=72000 + when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version = "16" -- name: 安装 haproxy +- name: 安装 haproxy using apt apt: name=haproxy state=latest + when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version = "16" + +- name: 安装 haproxy using yum + yum: name=haproxy state=latest + when: ansible_distribution == "CentOS" and ansible_distribution_major_version = "7" - name: 创建haproxy配置目录 file: name=/etc/haproxy state=directory @@ -11,8 +17,13 @@ - name: 配置 haproxy template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg -- name: 安装 keepalived +- name: 安装 keepalived using apt apt: name=keepalived state=latest + when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version = "16" + +- name: 安装 keepalived using yum + yum: name=keepalived state=latest + when: ansible_distribution == "CentOS" and ansible_distribution_major_version = "7" - name: 创建keepalived配置目录 file: name=/etc/keepalived state=directory diff --git a/roles/prepare/tasks/main.yml b/roles/prepare/tasks/main.yml index ef16f88..2b0b1b4 100644 --- a/roles/prepare/tasks/main.yml +++ b/roles/prepare/tasks/main.yml @@ -10,7 +10,7 @@ # copy: src=hosts.j2 dest=/etc/hosts - name: 写入环境变量$PATH - shell: "sed -i '/export PATH/d' /etc/profile && \ + shell: "sed -i '/export PATH=/d' /etc/profile && \ echo export PATH={{ bin_dir }}:$PATH >> /etc/profile" - name: 下载证书工具 CFSSL