一个计算机技术爱好者与学习者

0%

好好学Sealos:Sealos制作KubeSphere集群镜像

1. 前言

本文中,我们会基于sealos制作一个Kubesphere集群镜像。
使用这个集群镜像,我们能够在sealos拉起的K8S集群中,一键部署KubeSphere。

参考文档:

2. 前置条件

安装sealos4.2.0,拉起K8S 1.24.8集群(同时安装helm),具体方法参考《sealos入门篇》

3. 制作KubeSphere集群镜像

1、准备资源清单

1
2
3
4
mkdir kubesphere && cd kubesphere
mkdir manifests
wget -O manifests/01-kubesphere-installer.yaml https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/kubesphere-installer.yaml
wget -O manifests/02-cluster-configuration.yaml https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/cluster-configuration.yaml

2、修改 manifests/02-cluster-configuration.yaml
ks-apiserver和ks-controller-manager的资源调整示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
spec:
common:
core:
console:
enableMultiLogin: true
port: 30880
apiserver:
resources:
requests:
cpu: 100m
memory: 400Mi
limits:
cpu: "2"
memory: 8Gi
controllerManager:
resources:
requests:
cpu: 100m
memory: 400Mi
limits:
cpu: "2"
memory: 8Gi
minio:
volumeSize: 200Gi # Minio PVC size.

如果不想安装Prometheus,那么需要修改monitoring使用外部Prometheus(可以配置个假的地址)。

1
2
3
4
5
spec:
common:
monitoring:
type: external
endpoint: http://prometheus-operated.prometheus.svc:9090

参考文档:安装时如何不安装Prometheus

3、添加镜像列表

1
2
3
4
5
cat manifests/* | grep image
mkdir -p images/shim/
curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/images-list.txt
vim images-list.txt
mv images-list.txt images/shim/

编辑images-list.txt时,因为我们只想要一个kubesphere集群用来管理k8s资源,所以只保留kubesphere-images和kubesphere-monitoring-images。

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
##kubesphere-images
kubesphere/ks-installer:v3.3.2
kubesphere/ks-apiserver:v3.3.2
kubesphere/ks-console:v3.3.2
kubesphere/ks-controller-manager:v3.3.2
#kubesphere/kubectl:v1.20.0
kubesphere/kubectl:v1.22.0
kubesphere/kubefed:v0.8.1
kubesphere/tower:v0.2.0
minio/minio:RELEASE.2019-08-07T01-59-21Z
minio/mc:RELEASE.2019-08-07T23-14-43Z
csiplugin/snapshot-controller:v4.0.0
kubesphere/nginx-ingress-controller:v1.1.0
mirrorgooglecontainers/defaultbackend-amd64:1.4
kubesphere/metrics-server:v0.4.2
redis:5.0.14-alpine
haproxy:2.0.25-alpine
alpine:3.14
osixia/openldap:1.3.0
kubesphere/netshoot:v1.0
##kubesphere-monitoring-images
jimmidyson/configmap-reload:v0.5.0
prom/prometheus:v2.34.0
kubesphere/prometheus-config-reloader:v0.55.1
kubesphere/prometheus-operator:v0.55.1
kubesphere/kube-rbac-proxy:v0.11.0
kubesphere/kube-state-metrics:v2.5.0
prom/node-exporter:v1.3.1
prom/alertmanager:v0.23.0
thanosio/thanos:v0.25.2
grafana/grafana:8.3.3
kubesphere/kube-rbac-proxy:v0.8.0
kubesphere/notification-manager-operator:v1.4.0
kubesphere/notification-manager:v1.4.0
kubesphere/notification-tenant-sidecar:v3.2.0

4、编写Dockerfile

1
2
3
4
FROM scratch
COPY ../kubesphere .
CMD ["kubectl apply -f manifests/01-kubesphere-installer.yaml \
&& kubectl apply -f manifests/02-cluster-configuration.yaml"]

5、构建集群镜像

1
2
sealos build -f Dockerfile -t docker.io/voidking/kubesphere:v3.3.2 .
sealos inspect docker.io/voidking/kubesphere:v3.3.2

4. 使用KubeSphere集群镜像

4.1. 自定义安装KubeSphere

1
2
3
4
sealos run docker.io/voidking/kubesphere:v3.3.2 --cmd="kubectl apply -f manifests/01-kubesphere-installer.yaml \
&& kubectl apply -f manifests/02-cluster-configuration.yaml"

kubectl get all -n kubesphere-system

默认帐户 admin ,默认密码 P@88w0rd

4.2. 上传集群镜像

上传到公共镜像仓库

1
2
3
4
sealos push docker.io/voidking/kubesphere:v3.3.2
sealos tag docker.io/voidking/kubesphere:v3.3.2 hub.sealos.cn/voidking/kubesphere:v3.3.2
sealos login -k config.yml hub.sealos.cn
sealos push hub.sealos.cn/voidking/kubesphere:v3.3.2

上传到私有镜像仓库

1
2
3
sealos tag docker.io/voidking/kubesphere:v3.3.2 harbor.voidking.com/sealos/kubesphere:v3.3.2
sealos login harbor.voidking.com
sealos push harbor.voidking.com/sealos/kubesphere:v3.3.2