Kubernetes 入门篇 (二) Kubernetes 安装—Ansible
环境规划
主机名 | OS | IP地址 | 角色 |
---|---|---|---|
k8s-master1 | Centos 7.6 | 192.168.100.200 | Master,etcd |
k8s-master2 | Centos 7.6 | 192.168.100.206 | Master |
k8s-node1 | Centos 7.6 | 192.168.100.201 | Node |
k8s-node2 | Centos 7.6 | 192.168.100.202 | Node |
- | - | 192.168.100.207 | Vip |
准备工作
1. 设置主机名
[root@k8s_master1 ~]# hostnamectl set-hostname k8s-master1
[root@k8s_master1 ~]# bash
[root@k8s_master2 ~]# hostnamectl set-hostname k8s-master2
[root@k8s_master2 ~]# bash
[root@k8s_node1 ~]# hostnamectl set-hostname k8s-node1
[root@k8s_node1 ~]# bash
[root@k8s_node2 ~]# hostnamectl set-hostname k8s-node2
[root@k8s_node2 ~]# bash
2. 设置hosts解析,所有节点那都添加
[root@k8s-master1 ~]# echo "192.168.100.200 k8s-master1" >> /etc/hosts
[root@k8s-master1 ~]# echo "192.168.100.206 k8s-master2" >> /etc/hosts
[root@k8s-master1 ~]# echo "192.168.100.201 k8s-node1" >> /etc/hosts
[root@k8s-master1 ~]# echo "192.168.100.202 k8s-node2" >> /etc/hosts
3. 在Master节点中设置 ssh 免密登录
[root@k8s-master1 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Kbht6inNkV081LUlBO1GxiDMGevGt/eZtO0dIS74eQ0 root@k8s-master
The key's randomart image is:
+---[RSA 2048]----+
| oo+oB+ . |
| =o. =+ |
| o. +. |
| . o+. o |
| .o..S... . . |
| oo.o ....E. .|
| o..o .....+. |
| . o+ ..o+ *o|
| o+ o. =.+|
+----[SHA256]-----+
[root@k8s-master1 ~]# for i in 0 1 2 6 ;do ssh-copy-id root@192.168.100.20$i ;done
4. 安装Ansilbe(在Master1中)
[root@k8s-master1 ~]# yum -y install epel-release
[root@k8s-master1 ~]# yum update -y
[root@k8s-master1 ~]# yum install -y python-pip git
[root@k8s-master1 ~]# pip install pip --upgrade -i http://mirrors.aliyun.com/pypi/simple/
[root@k8s-master1 ~]# pip install --no-cache-dir ansible -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
5. 下载所需二进制包
链接:https://pan.baidu.com/s/1kmZbZp06nHKuwl7z_CR0Rg
提取码:idle
或者浏览器打开 https://download.csdn.net/download/weixin_41843733/12628737
6. 拉取 Ansible 项目
此安装方式采用的是 easzlab/kubeasz 的项目代码
项目地址: https://github.com/easzlab/kubeasz
[root@k8s-master1 ~]# git clone https://github.com/gjmzj/kubeasz.git
安装Kubernetes
1. 编辑 Ansible 配置
[root@k8s-master1 ~]# tar zxf k8s.1-13-12.tar.gz
[root@k8s-master1 ~]# mkdir -p /etc/ansible
[root@k8s-master1 ~]# mv kubeasz/* /etc/ansib