离线安装

离线安装几乎与在线安装相同,不同之处是您必须创建一个本地仓库来托管 Docker 镜像。本教程演示了如何在离线环境中将 KubeSphere 安装到 Kubernetes 上。

开始下方步骤之前,请先参阅准备工作

步骤 1:准备一个私有镜像仓库

您可以使用 Harbor 或者其他任意私有镜像仓库。本教程以 Docker 仓库作为示例,并使用自签名证书(如果您有自己的私有镜像仓库,可以跳过这一步)。

使用自签名证书

  1. 执行以下命令生成您自己的证书:

    1. mkdir -p certs
    1. openssl req \
    2. -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \
    3. -x509 -days 36500 -out certs/domain.crt
  2. 当您生成自己的证书时,请确保在字段 Common Name 中指定一个域名。例如,本示例中该字段被指定为 dockerhub.kubekey.local

    自签名证书

启动 Docker 仓库

执行以下命令启动 Docker 仓库:

  1. docker run -d \
  2. --restart=always \
  3. --name registry \
  4. -v "$(pwd)"/certs:/certs \
  5. -v /mnt/registry:/var/lib/registry \
  6. -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
  7. -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  8. -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
  9. -p 443:443 \
  10. registry:2

备注

Docker 使用 /var/lib/docker 作为默认路径来存储所有 Docker 相关文件(包括镜像)。建议您添加附加存储卷,分别给 /var/lib/docker/mnt/registry 挂载至少 100G。请参见 fdisk 的参考命令。

配置仓库

  1. /etc/hosts 中添加一个条目,将主机名(即仓库域名;在本示例中是 dockerhub.kubekey.local)映射到您机器的私有 IP 地址,如下所示。

    1. # docker registry
    2. 192.168.0.2 dockerhub.kubekey.local
  2. 执行以下命令,复制证书到指定目录,并使 Docker 信任该证书。

    1. mkdir -p /etc/docker/certs.d/dockerhub.kubekey.local
    1. cp certs/domain.crt /etc/docker/certs.d/dockerhub.kubekey.local/ca.crt

    备注

    证书的路径与域名相关联。当您复制路径时,如果与上面设置的路径不同,请使用实际域名。

  3. 要验证私有仓库是否有效,您可以先复制一个镜像到您的本地机器,然后使用 docker pushdocker pull 来测试。

步骤 2:准备安装镜像

当您在离线环境中安装 KubeSphere 时,需要事先准备一个包含所有必需镜像的镜像包。

  1. 使用以下命令从能够访问互联网的机器上下载镜像清单文件 images-list.txt

    1. curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.2.0/images-list.txt

    备注

    该文件根据不同的模块列出了 ##+modulename 下的镜像。您可以按照相同的规则把自己的镜像添加到这个文件中。要查看完整文件,请参见附录

  2. 下载 offline-installation-tool.sh

    1. curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.2.0/offline-installation-tool.sh
  3. 使 .sh 文件可执行。

    1. chmod +x offline-installation-tool.sh
  4. 您可以执行命令 ./offline-installation-tool.sh -h 来查看如何使用脚本:

    1. [email protected]:/home/ubuntu# ./offline-installation-tool.sh -h
    2. Usage:
    3. ./offline-installation-tool.sh [-l IMAGES-LIST] [-d IMAGES-DIR] [-r PRIVATE-REGISTRY] [-v KUBERNETES-VERSION ]
    4. Description:
    5. -b : save kubernetes' binaries.
    6. -d IMAGES-DIR : the dir of files (tar.gz) which generated by `docker save`. default: ./kubesphere-images
    7. -l IMAGES-LIST : text file with list of images.
    8. -r PRIVATE-REGISTRY : target private registry:port.
    9. -s : save model will be applied. Pull the images in the IMAGES-LIST and save images as a tar.gz file.
    10. -v KUBERNETES-VERSION : download kubernetes' binaries. default: v1.17.9
    11. -h : usage message
  5. offline-installation-tool.sh 中拉取镜像。

    1. ./offline-installation-tool.sh -s -l images-list.txt -d ./kubesphere-images

    备注

    您可以根据需要选择拉取的镜像。例如,如果已经有一个 Kubernetes 集群了,您可以在 images-list.text 中删除 ##k8s-images 和在它下面的相关镜像。

步骤 3:推送镜像至私有仓库

将打包的镜像文件传输至您的本地机器,并运行以下命令把它推送至仓库。

  1. ./offline-installation-tool.sh -l images-list.txt -d ./kubesphere-images -r dockerhub.kubekey.local

备注

命令中的域名是 dockerhub.kubekey.local。请确保使用您自己仓库的地址

步骤 4:下载部署文件

