k8s安装KubeSphere

参考资料:https://v2-1.docs.kubesphere.io/docs/zh-CN/introduction/what-is-kubesphere/

安装前置环境

  1. 安装helm 和 tiller
    1. helm介绍
      helm是kubernetes的包管理器。包管理器类似于Ubuntu中的apt、Centos中的yum,能快速查找、下载和安装软件包。helm由客户端组件helm和服务端组件tiller组成,能够将一组k8s资源打包统一管理,是查找,共享和使用Kubernetes构建软件的最佳方式。

    2. 执行get_helm.sh脚本,安装helm

      #!/usr/bin/env bash
      
      # Copyright The Helm 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.
      
      # The install script is based off of the MIT-licensed script from glide,
      # the package manager for Go: https://github.com/Masterminds/glide.sh/blob/master/get
      
      PROJECT_NAME="helm"
      TILLER_NAME="tiller"
      
      : ${USE_SUDO:="true"}
      : ${HELM_INSTALL_DIR:="/usr/local/bin"}
      
      # initArch discovers the architecture for this system.
      initArch() {
        ARCH=$(uname -m)
        case $ARCH in
          armv5*) ARCH="armv5";;
          armv6*) ARCH="armv6";;
          armv7*) ARCH="arm";;
          aarch64) ARCH="arm64";;
          x86) ARCH="386";;
          x86_64) ARCH="amd64";;
          i686) ARCH="386";;
          i386) ARCH="386";;
        esac
      }
      
      # initOS discovers the operating system for this system.
      initOS() {
        OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
      
        case "$OS" in
          # Minimalist GNU for Windows
          mingw*) OS='windows';;
        esac
      }
      
      # runs the given command as root (detects if we are root already)
      runAsRoot() {
        local CMD="$*"
      
        if [ $EUID -ne 0 -a $USE_SUDO = "true" ]; then
          CMD="sudo $CMD"
        fi
      
        $CMD
      }
      
      # verifySupported checks that the os/arch combination is supported for
      # binary builds.
      verifySupported() {
        local supported="darwin-386\ndarwin-amd64\nlinux-386\nlinux-amd64\nlinux-arm\nlinux-arm64\nlinux-ppc64le\nwindows-386\nwindows-amd64"
        if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
          echo "No prebuilt binary for ${OS}-${ARCH}."
          echo "To build from source, go to https://github.com/helm/helm"
          exit 1
        fi
      
        if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then
          echo "Either curl or wget is required"
          exit 1
        fi
      }
      
      # checkDesiredVersion checks if the desired version is available.
      checkDesiredVersion() {
        if [ "x$DESIRED_VERSION" == "x" ]; then
          # Get tag from release URL
          local release_url="https://github.com/helm/helm/releases"
          if type "curl" > /dev/null; then
      
            TAG=$(curl -Ls $release_url | grep 'href="/helm/helm/releases/tag/v2.' | grep -v no-underline | head -n 1 | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}')
          elif type "wget" > /dev/null; then
            TAG=$(wget $release_url -O - 2>&1 | grep 'href="/helm/helm/releases/tag/v2.' | grep -v no-underline | head -n 1 | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}')
          fi
        else
          TAG=$DESIRED_VERSION
        fi
      }
      
      # checkHelmInstalledVersion checks which version of helm is installed and
      # if it needs to be changed.
      checkHelmInstalledVersion() {
        if [[ -f "${HELM_INSTALL_DIR}/${PROJECT_NAME}" ]]; then
          local version=$("${HELM_INSTALL_DIR}/${PROJECT_NAME}" version -c | grep '^Client' | cut -d'"' -f2)
          if [[ "$version" == "$TAG" ]]; then
            echo "Helm ${version} is already ${DESIRED_VERSION:-latest}"
            return 0
          else
            echo "Helm ${TAG} is available. Changing from version ${version}."
            return 1
          fi
        else
          return 1
        fi
      }
      
      # downloadFile downloads the latest binary package and also the checksum
      # for that binary.
      downloadFile() {
        # HELM_DIST="helm-$TAG-$OS-$ARCH.tar.gz"
        HELM_DIST="helm-v2.16.3-linux-amd64.tar.gz"
        DOWNLOAD_URL="https://get.helm.sh/$HELM_DIST"
        CHECKSUM_URL="$DOWNLOAD_URL.sha256"
        HELM_TMP_ROOT="$(mktemp -dt helm-installer-XXXXXX)"
        HELM_TMP_FILE="$HELM_TMP_ROOT/$HELM_DIST"
        HELM_SUM_FILE="$HELM_TMP_ROOT/$HELM_DIST.sha256"
        echo "Downloading $DOWNLOAD_URL"
        if type "curl" > /dev/null; then
          curl -SsL "$CHECKSUM_URL" -o "$HELM_SUM_FILE"
        elif type "wget" > /dev/null; then
          wget -q -O "$HELM_SUM_FILE" "$CHECKSUM_URL"
        fi
        if type "curl" > /dev/null; then
          curl -SsL "$DOWNLOAD_URL" -o "$HELM_TMP_FILE"
        elif type "wget" > /dev/null; then
          wget -q -O "$HELM_TMP_FILE" "$DOWNLOAD_URL"
        fi
      }
      
      # installFile verifies the SHA256 for the file, then unpacks and
      # installs it.
      installFile() {
        HELM_TMP="$HELM_TMP_ROOT/$PROJECT_NAME"
        local sum=$(openssl sha1 -sha256 ${HELM_TMP_FILE} | awk '{print $2}')
        local expected_sum=$(cat ${HELM_SUM_FILE})
        if [ "$sum" != "$expected_sum" ]; then
          echo "SHA sum of ${HELM_TMP_FILE} does not match. Aborting."
          exit 1
        fi
      
        mkdir -p "$HELM_TMP"
        tar xf "$HELM_TMP_FILE" -C "$HELM_TMP"
        HELM_TMP_BIN="$HELM_TMP/$OS-$ARCH/$PROJECT_NAME"
        TILLER_TMP_BIN="$HELM_TMP/$OS-$ARCH/$TILLER_NAME"
        echo "Preparing to install $PROJECT_NAME and $TILLER_NAME into ${HELM_INSTALL_DIR}"
        runAsRoot cp "$HELM_TMP_BIN" "$HELM_INSTALL_DIR"
        echo "$PROJECT_NAME installed into $HELM_INSTALL_DIR/$PROJECT_NAME"
        if [ -x "$TILLER_TMP_BIN" ]; then
          runAsRoot cp "$TILLER_TMP_BIN" "$HELM_INSTALL_DIR"
          echo "$TILLER_NAME installed into $HELM_INSTALL_DIR/$TILLER_NAME"
        else
          echo "info: $TILLER_NAME binary was not found in this release; skipping $TILLER_NAME installation"
        fi
      }
      
      # fail_trap is executed if an error occurs.
      fail_trap() {
        result=$?
        if [ "$result" != "0" ]; then
          if [[ -n "$INPUT_ARGUMENTS" ]]; then
            echo "Failed to install $PROJECT_NAME with the arguments provided: $INPUT_ARGUMENTS"
            help
          else
            echo "Failed to install $PROJECT_NAME"
          fi
          echo -e "\tFor support, go to https://github.com/helm/helm."
        fi
        cleanup
        exit $result
      }
      
      # testVersion tests the installed client to make sure it is working.
      testVersion() {
        set +e
        HELM="$(which $PROJECT_NAME)"
        if [ "$?" = "1" ]; then
          echo "$PROJECT_NAME not found. Is $HELM_INSTALL_DIR on your "'$PATH?'
          exit 1
        fi
        set -e
        echo "Run '$PROJECT_NAME init' to configure $PROJECT_NAME."
      }
      
      # help provides possible cli installation arguments
      help () {
        echo "Accepted cli arguments are:"
        echo -e "\t[--help|-h ] ->> prints this help"
        echo -e "\t[--version|-v <desired_version>]"
        echo -e "\te.g. --version v2.4.0  or -v latest"
        echo -e "\t[--no-sudo]  ->> install without sudo"
      }
      
      # cleanup temporary files to avoid https://github.com/helm/helm/issues/2977
      cleanup() {
        if [[ -d "${HELM_TMP_ROOT:-}" ]]; then
          rm -rf "$HELM_TMP_ROOT"
        fi
      }
      
      # Execution
      
      #Stop execution on any error
      trap "fail_trap" EXIT
      set -e
      
      # Parsing input arguments (if any)
      export INPUT_ARGUMENTS="${@}"
      set -u
      while [[ $# -gt 0 ]]; do
        case $1 in
          '--version'|-v)
             shift
             if [[ $# -ne 0 ]]; then
                 export DESIRED_VERSION="${1}"
             else
                 echo -e "Please provide the desired version. e.g. --version v2.4.0 or -v latest"
                 exit 0
             fi
             ;;
          '--no-sudo')
             USE_SUDO="false"
             ;;
          '--help'|-h)
             help
             exit 0
             ;;
          *) exit 1
             ;;
        esac
        shift
      done
      set +u
      
      initArch
      initOS
      verifySupported
      checkDesiredVersion
      if ! checkHelmInstalledVersion; then
        downloadFile
        installFile
      fi
      testVersion
      cleanup
      
    3. 执行helm-rbac.yaml在master节点创建权限

      kubectl apply -f helm-rbac.yaml
      

      helm-rbac.yaml:

      apiVersion: v1
      kind: ServiceAccount
      metadata:
      name: tiller
      namespace: kube-system
      ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRoleBinding
      metadata:
      name: tiller
      roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
      subjects:
      - kind: ServiceAccount
      name: tiller
      namespace: kube-system
      
    4. 安装tiller

      # 不指定镜像地址安装tiller 
      helm init --service-account=tiller --tiller-image=sapcc/tiller:v2.16.3 --history-max 300
      # 指定镜像下载地址安装tiller
      helm init --service-account=tiller --stable-repo-url=https://charts.helm.sh/stable --tiller-image=sapcc/tiller:v2.16.3
      
  2. 安装OpenEBS
    1. 确定集群中存在master节点
      kubectl get node -o wide
      
      在这里插入图片描述
    2. 确认节点是否有Taint
      kubectl describe node k8s-node1 |grep Taint # master节点的名字是k8s-node1
      
      在这里插入图片描述
    3. 去掉master节点的Taint
      kubectl taint nodes k8s-node1 node-role.kubernetes.io/master:NoSchedule-
      
    4. 安装OpenEBS
      1. 创建OpenEBS的namespace,OpenEBS相关资源将创建在这个namespace下:

        kubectl create ns openebs
        
      2. 若集群安装了Helm,可通过Helm命令来安装OpenEBS:

        helm install --namespace openebs --name openebs stable/openebs --version 1.5.0
        
      3. 安装OpenEBS后将自动创建4个StorageClass,可以用如下命令查看:

        kubectl get sc
        

        在这里插入图片描述

      4. 将openebs-hostpath设置为默认的StorageClass:

        kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class":"true"}}}'
        
      5. 将去掉的Taint添加回去:

        kubectl taint nodes k8s-node1 node-role.kubernetes.io=master:NoSchedule-
        

