安装KubeSphere

Linux上多节点安装

安装docker

  • 换科大源
1
yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
1
2
3
4
sed -i 's+download.docker.com+mirrors.ustc.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

# 刷新缓存
yum makecache
  • 安装docker
1
2
3
4
yum install docker-ce    # 默认安装最新版本

yum list docker-ce --showduplicates #查看当前镜像的docker版本
yum install --setopt=obsoletes=0 docker-ce-20.10.24-3.el7 #指定安装版本
  • 配置镜像加速地址
1
2
3
4
5
6
7
8
9
10
11
mkdir -p /etc/docker
# 同时修改cgroupfs驱动为systemd,与kubelet一致否则kubelet启动失败
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://44voctpv.mirror.aliyuncs.com",
"https://docker.1panel.live"
],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
  • 启动docker
1
2
3
systemctl  daemon-reload
systemctl start docker
systemctl enable docker

安装依赖

1
yum install -y socat conntrack ebtables ipset

下载KubeKey

  • 先执行以下命令以确保您从正确的区域下载 KubeKey
1
export KKZONE=cn
  • 执行以下命令下载 KubeKey:
1
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -
  • 赋予可执行权限
1
chmod +x kk

创建集群

  • 创建配置文件
1
./kk create config --with-kubernetes v1.22.16 --with-kubesphere v3.3.2
  • 修改默认生成的配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
spec:
hosts:
- {name: master, address: 192.168.0.2, internalAddress: 192.168.0.2, user: ubuntu, password: Testing123}
- {name: node1, address: 192.168.0.3, internalAddress: 192.168.0.3, user: ubuntu, password: Testing123}
- {name: node2, address: 192.168.0.4, internalAddress: 192.168.0.4, user: ubuntu, password: Testing123}
roleGroups:
etcd:
- master
control-plane:
- master
worker:
- node1
- node2
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: 6443
  • 执行安装命令
1
./kk create cluster -f config-sample.yaml
  • 验证安装
1
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

Linux离线安装

部署准备

  • 导出manifest-sample.yaml用于离线安装
1
./kk create manifest
  • 修改配置文件内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Manifest
metadata:
name: sample
spec:
arches:
- amd64
operatingSystems:
- arch: amd64
type: linux
id: centos
version: "7"
osImage: CentOS Linux 7 (Core)
repository:
iso:
localPath: ./centos7-rpms-amd64.iso
kubernetesDistributions:
- type: kubernetes
version: v1.22.16
components:
helm:
version: v3.9.0
cni:
version: v0.9.1
etcd:
version: v3.4.13
containerRuntimes:
- type: docker
version: 20.10.8 # 只支持这个版本
crictl:
version: v1.24.0
docker-registry:
version: "2"
harbor:
version: v2.4.1
docker-compose:
version: v2.2.2
images:
- registry.cn-beijing.aliyuncs.com/kubesphereio/alertmanager:v0.23.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/cni:v3.23.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/coredns:1.8.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/defaultbackend-amd64:1.4
- registry.cn-beijing.aliyuncs.com/kubesphereio/k8s-dns-node-cache:1.15.12
- registry.cn-beijing.aliyuncs.com/kubesphereio/ks-apiserver:v3.3.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/ks-console:v3.3.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/ks-controller-manager:v3.3.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/ks-installer:v3.3.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-apiserver:v1.22.16
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controller-manager:v1.22.16
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controllers:v3.23.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-proxy:v1.22.16
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-rbac-proxy:v0.11.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-rbac-proxy:v0.8.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-scheduler:v1.22.16
- registry.cn-beijing.aliyuncs.com/kubesphereio/kube-state-metrics:v2.5.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/kubectl:v1.22.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/linux-utils:3.3.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/node-exporter:v1.3.1
- registry.cn-beijing.aliyuncs.com/kubesphereio/node:v3.23.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/notification-manager-operator:v1.4.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/notification-manager:v1.4.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/notification-tenant-sidecar:v3.2.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.5
- registry.cn-beijing.aliyuncs.com/kubesphereio/pod2daemon-flexvol:v3.23.2
- registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus-config-reloader:v0.55.1
- registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus-operator:v0.55.1
- registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus:v2.34.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/provisioner-localpv:3.3.0
- registry.cn-beijing.aliyuncs.com/kubesphereio/snapshot-controller:v4.0.0
registry:
auths: {}

导出制品 artifact

