目录
1. All-in-One模式安装 KubeSphere
All-in-one模式即在唯一一台Linux服务器上同时安装K8s相关组件、KubeSphere组件。
对于刚接触 KubeSphere 并想快速上手该容器平台的用户,All-in-One 安装模式是最佳的选择,
它能够帮助您零配置快速部署 KubeSphere 和 Kubernetes。
1.1 基础环境准备
要求:
- ubuntu 16.04、18.04
- 单节点最低要求:2核心 4G 40G磁盘
- 安装docker 19.3.8 +
- 安装ssh、socat、contrack
- 可使用sudo、curl、openssl
实际安装时使用的是新制作的VirboxBox虚拟机
,
- Ubuntu20.04.3
- 设置内存6144MB,CPU为6核心
实际测试默认1核心会导致安装k8s失败,2核心导致prometheus因cpu不足而启动失败
安装curl、socat、contrack脚本
su root
apt install curl
apt install socat
apt install conntrack
1.2 下载kubekey
下载命令
# 国内建议设置KKZONE=cn, 后续下载docker镜像会走阿里云docker镜像仓库
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v1.2.0 sh -
下载结果如下图
若无法访问github,可通过其他可以正常访问github的电脑手动下载,
KubeKey release地址:https://github.com/kubesphere/kubekey/releases
1.3 开始安装
chmod +x kk
./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.0
安装过程日志
在安装过程中相关下载如下:
1.4 访问Kubesphere管理界面
安装完成后提示如下
#####################################################
### Welcome to KubeSphere! ###
#####################################################
Console: http://192.168.3.120:30880
Account: admin
Password: P@88w0rd
NOTES:
1. After you log into the console, please check the
monitoring status of service components in
"Cluster Management". If any service is not
ready, please wait patiently until all components
are up and running.
2. Please change the default password after login.
#####################################################
https://kubesphere.io 2021-11-30 20:29:28
#####################################################
INFO[20:29:37 CST] Installation is complete.
Please check the result using the command:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
该提示亦可通过如下命令获取(即在kubesphere-system.ks-installer容器的日志中获取):
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
按提示登录ks管理界面:
Console: http://192.168.3.120:30880
Account: admin
Password: P@88w0rd
第一次登录成功后会提示修改默认密码
登录成功后具体管理界面如下图
2. 拷贝ks all-in-one虚拟机镜像
如果网络没有限制(比如我家里的网络),按照官方的安装方法可以很顺利的完成安装。
但是如果网络有限制(比如公司网络),比如限制访问公网、github等,那就得想别的办法了。
在安装过程中可以发现,kubeKey下载如下相关组件、docker镜像(这些组件在我公司网络是无法直接下载的)。
我使用的方法比较暴力,就是跨电脑拷贝(家里电脑 -> 公司电脑)VirtualBox虚拟机
,
在家里把Ks相关组件下载成功,然后到公司网络后即无需再次下载,
具体核心步骤如下文。
2.1 导出已安装KubeSphere的虚拟机镜像
直接将安装Kubesphere成功的VirtualBox虚拟机(家里电脑上VirtualBox)导出,
即拷贝对应虚拟机存储目录中的.vdi文件。
2.2 导入vdi创建新的虚拟机
然后在公司环境的VirtualBox中以之前导出的.vdi文件新建虚拟机,
导入成功后的虚拟机镜像就已经拥有了如上图中相关组件、docker镜像,无需再次下载。
注: 关于VirtualBox的导入、导出可参见我之前的博客:VirtualBox复制虚拟机(同电脑、跨电脑) - 2. 跨电脑复制
2.3 修改新建虚拟机网络配置
由于家里虚拟机使用的桥接网卡
模式,公司环境使用的NAT + Host-only
模式,因此还需修改网络配置(修改Host-only网卡对应IP),我公司的网络限制比较多,还需设置代理(通用、docker)、CA证书。
注: 设置代理(vim /etc/profile)时需额外添加no_proxy=lb.kubesphere.local
,
即设置域名lb.kubesphere.local不走代理,否则虚拟机中kubectl报错unknow host,
实际测试即使不设置no_proxy,在kubesphere管理界面中也可正常使用kubectl。
2.4 删除已安装的k8s+kubesphere
启动新迁移的虚拟机,修改网络后,发现之前已安装的K8s已不好用,
可通过如下命令删除已安装的k8s
# all-in-one删除方式(实际使用)
./kk delete cluster
# 根据配置文件删除
./kk delete cluster [-f config-sample.yaml]
2.5 通过kk + config-sample.yaml重新安装kubesphere
起初尝试通过./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.0
命令直接安装,
但是由于NAT + Host-only
网络模式存在2张网卡(2个IP),Kubekey工具自动识别NAT网卡对应的IP进行安装(宿主机无法访问此IP),应该使用Host-only网卡对应的IP才可正确安装,
所以最后采用创建配置文件的安装方式进行单节点安装。
2.5.1 创建配置文件
# 创建示例配置文件(若不指定-f则默认输出到config-sample.yaml文件)
./kk create config--with-kubernetes v1.21.5 --with-kubesphere v3.2.0 -f config-sample.yaml
2.5.2 修改config-sample.yaml文件
修改config-sample.yaml文件,此时需注意:
address IP需设置为Host-only网卡对应的IP
etcd、master、worker均设置成同一节点
具体config-sample.yaml内容示例如下:
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: sample
spec:
hosts:
# 此处的address为host-only网卡对应的IP
- {name: ks-all-in-one, address: 192.168.56.120, internalAddress: 192.168.56.120, user: root, password: "123456"}
roleGroups:
etcd:
- ks-all-in-one
master:
- ks-all-in-one
worker:
- ks-all-in-one
controlPlaneEndpoint:
##Internal loadbalancer for apiservers
#internalLoadbalancer: haproxy
domain: lb.kubesphere.local
address: ""
port: 6443
kubernetes:
version: v1.21.5
clusterName: cluster.local
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
registry:
registryMirrors: []
insecureRegistries: []
addons: []
---
# 示例文件中的余下部分暂时保持默认
2.5.3 根据配置文件创建kubesphere
修改完此config-sample.yaml,可根据此配置文件创建kubesphere,命令如下
./kk create cluster -f config-sample.yaml
安装完成后,具体提示中的Console: http://192.168.56.120:30880
即为Host-only网卡对应的IP,
之后即可在宿主机通过该IP访问KubeSphere管理界面。