最小化安装kubesphere

  1. 使用kubesphere-minimal.yaml安装kubesphere
    kubeclt apply -f kubesphere-minimal.yaml
    
    kubersphere-minimal.yaml文件:
    ---
    apiVersion: v1
    kind: Namespace
    metadata:
      name: kubesphere-system
    
    ---
    apiVersion: v1
    data:
      ks-config.yaml: |
        ---
    
        persistence:
          storageClass: ""
    
        etcd:
          monitoring: False
          endpointIps: 192.168.0.7,192.168.0.8,192.168.0.9
          port: 2379
          tlsEnable: True
    
        common:
          mysqlVolumeSize: 20Gi
          minioVolumeSize: 20Gi
          etcdVolumeSize: 20Gi
          openldapVolumeSize: 2Gi
          redisVolumSize: 2Gi
    
        metrics_server:
          enabled: False
    
        console:
          enableMultiLogin: False  # enable/disable multi login
          port: 30880
    
        monitoring:
          prometheusReplicas: 1
          prometheusMemoryRequest: 400Mi
          prometheusVolumeSize: 20Gi
          grafana:
            enabled: False
    
        logging:
          enabled: False
          elasticsearchMasterReplicas: 1
          elasticsearchDataReplicas: 1
          logsidecarReplicas: 2
          elasticsearchMasterVolumeSize: 4Gi
          elasticsearchDataVolumeSize: 20Gi
          logMaxAge: 7
          elkPrefix: logstash
          containersLogMountedPath: ""
          kibana:
            enabled: False
    
        openpitrix:
          enabled: False
    
        devops:
          enabled: False
          jenkinsMemoryLim: 2Gi
          jenkinsMemoryReq: 1500Mi
          jenkinsVolumeSize: 8Gi
          jenkinsJavaOpts_Xms: 512m
          jenkinsJavaOpts_Xmx: 512m
          jenkinsJavaOpts_MaxRAM: 2g
          sonarqube:
            enabled: False
            postgresqlVolumeSize: 8Gi
    
        servicemesh:
          enabled: False
    
        notification:
          enabled: False
    
        alerting:
          enabled: False
    
    kind: ConfigMap
    metadata:
      name: ks-installer
      namespace: kubesphere-system
    
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: ks-installer
      namespace: kubesphere-system
    
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      creationTimestamp: null
      name: ks-installer
    rules:
    - apiGroups:
      - ""
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - apps
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - extensions
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - batch
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - rbac.authorization.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - apiregistration.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - apiextensions.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - tenant.kubesphere.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - certificates.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - devops.kubesphere.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - monitoring.coreos.com
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - logging.kubesphere.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - jaegertracing.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - storage.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - admissionregistration.k8s.io
      resources:
      - '*'
      verbs:
      - '*'
    
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: ks-installer
    subjects:
    - kind: ServiceAccount
      name: ks-installer
      namespace: kubesphere-system
    roleRef:
      kind: ClusterRole
      name: ks-installer
      apiGroup: rbac.authorization.k8s.io
    
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ks-installer
      namespace: kubesphere-system
      labels:
        app: ks-install
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ks-install
      template:
        metadata:
          labels:
            app: ks-install
        spec:
          serviceAccountName: ks-installer
          containers:
          - name: installer
            image: kubesphere/ks-installer:v2.1.1
            imagePullPolicy: "Always"
    
  2. 安装完成后,会提供web页面访问的用户名密码,默认:
    Console: http://ip:30880
    Account: admin
    Password: P@88w0rd
    

定制化安装kubesphere【可插拔组件的安装方式】

  1. 默认最小化安装的kubesphere-minimal.yaml配置文件中,已经配置了所有组件。默认配置选项是false的组件,不会安装。
  2. 修改文件,将需要安装的组件,enabled值改为True, 保存退出后,自动安装:
    kubectl edit cm -n kubesphere-system ks-installer
    
  3. 这次安装开启了devops组件、notification组件,alerting组件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值