One . Installation requirements
1、 Prepare the environment
# System centos7
# Hardware :1 individual CPU,2G Memory
# Access to the Internet , Ban swap
# Install in advance docker Environmental Science
2、 Prepare three linux The server ( Use here centos7 virtual machine )
3、 Initialize the system environment , The following commands are executed on all three servers
3.1、 Turn off firewall
# systemctl stop firewalld
# systemctl disable firewalld
3.2、 close selinux and swap
# sed -i 's/enforcing/disabled' /etc/selinux/config
# setenforce 0
# swapoff -a # Temporarily Closed , Permanent shutdown requires writing fatab
3.3、 Modify hostname
# vim /etc/hostname
192.168.37.74 K8S-master
192.168.37.75 K8S-node01
192.168.37.76 K8S-mast02
4、mac On the configuration Ansible
4.1、 stay Ansible On the server /etc/hosts Add... To the file k8s Server node information
192.168.37.74 K8S-master
192.168.37.75 K8S-node01
192.168.37.76 K8S-node02
4.2、 stay Ansible On the server /etc/ansible/hosts Add... To the file k8s Server nodes
[k8s-all]
K8S-master
K8S-node01
K8S-node02
[k8s-master]
K8S-master
[k8s-nodes]
K8S-node01
K8S-node02
4.3、 modify k8s Cluster nodes /etc/hosts( Not necessary )
Modify all hosts /etc/hosts file , add to IP/ Host name mapping , Convenient through the host name ssh visit
(1) establish playbook file ( Reference resources set_hosts_playbook.yml)
vim set_hosts_playbook.yml
---
- hosts: k8s-all
remote_user: root
tasks:
- name: backup /etc/hosts
shell: mv /etc/hosts /etc/hosts_bak
- name: copy local hosts file to remote
copy: src=/etc/hosts dest=/etc/ owner=root group=root mode=0644
(2) perform ansible-playbook
ansible-playbook set_hosts_playbook.yml
5、 install docker
Install... On all hosts docker
5.1、 establish playbook file ( Reference resources install_docker_playbook.yml)
$ vim install_docker_playbook.yml
- hosts: k8s-all
remote_user: root
vars:
docker_version: 18.09.2
tasks:
- name: install dependencies
#shell: yum install -y yum-utils device-mapper-persistent-data lvm2
yum: name={{item}} state=present
with_items:
- yum-utils
- device-mapper-persistent-data
- lvm2
- name: config yum repo
shell: yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
- name: install docker
yum: name=docker-ce-{{docker_version}} state=present
- name: start docker
shell: systemctl enable docker && systemctl start docker
5.2、 perform ansible-playbook
ansible-playbook install_docker_playbook.yml
Error report in execution , There's no connection at home docker Default overseas address , Change the image address to http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo Do it again .