使用kubeKey安装kubeSphere

本文档介绍了如何使用kubeKey工具来安装kubeSphere集群。首先,通过编辑脚本设置代理URL下载kubeKey。接着,手动下载cni插件和nfs配置文件。然后,配置集群和组件的详细信息,包括主机地址、用户密码、网络插件、存储类等。最后,使用kubeKey创建配置文件并部署k8s集群。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用kubeKey安装kubeSphere

使用kubeKey安装kubeSphere。如果你和作者一样在部署时下载遇到了约束可用参考该文章,该文档主要使用代理方案将包给提前下载了有些脚本更改了代理路径,希望对您有所帮助!

下载安装工具kubeKey

下载脚本

wget https://get-kk.kubesphere.io

编辑脚本替换成代理URL

#!/bin/sh

# Copyright 2020 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.

ISLINUX=true
OSTYPE="linux"

if [ "x$(uname)" != "xLinux" ]; then
  echo ""
  echo 'Warning: Non-Linux operating systems are not supported! After downloading, please copy the tar.gz file to linux.'  
  ISLINUX=false
fi

# Fetch latest version
if [ "x${VERSION}" = "x" ]; then
  VERSION="$(curl -sL https://ghproxy.com/https://api.github.com/repos/kubesphere/kubekey/releases |
    grep -o 'download/v[0-9]*.[0-9]*.[0-9]*/' |
    sort --version-sort |
    tail -1 | awk -F'/' '{ print $2}')"
  VERSION="${VERSION##*/}"
fi

if [ -z "${ARCH}" ]; then
  case "$(uname -m)" in
  x86_64)
    ARCH=amd64
    ;;
  armv8*)
    ARCH=arm64
    ;;
  aarch64*)
    ARCH=arm64
    ;;
  *)
    echo "${ARCH}, isn't supported"
    exit 1
    ;;
  esac
fi

if [ "x${VERSION}" = "x" ]; then
  echo "Unable to get latest Kubekey version. Set VERSION env var and re-run. For example: export VERSION=v1.0.0"
  echo ""
  exit
fi

DOWNLOAD_URL="https://ghproxy.com/https://github.com/kubesphere/kubekey/releases/download/${VERSION}/kubekey-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
if [ "x${KKZONE}" = "xcn" ]; then
  DOWNLOAD_URL="https://ghproxy.com/https://kubernetes.pek3b.qingstor.com/kubekey/releases/download/${VERSION}/kubekey-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
fi

echo ""
echo "Downloading kubekey ${VERSION} from ${DOWNLOAD_URL} ..."
echo ""

curl -fsLO "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then
  echo ""
  echo "Failed to download Kubekey ${VERSION} !"
  echo ""
  echo "Please verify the version you are trying to download."
  echo ""
  exit
fi

if [ ${ISLINUX} = true ]; then
  filename="kubekey-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
  ret='0'
  command -v tar >/dev/null 2>&1 || { ret='1'; }
  if [ "$ret" -eq 0 ]; then
    tar -xzf "${filename}"
  else
    echo "Kubekey ${VERSION} Download Complete!"
    echo ""
    echo "Try to unpack the ${filename} failed."
    echo "tar: command not found, please unpack the ${filename} manually."
    exit
  fi
fi

echo ""
echo "Kubekey ${VERSION} Download Complete!"
echo ""

执行脚本

export VERSION=v1.1.1 & sh downloadKubekey.sh

使用kk安装k8s集群

./kk create config --with-kubernetes v1.20.4 --with-kubesphere v3.1.1
  • 手动下载
curl -L -o /opt/share/k8s/kubekey/kubekey/v1.20.4/amd64/cni-plugins-linux-amd64-v0.8.6.tgz https://ghproxy.com/https://github.com/containernetworking/plugins/releases/download/v0.8.6/cni-plugins-linux-amd64-v0.8.6.tgz
  • 手动下载nfs 配置类文件
 curl -L -o addons.md https://ghproxy.com/https://raw.githubusercontent.com/kubesphere/kubekey/master/docs/addons.md
  • 配置一下addons
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: k8smaster, address: 192.168.122.110, internalAddress: 192.168.122.110, user: root, password:yourServerPassword}
  - {name: k8snode1, address: 192.168.122.111, internalAddress: 192.168.122.111, user: root, password: yourServerPassword}
  - {name: k8snode2, address: 192.168.122.112, internalAddress: 192.168.122.112, user: root, password: yourServerPassword}
  roleGroups:
    etcd:
    - k8smaster
    master:
    - k8smaster
    worker:
    - k8snode1
    - k8snode2
  controlPlaneEndpoint:
    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.20.4
    imageRepo: kubesphere
    clusterName: cluster.local
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
  registry:
    registryMirrors: []
    insecureRegistries: []
  addons:
  - name: nfs-client
    namespace: kube-system
    sources:
      chart:
        name: nfs-client-provisioner
        repo: https://charts.kubesphere.io/main
        valuesFile: custom-nfs-client-values.yaml  # or https://raw.githubusercontent.com/kubesphere/helm-charts/master/src/main/nfs-client-provisioner/values.yaml
        # values also supports parameter lists
        values:
        - storageClass.defaultClass=true
        - nfs.server=192.168.122.1
        - nfs.path=/home/nfs/k8s

---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
  name: ks-installer
  namespace: kubesphere-system
  labels:
    version: v3.1.1
