1.下载Kubersphere离线安装包
https://kubesphere.com.cn/forum/d/852-kubesphere-2-1-1-kubernetes
tar -zxvf kubesphere-all-offline-v2.1.1.tar.gz
cd kubesphere-all-offline-v2.1.1/conf
2.配置hosts.ini
以下示例在 CentOS 7.5 上使用 root用户安装,每台机器信息占一行,不能分行。
root 配置 hosts.ini 示例:
[all]
master ansible_connection=local ip=192.168.0.1
node1 ansible_host=192.168.0.2 ip=192.168.0.2 ansible_ssh_pass=PASSWORD
node2 ansible_host=192.168.0.3 ip=192.168.0.3 ansible_ssh_pass=PASSWORD
[kube-master]
master
[kube-node]
node1
node2
[etcd]
master
[k8s-cluster:children]
kube-node
kube-master
说明:
[all]
: 中需要修改集群中各个节点的内网 IP 和主机 root 用户密码:主机名为 “master” 的节点作为已通过 SSH 连接的 Taskbox 所以无需填写密码。Node 节点的参数比如 node1 和 node2 的ansible_host
和ip
都替换为当前 node1 和 node2 的内网 IP,将ansible_ssh_pass
相应替换为 node1 和 node2 的root
用户密码。参数解释:ansible_connection
: 与主机的连接类型,此处设置为local
即本地连接ansible_host
: 集群中将要连接的主机地址或域名ip
: 集群中将要连接的主机 IPansible_user
: 默认的 SSH 用户名 (非 root),例如 ubuntuansible_become_pass
: 默认的 SSH 用户登录密码ansible_ssh_pass
: 待连接主机 root 用户的密码
[kube-master]
和[etcd]
:应将主机名 “master” 填入 [kube-master] 和 [etcd] 部分,”master” 节点作为 taskbox,用来执行整个集群的安装任务,同时 “master” 节点在 KubeSphere 集群架构中也将作为 Master 节点管理集群和 etcd 节点负责保存集群的数据。[kube-node]
:将主机名 “node1”,”node2” 填入 [kube-node] 部分,作为 KubeSphere 集群的 node 节点。[local-registry]
:离线安装包中该参数值表示设置哪个节点作为本地镜像仓库,默认值为 master 节点。建议给该节点的/mnt/registry
单独挂盘 (参考 fdisk 命令),使镜像可保存在持久化存储并节省机器空间。
3.配置common.yaml
3.1.持久化存储配置说明(NFS)
NFS 配置文件
nfs_client_enabled: false
nfs_client_is_default_class: false
# Hostname of the NFS server(ip or hostname)
nfs_server: SHOULD_BE_REPLACED
# Basepath of the mount point
nfs_path: SHOULD_BE_REPLACED
nfs_vers3_enabled: false
nfs_archiveOnDelete: false
属性配置说明:
NFS | Description |
---|---|
nfs_client_enable | 是否使用 NFS 作为持久化存储,是:true;否:false |
nfs_client_is_default_class | 是否设定为默认存储类型,是:true;否:false 注:系统中存在多种存储类型时,只能设定一种为默认存储类型 |
nfs_server | 允许其访问的 NFS 服务端地址,可以是 IP 或 Hostname |
nfs_path | NFS 共享目录,即服务器上共享出去的文件目录,可参考 Kubernetes 官方文档 |
nfs_vers3_enabled | 指定要使用的 NFS 协议版本,默认 false 表示 v4,设置 true 则为 v3 |
nfs_archiveOnDelete | 指定 archiveOnDelete 为 false 时,则会自动删除 oldPath 下的所有数据,即 Pod 对应的数据持久化存储数据 |
3.2.可选的组件安装
KubeSphere 默认仅开启最小化安装,若您的机器资源满足上述表格中完整安装的需求,建议您在安装前开启所有组件,体验 KubeSphere 完整的平台功能。
编辑 conf/common.yaml,参考如下说明开启所有组件(将 false 改为 true):
# LOGGING CONFIGURATION
# logging is an optional component when installing KubeSphere, and
# Kubernetes builtin logging APIs will be used if logging_enabled is set to false.
# Builtin logging only provides limited functions, so recommend to enable logging.
logging_enabled: true # 是否安装内置的日志系统
elasticsearch_master_replica: 1 # es 主节点副本数,主节点数不能为偶数
elasticsearch_data_replica: 2 # 数据节点副本数
elasticsearch_volume_size: 20Gi # Elasticsearch 存储卷大小
log_max_age: 7 # 集群内置的 Elasticsearch 中日志保留时间,默认是 7 天
elk_prefix: logstash # 自定义 index 命名方式,index 将以 ks-<elk_prefix>-log 形式命名
kibana_enabled: false # 是否部署内置的 Kibana
#external_es_url: SHOULD_BE_REPLACED # 安装支持对接外部的 Elasticsearch 7.x,可减少资源消耗,此处填写 ES 服务的地址
#external_es_port: SHOULD_BE_REPLACED # 此处填写 ES 服务暴露的端口号
#DevOps Configuration
devops_enabled: true # 是否安装内置的 DevOps 系统(支持流水线、 Source-to-Image 和 Binary-to-Image 等功能)
jenkins_memory_lim: 8Gi # Jenkins 内存限制,默认 8 Gi
jenkins_memory_req: 4Gi # Jenkins 内存请求,默认 4 Gi
jenkins_volume_size: 8Gi # Jenkins 存储卷大小,默认 8 Gi
jenkinsJavaOpts_Xms: 3g # 以下三项为 jvm 启动参数
jenkinsJavaOpts_Xmx: 6g
jenkinsJavaOpts_MaxRAM: 8g
sonarqube_enabled: true # 是否安装内置的 SonarQube (代码静态分析工具)
#sonar_server_url: SHOULD_BE_REPLACED # 安装支持对接外部已有的 SonarQube,此处填写 SonarQube 服务的地址
#sonar_server_token: SHOULD_BE_REPLACED # 此处填写 SonarQube 的 Token
# Following components are all optional for KubeSphere,
# Which could be turned on to install it before installation or later by updating its value to true
openpitrix_enabled: true # KubeSphere 应用商店
metrics_server_enabled: true # KubeSphere HPA(弹性伸缩)
servicemesh_enabled: true # KubeSphere Service Mesh
notification_enabled: true # KubeSphere 通知系统
alerting_enabled: true # KubeSphere 告警系统
4.安装 KubeSphere
KubeSphere 多节点部署会自动化地进行环境和文件监测、平台依赖软件的安装、Kubernetes 和 etcd 集群的自动化部署,以及存储的自动化配置。Installer 默认安装的 Kubernetes 版本 是 v1.16.7。
说明:
- 由于 Kubernetes 集群的 Cluster IP 子网网段默认是 10.233.0.0/18,Pod 的子网网段默认是 10.233.64.0/18,因此安装 KubeSphere 的节点 IP 地址范围不应与以上两个网段有重复,若遇到地址范围冲突可在配置文件 conf/common.yaml 修改 kube_service_addresses 或 kube_pods_subnet 的参数。
5.1.执行 install.sh 安装脚本
cd .. cd scripts ./install.sh
5.2. Multi-node 模式开始部署
输入数字 2 选择第二种 Multi-node 模式开始部署,安装程序会提示您的环境是否前提条件,若满足请输入 “yes” 开始安装。
################################################
KubeSphere Installer Menu
################################################
* 1) All-in-one
* 2) Multi-node
* 3) Quit
################################################
https://kubesphere.io/ 2020-02-23
################################################
Please input an option: 2
请确保您的环境满足上述要求,满足选择yes
Prerequisites:
1. It's recommended that Your OS is clean (without any other software installed), otherwise there may be conflicts.
2. OS requirements (For Minimal Installation only):at least 2 vCPUs and 4GB RAM.
3. Please make sure the storage service is available if you've configured storage parameters in the conf directory.
4. Make sure the DNS address in /etc/resolv.conf is available.
5. If your network configuration uses an firewall,you must ensure infrastructure components can communicate with each other through specific ports.
It's recommended that you turn off the firewall or follow the link configuriation:
https://github.com/kubesphere/ks-installer/blob/master/docs/NetWorkAccess.md
Please ensure that your environment has met the above requirements (yes/no)
选择存储类型
Only one default storage class can be set ! Must choose one from the following list:
1. local_volume
2. nfs_client
please choose: 2