与在现有 Kubernetes 集群上在线安装 KubeSphere 相似,您也需要事先下载 cluster-configuration.yamlkubesphere-installer.yaml

  1. 执行以下命令下载这两个文件,并将它们传输至您充当任务机的机器,用于安装。

    1. curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.2.0/cluster-configuration.yaml
    2. curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.2.0/kubesphere-installer.yaml
  2. 编辑 cluster-configuration.yaml 添加您的私有镜像仓库。例如,本教程中的仓库地址是 dockerhub.kubekey.local,将它用作 .spec.local_registry 的值,如下所示:

    1. spec:
    2. persistence:
    3. storageClass: ""
    4. authentication:
    5. jwtSecret: ""
    6. local_registry: dockerhub.kubekey.local # Add this line manually; make sure you use your own registry address.

    备注

    您可以在该 YAML 文件中启用可插拔组件,体验 KubeSphere 的更多功能。有关详情,请参考启用可插拔组件

  3. 编辑完成后保存 cluster-configuration.yaml。使用以下命令将 ks-installer 替换为您自己仓库的地址

    1. sed -i "s#^\s*image: kubesphere.*/ks-installer:.*# image: dockerhub.kubekey.local/kubesphere/ks-installer:v3.0.0#" kubesphere-installer.yaml

    警告

    命令中的仓库地址是 dockerhub.kubekey.local。请确保使用您自己仓库的地址。

步骤 5:开始安装

确定完成上面所有步骤后,您可以执行以下命令。

  1. kubectl apply -f kubesphere-installer.yaml
  2. kubectl apply -f cluster-configuration.yaml

步骤 6:验证安装

安装完成后,您会看到以下内容:

  1. #####################################################
  2. ### Welcome to KubeSphere! ###
  3. #####################################################
  4. Console: http://192.168.0.2:30880
  5. Account: admin
  6. Password: [email protected]
  7. NOTES
  8. 1. After logging into the console, please check the
  9. monitoring status of service components in
  10. the "Cluster Management". If any service is not
  11. ready, please wait patiently until all components
  12. are ready.
  13. 2. Please modify the default password after login.
  14. #####################################################
  15. https://kubesphere.io 20xx-xx-xx xx:xx:xx
  16. #####################################################

现在,您可以通过 http://{IP}:30880 使用默认帐户和密码 admin/[[email protected]](https://kubesphere.io/cdn-cgi/l/email-protection) 访问 KubeSphere 的 Web 控制台。

备注

要访问控制台,请确保在您的安全组中打开端口 30880。

附录