spec:
  persistence:
    storageClass: ""
  authentication:
    jwtSecret: ""
  zone: ""
  local_registry: ""
  etcd:
    monitoring: true
    endpointIps: localhost
    port: 2379
    tlsEnable: true
  common:
    redis:
      enabled: true
    redisVolumSize: 2Gi
    openldap:
      enabled: true
    openldapVolumeSize: 2Gi
    minioVolumeSize: 20Gi
    monitoring:
      endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
    es:
      elasticsearchMasterVolumeSize: 4Gi
      elasticsearchDataVolumeSize: 20Gi
      logMaxAge: 7
      elkPrefix: logstash
      basicAuth:
        enabled: false
        username: ""
        password: ""
      externalElasticsearchUrl: ""
      externalElasticsearchPort: ""
  console:
    enableMultiLogin: true
    port: 30880
  alerting:
    enabled: true
    # thanosruler:
    #   replicas: 1
    #   resources: {}
  auditing:
    enabled: true
  devops:
    enabled: true
    jenkinsMemoryLim: 2Gi
    jenkinsMemoryReq: 1500Mi
    jenkinsVolumeSize: 8Gi
    jenkinsJavaOpts_Xms: 512m
    jenkinsJavaOpts_Xmx: 512m
    jenkinsJavaOpts_MaxRAM: 2g
  events:
    enabled: true
    ruler:
      enabled: true
      replicas: 2
  logging:
    enabled: true
    logsidecar:
      enabled: true
      replicas: 2
  metrics_server:
    enabled: true
  monitoring:
    storageClass: ""
    prometheusMemoryRequest: 400Mi
    prometheusVolumeSize: 20Gi
  multicluster:
    clusterRole: host
  network:
    networkpolicy:
      enabled: true
    ippool:
      type: none
    topology:
      type: none
  openpitrix:
    store:
      enabled: true
  servicemesh:
    enabled: true
  kubeedge:
    enabled: true
    cloudCore:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      cloudhubPort: "10000"
      cloudhubQuicPort: "10001"
      cloudhubHttpsPort: "10002"
      cloudstreamPort: "10003"
      tunnelPort: "10004"
      cloudHub:
        advertiseAddress:
          - ""
        nodeLimit: "100"
      service:
        cloudhubNodePort: "30000"
        cloudhubQuicNodePort: "30001"
        cloudhubHttpsNodePort: "30002"
        cloudstreamNodePort: "30003"
        tunnelNodePort: "30004"
    edgeWatcher:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      edgeWatcherAgent:
        nodeSelector: {"node-role.kubernetes.io/worker": ""}
        tolerations: []

  • 部署k8s集群
./kk create cluster -f config-sample.yaml
在离线环境下使用 KubeKey 安装 KubeSphere 4.1 需要进行一系列的准备工作,包括镜像下载、配置文件修改以及安装步骤的执行。以下是详细的步骤说明: ### 环境准备 1. **获取 KubeKey** 下载适用于离线环境的 KubeKey 工具包,并将其解压到离线环境中。 2. **准备依赖镜像** 在有网络连接的环境中,使用 `docker` 或其他容器工具拉取 KubeSphere 和 Kubernetes 所需的所有镜像,并将这些镜像导出为 `.tar` 文件。例如: ```bash docker pull kubesphere/ks-installer:v3.0.0 docker save -o ks-installer-v3.0.0.tar kubesphere/ks-installer:v3.0.0 ``` 3. **导入镜像到离线环境** 将导出的镜像文件传输到离线环境中,并使用 `docker load` 命令导入这些镜像: ```bash docker load -i ks-installer-v3.0.0.tar ``` 4. **标签镜像** 为了确保镜像能够在离线环境中正确使用,需要对镜像进行重新打标签。例如: ```bash docker tag kubesphere/ks-installer:v3.0.0 registry.local/ks-installer:v3.0.0 ``` 5. **推送镜像到私有仓库** 将重新打标签的镜像推送到离线环境中的私有仓库: ```bash docker push registry.local/ks-installer:v3.0.0 ``` ### 配置 KubeKey 1. **生成配置文件** 使用 KubeKey 生成配置文件,指定 Kubernetes 和 KubeSphere 的版本,以及私有仓库地址: ```bash ./kubekey create config --with-kubernetes v1.22.12 --with-kubesphere v3.0.0 ``` 2. **编辑配置文件** 修改生成的 `config-sample.yaml` 文件,添加私有仓库地址和其他必要的配置项。例如: ```yaml privateRegistry: "registry.local" ``` ### 安装 KubeSphere 1. **初始化集群** 使用 KubeKey 初始化 Kubernetes 集群并安装 KubeSphere: ```bash ./kubekey apply cluster --config config-sample.yaml ``` 2. **检查安装状态** 查看 KubeSphere 安装日志以确认安装进度和状态: ```bash kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f ``` 3. **验证安装** 安装完成后,使用以下命令验证 KubeSphere 组件的状态: ```bash kubectl get pods -n kubesphere-system ``` ### 注意事项 - 确保所有节点的时间同步,可以使用 NTP 服务来实现。 - 确保所有节点之间的网络互通,特别是 Kubernetes 和 KubeSphere 所需的服务端口。 - 在离线环境中,确保私有仓库的访问权限正确配置,避免因权限问题导致镜像拉取失败。 通过以上步骤,可以在离线环境中成功使用 KubeKey 安装 KubeSphere 4.1。如果遇到任何问题,可以通过查看日志文件和 Kubernetes 事件来排查故障[^1]。 ```python # 示例代码:检查KubeSphere安装日志 import subprocess def check_kubesphere_logs(): command = "kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f" process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() if error: print(f"Error: {error.decode('utf-8')}") else: print(output.decode('utf-8')) check_kubesphere_logs() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值