1
2
export KKZONE=cn
./kk artifact export -m manifest-sample.yaml -o kubesphere.tar.gz

离线安装集群

  • 将下载的 KubeKey 和制品 artifact 通过 U 盘等介质拷贝至离线环境安装节点
  • 创建离线集群配置文件
1
./kk create config --with-kubernetes v1.22.16 --with-kubesphere v3.3.2 -f config-sample.yaml
  • 修改配置文件
1
vim config-sample.yaml

按照实际离线环境配置修改节点信息。
必须指定registry仓库部署节点(用于 KubeKey 部署自建 Harbor 仓库)。
registry里必须指定type类型为harbor,否则默认安装 docker registry。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: master, address: 192.168.0.3, internalAddress: 192.168.0.3, user: root, password: "<REPLACE_WITH_YOUR_ACTUAL_PASSWORD>"}
- {name: node1, address: 192.168.0.4, internalAddress: 192.168.0.4, user: root, password: "<REPLACE_WITH_YOUR_ACTUAL_PASSWORD>"}

roleGroups:
etcd:
- master
control-plane:
- master
worker:
- node1
# 如需使用 kk 自动部署镜像仓库,请设置该主机组 (建议仓库与集群分离部署,减少相互影响)
registry:
- node1
controlPlaneEndpoint:
## Internal loadbalancer for apiservers
# internalLoadbalancer: haproxy

domain: lb.kubesphere.local
address: ""
port: 6443
kubernetes:
version: v1.22.12
clusterName: cluster.local
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
multusCNI:
enabled: false
registry:
# 如需使用 kk 部署 harbor, 可将该参数设置为 harbor,不设置该参数且需使用 kk 创建容器镜像仓库,将默认使用docker registry。
type: harbor
# 如使用 kk 部署的 harbor 或其他需要登录的仓库,可设置对应仓库的auths,如使用 kk 创建的 docker registry 仓库,则无需配置该参数。
# 注意:如使用 kk 部署 harbor,该参数请于 harbor 启动后设置。
#auths:
# "dockerhub.kubekey.local":
# username: admin
# password: xxxxxxx
# 设置集群部署时使用的私有仓库
privateRegistry: ""
namespaceOverride: ""
registryMirrors: []
insecureRegistries: []
addons: []
  • 安装镜像仓库
1
./kk init registry -f config-sample.yaml -a kubesphere.tar.gz

安装Harbor项目

  • 下载初始化Harbor脚本

初始化Harbor脚本

  • 修改脚本配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash

# Copyright 2018 The KubeSphere Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

url="https://dockerhub.kubekey.local" #修改url的值为https://dockerhub.kubekey.local
user="admin"
passwd="xxxxxx"

harbor_projects=(library
kubesphereio
kubesphere
calico
coredns
openebs
csiplugin
minio
mirrorgooglecontainers
osixia
prom
thanosio
jimmidyson
grafana
elastic
istio
jaegertracing
jenkins
weaveworks
openpitrix
joosthofman
nginxdemos
fluent
kubeedge
kubesphereio # 官方文档没加这个project后边报错
)

for project in "${harbor_projects[@]}"; do
echo "creating $project"
curl -u "${user}:${passwd}" -X POST -H "Content-Type: application/json" "${url}/api/v2.0/projects" -d "{ \"project_name\": \"${project}\", \"public\": true}" -k #curl命令末尾加上 -k
done
  • 执行脚本创建Harbor项目
1
2
chmod +x create_project_harbor.sh
./create_project_harbor.sh

装 KubeSphere 集群

  • 修改集群配置文件config-sample.yaml
1
2
3
4
5
6
7
8
9
10
11
12
...
registry:
type: harbor
auths:
"dockerhub.kubekey.local":
username: admin
password: xxxxxxxxxx
privateRegistry: "dockerhub.kubekey.local"
namespaceOverride: "kubesphereio"
registryMirrors: []
insecureRegistries: []
addons: []

新增auths配置增加dockerhub.kubekey.local和账号密码。
privateRegistry增加dockerhub.kubekey.local。
namespaceOverride增加kubesphereio。

  • 执行以下命令安装 KubeSphere 集群:
1
./kk create cluster -f config-sample.yaml -a kubesphere.tar.gz --with-packages

安装KubeSphere
https://blog.erhuoyan.cn/2024/07/26/ffb5115257f4/
作者
erhuoyan
发布于
2024年7月26日
许可协议