KubeSphere 3.2.0 镜像清单

  1. ##k8s-images
  2. kubesphere/kube-apiserver:v1.22.1
  3. kubesphere/kube-controller-manager:v1.22.1
  4. kubesphere/kube-proxy:v1.22.1
  5. kubesphere/kube-scheduler:v1.22.1
  6. kubesphere/kube-apiserver:v1.21.5
  7. kubesphere/kube-controller-manager:v1.21.5
  8. kubesphere/kube-proxy:v1.21.5
  9. kubesphere/kube-scheduler:v1.21.5
  10. kubesphere/kube-apiserver:v1.20.10
  11. kubesphere/kube-controller-manager:v1.20.10
  12. kubesphere/kube-proxy:v1.20.10
  13. kubesphere/kube-scheduler:v1.20.10
  14. kubesphere/kube-apiserver:v1.19.9
  15. kubesphere/kube-controller-manager:v1.19.9
  16. kubesphere/kube-proxy:v1.19.9
  17. kubesphere/kube-scheduler:v1.19.9
  18. kubesphere/pause:3.5
  19. kubesphere/pause:3.4.1
  20. coredns/coredns:1.8.0
  21. calico/cni:v3.20.0
  22. calico/kube-controllers:v3.20.0
  23. calico/node:v3.20.0
  24. calico/pod2daemon-flexvol:v3.20.0
  25. calico/typha:v3.20.0
  26. kubesphere/flannel:v0.12.0
  27. openebs/provisioner-localpv:2.10.1
  28. openebs/linux-utils:2.10.0
  29. kubesphere/k8s-dns-node-cache:1.15.12
  30. ##kubesphere-images
  31. kubesphere/ks-installer:v3.2.0
  32. kubesphere/ks-apiserver:v3.2.0
  33. kubesphere/ks-console:v3.2.0
  34. kubesphere/ks-controller-manager:v3.2.0
  35. kubesphere/kubectl:v1.20.0
  36. kubesphere/kubefed:v0.8.1
  37. kubesphere/tower:v0.2.0
  38. kubesphere/kubectl:v1.19.1
  39. minio/minio:RELEASE.2019-08-07T01-59-21Z
  40. minio/mc:RELEASE.2019-08-07T23-14-43Z
  41. csiplugin/snapshot-controller:v4.0.0
  42. kubesphere/nginx-ingress-controller:v0.48.1
  43. mirrorgooglecontainers/defaultbackend-amd64:1.4
  44. kubesphere/metrics-server:v0.4.2
  45. redis:5.0.12-alpine
  46. haproxy:2.0.22-alpine
  47. alpine:3.14
  48. osixia/openldap:1.3.0
  49. kubesphere/netshoot:v1.0
  50. ##kubeedge-images
  51. kubeedge/cloudcore:v1.7.2
  52. kubesphere/edge-watcher:v0.1.1
  53. kubesphere/edge-watcher-agent:v0.1.0
  54. ##gatekeeper-images
  55. openpolicyagent/gatekeeper:v3.5.2
  56. ##openpitrix-images
  57. kubesphere/openpitrix-jobs:v3.2.0
  58. ##kubesphere-devops-images
  59. kubesphere/devops-apiserver:v3.2.0
  60. kubesphere/devops-controller:v3.2.0
  61. kubesphere/devops-tools:v3.2.0
  62. kubesphere/ks-jenkins:v3.2.0-2.249.1
  63. jenkins/jnlp-slave:3.27-1
  64. kubesphere/builder-base:v3.2.0
  65. kubesphere/builder-nodejs:v3.2.0
  66. kubesphere/builder-maven:v3.2.0
  67. kubesphere/builder-go:v3.2.0
  68. kubesphere/builder-go:v3.2.0
  69. kubesphere/s2ioperator:v3.2.0
  70. kubesphere/s2irun:v3.2.0
  71. kubesphere/s2i-binary:v3.2.0
  72. kubesphere/tomcat85-java11-centos7:v3.2.0
  73. kubesphere/tomcat85-java11-runtime:v3.2.0
  74. kubesphere/tomcat85-java8-centos7:v3.2.0
  75. kubesphere/tomcat85-java8-runtime:v3.2.0
  76. kubesphere/java-11-centos7:v3.2.0
  77. kubesphere/java-8-centos7:v3.2.0
  78. kubesphere/java-8-runtime:v3.2.0
  79. kubesphere/java-11-runtime:v3.2.0
  80. kubesphere/nodejs-8-centos7:v3.2.0
  81. kubesphere/nodejs-6-centos7:v3.2.0
  82. kubesphere/nodejs-4-centos7:v3.2.0
  83. kubesphere/python-36-centos7:v3.2.0
  84. kubesphere/python-35-centos7:v3.2.0
  85. kubesphere/python-34-centos7:v3.2.0
  86. kubesphere/python-27-centos7:v3.2.0
  87. ##kubesphere-monitoring-images
  88. jimmidyson/configmap-reload:v0.3.0
  89. prom/prometheus:v2.26.0
  90. kubesphere/prometheus-config-reloader:v0.43.2
  91. kubesphere/prometheus-operator:v0.43.2
  92. kubesphere/kube-rbac-proxy:v0.8.0
  93. kubesphere/kube-state-metrics:v1.9.7
  94. prom/node-exporter:v0.18.1
  95. kubesphere/k8s-prometheus-adapter-amd64:v0.6.0
  96. prom/alertmanager:v0.21.0
  97. thanosio/thanos:v0.18.0
  98. grafana/grafana:7.4.3
  99. kubesphere/kube-rbac-proxy:v0.8.0
  100. kubesphere/notification-manager-operator:v1.4.0
  101. kubesphere/notification-manager:v1.4.0
  102. kubesphere/notification-tenant-sidecar:v3.2.0
  103. ##kubesphere-logging-images
  104. kubesphere/elasticsearch-curator:v5.7.6
  105. kubesphere/elasticsearch-oss:6.7.0-1
  106. kubesphere/fluentbit-operator:v0.11.0
  107. docker:19.03
  108. kubesphere/fluent-bit:v1.8.3
  109. kubesphere/log-sidecar-injector:1.1
  110. elastic/filebeat:6.7.0
  111. kubesphere/kube-events-operator:v0.3.0
  112. kubesphere/kube-events-exporter:v0.3.0
  113. kubesphere/kube-events-ruler:v0.3.0
  114. kubesphere/kube-auditing-operator:v0.2.0
  115. kubesphere/kube-auditing-webhook:v0.2.0
  116. ##istio-images
  117. istio/pilot:1.11.1
  118. istio/proxyv2:1.11.1
  119. jaegertracing/jaeger-operator:1.27
  120. jaegertracing/jaeger-agent:1.27
  121. jaegertracing/jaeger-collector:1.27
  122. jaegertracing/jaeger-query:1.27
  123. jaegertracing/jaeger-es-index-cleaner:1.27
  124. kubesphere/kiali-operator:v1.38.1
  125. kubesphere/kiali:v1.38
  126. ##example-images
  127. busybox:1.31.1
  128. nginx:1.14-alpine
  129. joosthofman/wget:1.0
  130. nginxdemos/hello:plain-text
  131. wordpress:4.8-apache
  132. mirrorgooglecontainers/hpa-example:latest
  133. java:openjdk-8-jre-alpine
  134. fluent/fluentd:v1.4.2-2.0
  135. perl:latest
  136. kubesphere/examples-bookinfo-productpage-v1:1.16.2
  137. kubesphere/examples-bookinfo-reviews-v1:1.16.2
  138. kubesphere/examples-bookinfo-reviews-v2:1.16.2
  139. kubesphere/examples-bookinfo-details-v1:1.16.2
  140. kubesphere/examples-bookinfo-ratings-v1:1.16.3
  141. ##weave-scope-images
  142. weaveworks/scope:1.13.0