1.服务器规划
部署节点
etcd节点
master节点
node节点
192.168.0.101
是
是
是
192.168.0.102
是
192.168.0.103
是
192.168.0.104
是
2.部署步骤
2.1在每个节点安装依赖工具
# 文档中脚本默认均以root用户执行
# 安装 epel 源并更新
yum install epel-release -y
yum update
# 安装python
yum install python -y
2.2在部署节点安装ansible
yum install git python-pip -y
# pip安装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
作者:泛轻舟gen
链接:https://www.jianshu.com/p/0652522d3142
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
2.3部署到各个节点免秘钥登录
ssh-keygen -t rsa -b 2048 回车 回车 回车
ssh-copy-id $IPs #$IPs为所有节点地址包括自身,按照提示输入yes 和root密码
2.4在部署节点安装k8s安装
2.4.1 使用kubeasz简化安装
# 方式一:使用git clone
git clone https://github.com/gjmzj/kubeasz.git
mkdir -p /etc/ansible
mv kubeasz/* /etc/ansible
# 方式二:从发布页面 https://github.com/gjmzj/kubeasz/releases 下载源码解压到同样目录
# 本文用的是离线安装,版本为:kubeasz-0.4.0.tar
2.4.2 下载k8s代码版本包
#离线下载地址;
#https://pan.baidu.com/s/1c4RFaA#list/path=%2F
#当前版本:k8s.1-11-3.tar
tar zxvf k8s.1-11-3.tar.gz # 以安装k8s v1.11.3为例
mv bin/* /etc/ansible/bin
2.5配置集群参数
#单主多从配置
cd /etc/ansible && cp example/hosts.m-single.example hosts
修改详情如下:
# 'deploy' node, which the ansible-playbooks usually run on
# variable 'NTP_ENABLED(=yes/no)' enables/disables the NTP server 'chrony'
[deploy]
192.168.0.101 NTP_ENABLED=yes
# 'etcd' cluster must have odd member(s) (1,3,5,...)
# variable 'NODE_NAME' is the distinct name of a member in 'etcd' cluster
[etcd]
192.168.0.101 NODE_NAME=etcd1
[kube-master]
192.168.0.101
[kube-node]
192.168.0.102
192.168.0.103
192.168.0.104
# variable NEW_INSTALL: 'yes' to setup a new harbor server; 'no' to integrate with existed one
[harbor]
#192.168.1.8 HARBOR_DOMAIN="harbor.yourdomain.com" NEW_INSTALL=no
# group reserved, add new 'kube-node' in it
[new-node]
#192.168.1.xx
[all:vars]
# --------- Main Variables ---------------
# Cluster Deployment Mode: allinone, single-master, multi-master
DEPLOY_MODE=single-master
# Versions supported: v1.8, v1.9, v1.10, v1.11, v1.12
K8S_VER="v1.11"
# Cluster's Master IP, auto generated
MASTER_IP="{{ groups['kube-master'][0] }}"
KUBE_APISERVER="https://{{ MASTER_IP }}:6443"
# Network plugins supported: calico, flannel, kube-router, cilium
CLUSTER_NETWORK="flannel"
# K8S Service CIDR, not overlap with node(host) networking
SERVICE_CIDR="10.68.0.0/16"
# Cluster CIDR (Pod CIDR), not overlap with node(host) networking
CLUSTER_CIDR="172.20.0.0/16"
# NodePort Range
NODE_PORT_RANGE="20000-40000"
# Kubernetes SVC IP (usually assigned with the first available IP of 'SERVICE_CIDR')
CLUSTER_KUBERNETES_SVC_IP="10.68.0.1"
# Cluster DNS Server's IP (assigned with an available IP of 'SERVICE_CIDR')
CLUSTER_DNS_SVC_IP="10.68.0.2"
# Cluster DNS Domain
CLUSTER_DNS_DOMAIN="cluster.local."
# Basic auth for apiserver
BASIC_AUTH_USER="admin"
BASIC_AUTH_PASS="test1234"
# -------- Additional Variables --------------------
# Binaries Directory
bin_dir="/opt/kube/bin"
# CA and other components cert/key Directory
ca_dir="/etc/kubernetes/ssl"
# Deploy Directory (kubeasz workspace), don't change the default value right now
base_dir="/etc/ansible"
2.6 下载离线docker包指定文件夹
#从百度网盘下载https://pan.baidu.com/s/1c4RFaA
#下载basic_images_kubeasz_0.3.tar.gz
#basic_images_kubeasz_x.y.tar.gz 下载解压到/etc/ansible/down 目录
tar zxvf basic_images_kubeasz_0.3.tar.gz -C /etc/ansible/down
2.6开始安装
#cd /etc/ansible
# 分步安装
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
ansible-playbook 07.cluster-addon.yml
# 一步安装
#ansible-playbook 90.setup.yml
2.6获取dashbord访问链接
# 查看集群服务
kubectl cluster-info|grep dashboard
#结果如下:
kubernetes-dashboard is running at https://192.168.0.101:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
2.7获取dashbord访问token进行登录
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
2.8未完待续..........