github.com/gocrane/crane@v0.11.0/docs/installation.zh.md (about)

     1  # 产品部署指南
     2  
     3  为了让您更快的部署 Crane ,本文档提供清晰的:
     4  
     5  * 部署环境要求
     6  * 具体安装步骤
     7  
     8  Crane 安装时间在10分钟左右,具体时间也依赖集群规模以及硬件能力。目前安装已经非常成熟,如果您安装中遇到任何问题,可以采取如下几种方式:
     9  
    10  * 请首先检查后文的 F&Q
    11  * 可以提出一个 [Issue](https://github.com/gocrane/crane/issues/new?assignees=&labels=kind%2Fbug&template=bug_report.md&title=),我们会认真对待每一个 [Issue](https://github.com/gocrane/crane/issues)
    12  
    13  ## 部署环境要求
    14  
    15  - Kubernetes 1.18+
    16  - Helm 3.1.0
    17  
    18  ## 安装流程
    19  
    20  ### 安装 Helm
    21  
    22  建议参考 Helm 官网[安装文档](https://helm.sh/docs/intro/install/)。
    23  
    24  ### 安装 Prometheus 和 Grafana
    25  
    26  使用 Helm 安装 Prometheus 和 Grafana。
    27  
    28  !!! Note "注意" 
    29      如果您已经在环境中部署了 Prometheus 和 Grafana,可以跳过该步骤。
    30  
    31  !!! Warning "网络问题"
    32      如果你的网络无法访问GitHub资源(GitHub Release, GitHub Raw Content `raw.githubusercontent.com`)。
    33      
    34      那么你可以尝试镜像仓库。但镜像仓库具有一定的**时延**。[镜像仓库](mirror.zh.md)
    35  
    36  
    37  Crane 使用 Prometheus 抓取集群工作负载对资源的使用情况。安装 Prometheus:
    38  
    39  === "Main"
    40  
    41      ```bash
    42      helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    43      helm install prometheus -n crane-system \
    44                              --set pushgateway.enabled=false \
    45                              --set alertmanager.enabled=false \
    46                              --set server.persistentVolume.enabled=false \
    47                              -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/prometheus/override_values.yaml \
    48                              --create-namespace  prometheus-community/prometheus
    49      ```
    50  
    51  === "Mirror"
    52  
    53      ```bash
    54      helm repo add prometheus-community https://finops-helm.pkg.coding.net/gocrane/prometheus-community
    55      helm install prometheus -n crane-system \
    56                              --set pushgateway.enabled=false \
    57                              --set alertmanager.enabled=false \
    58                              --set server.persistentVolume.enabled=false \
    59                              -f https://gitee.com/finops/helm-charts/raw/main/integration/prometheus/override_values.yaml \
    60                              --create-namespace  prometheus-community/prometheus
    61      ```
    62  
    63  
    64  Crane 的 Fadvisor 使用 Grafana 展示成本预估。安装 Grafana:
    65  
    66  === "Main"
    67  
    68      ```bash
    69      helm repo add grafana https://grafana.github.io/helm-charts
    70      helm install grafana \
    71                   -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/grafana/override_values.yaml \
    72                   -n crane-system \
    73                   --create-namespace grafana/grafana
    74      ```
    75  
    76  === "Mirror"
    77  
    78      ```bash
    79      helm repo add grafana https://finops-helm.pkg.coding.net/gocrane/grafana
    80      helm install grafana \
    81                   -f https://gitee.com/finops/helm-charts/raw/main/integration/grafana/override_values.yaml \
    82                   -n crane-system \
    83                   --create-namespace grafana/grafana
    84      ```
    85  
    86  ### 安装 Crane 和 Fadvisor
    87  
    88  === "Main"
    89  
    90      ```bash
    91      helm repo add crane https://gocrane.github.io/helm-charts
    92      helm install crane -n crane-system --create-namespace crane/crane
    93      helm install fadvisor -n crane-system --create-namespace crane/fadvisor
    94      ```
    95  
    96  === "Mirror"
    97  
    98      ```bash
    99      helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
   100      helm install crane -n crane-system --create-namespace crane/crane
   101      helm install fadvisor -n crane-system --create-namespace crane/fadvisor
   102      ```
   103  
   104  ### 安装 Crane-scheduler(可选)
   105  ```console
   106  helm install scheduler -n crane-system --create-namespace crane/scheduler
   107  ```
   108  
   109  ## 验证安装是否成功
   110  
   111  使用如下命令检查安装的 Deployment 是否正常:
   112  
   113  ```console
   114  kubectl get deploy -n crane-system
   115  ```
   116  
   117  结果类似如下:
   118  
   119  ```shell
   120  NAME                            READY   UP-TO-DATE   AVAILABLE   AGE
   121  craned                          1/1     1            1           31m
   122  fadvisor                        1/1     1            1           41m
   123  grafana                         1/1     1            1           42m
   124  metric-adapter                  1/1     1            1           31m
   125  prometheus-kube-state-metrics   1/1     1            1           43m
   126  prometheus-server               1/1     1            1           43m
   127  ```
   128  
   129  可以查看本篇[文档](https://github.com/gocrane/helm-charts/blob/main/charts/crane/README.md)获取更多有关 Crane Helm Chart 的信息。
   130  
   131  ## Access Dashboard
   132  
   133  You can use the dashboard to view and manage crane manifests.
   134  
   135  ![](images/dashboard.png)
   136  
   137  ### Port Forward
   138  
   139  Easy access to the dashboard through `kubectl port-forward`.
   140  
   141  ```bash
   142  kubectl -n crane-system port-forward service/craned 9090:9090 
   143  ```
   144  
   145  ### NodePort
   146  
   147  ```bash
   148  # Change service type
   149  kubectl patch svc craned -n crane-system -p '{"spec": {"type": "NodePort"}}'
   150  ```
   151  
   152  ```bash
   153  # Get Dashboard link base on your cluster configuration
   154  PORT=$(kubectl get svc -n crane-system craned -o jsonpath='{.spec.ports[?(@.name == "dashboard-service")].nodePort}')
   155  NODE_IP=$(kubectl get node -ojsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}')
   156  echo "Dashboard link: http://${NODE_IP}:${PORT}"
   157  ```
   158  
   159  ### LoadBalancer
   160  
   161  
   162  #### Quick Start
   163  
   164  ```bash
   165  # Change service type
   166  kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'
   167  ```
   168  
   169  #### Example
   170  
   171  ```log
   172  $ kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'
   173  
   174  service/craned patched
   175  
   176  $ kubectl get svc -n crane-system craned
   177  NAME     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                      AGE
   178  craned   LoadBalancer   10.101.123.74   10.200.0.4    443:30908/TCP,8082:32426/TCP,9090:31331/TCP,8080:31072/TCP   57m
   179  
   180  # Access dashboard via 10.200.0.4:9090
   181  ```
   182  
   183  ### Ingress
   184  
   185  #### kubernetes/ingress-nginx
   186  
   187  If the cluster version is < 1.19, you can create the ingress resources like this:
   188  
   189  ```yaml
   190  apiVersion: networking.k8s.io/v1beta1
   191  kind: Ingress
   192  metadata:
   193    name: ingress-crane-dashboard
   194    namespace: crane-system
   195  spec:
   196    ingressClassName: nginx
   197    rules:
   198    - host: dashboard.gocrane.io # change to your domain
   199      http:
   200        paths:
   201        - path: /
   202          backend:
   203            serviceName: craned
   204            servicePort: 9090
   205  ```
   206  
   207  If the cluster uses Kubernetes version >= 1.19.x, then its suggested to create the second ingress resources, using yaml examples shown below.
   208  
   209  These examples are in conformity with the `networking.kubernetes.io/v1` api.
   210  
   211  ```yaml
   212  apiVersion: networking.k8s.io/v1
   213  kind: Ingress
   214  metadata:
   215    name: ingress-crane-dashboard
   216    namespace: crane-system
   217  spec:
   218    rules:
   219    - host: dashboard.gocrane.io # change to your domain
   220      http:
   221        paths:
   222        - path: /
   223          pathType: Prefix
   224          backend:
   225            service:
   226              name: craned
   227              port:
   228                number: 9090
   229    ingressClassName: nginx
   230  ```
   231  
   232  Example:
   233  
   234  ```log
   235  $ kubectl get svc -n ingress-nginx 
   236  NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
   237  ingress-nginx-controller             LoadBalancer   10.102.235.229   10.200.0.5    80:32568/TCP,443:30144/TCP   91m
   238  ingress-nginx-controller-admission   ClusterIP      10.102.49.240    <none>        443/TCP                      91m
   239  
   240  $ curl -H "Host: dashboard.gocrane.io" 10.200.0.5
   241  <!DOCTYPE html>
   242  <html lang="en">
   243    <head>
   244      <meta charset="UTF-8" />
   245      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   246      <title>Crane Dashboard</title>
   247      ................................................................
   248  ```
   249  
   250  #### Traefik
   251  
   252  ```yaml
   253  apiVersion: traefik.containo.us/v1alpha1
   254  kind: IngressRoute
   255  metadata:
   256    name: dashboard-crane-ingress
   257    namespace: crane-system
   258  spec:
   259    entryPoints:
   260      - web
   261    routes:
   262      - kind: Rule
   263        match: Host(`dashboard.gocrane.io`)
   264        services:
   265          - name: craned
   266            port: 9090
   267  ```
   268  
   269  ```log
   270  $ kubectl get svc -n traefik-v2                     
   271  NAME      TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
   272  traefik   LoadBalancer   10.107.109.44   10.200.0.6    80:30102/TCP,443:30139/TCP   16m
   273  
   274  $ curl -H "Host: dashboard.gocrane.io" 10.200.0.6 
   275  <!DOCTYPE html>
   276  <html lang="en">
   277    <head>
   278      <meta charset="UTF-8" />
   279      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   280      <title>Crane Dashboard</title>
   281      ................................................................
   282  ```
   283  
   284  ## 自定义安装
   285  
   286  通过 YAML 安装 `Crane` 。
   287  
   288  === "Main"
   289  
   290      ```bash
   291      git clone https://github.com/gocrane/crane.git
   292      CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
   293      git checkout $CRANE_LATEST_VERSION
   294      kubectl apply -f deploy/manifests 
   295      kubectl apply -f deploy/craned 
   296      kubectl apply -f deploy/metric-adapter
   297      ```
   298  
   299  === "Mirror"
   300  
   301      ```bash
   302      git clone https://e.coding.net/finops/gocrane/crane.git
   303      CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
   304      git checkout $CRANE_LATEST_VERSION
   305      kubectl apply -f deploy/manifests
   306      kubectl apply -f deploy/craned
   307      kubectl apply -f deploy/metric-adapter
   308      ```
   309  
   310  如果您想自定义 Crane 里配置 Prometheus 的 HTTP 地址,请参考以下的命令。如果您在集群里已存在一个 Prometheus,请将 Server 地址填于`CUSTOMIZE_PROMETHEUS` 。
   311  
   312  ```console
   313  export CUSTOMIZE_PROMETHEUS=
   314  if [ $CUSTOMIZE_PROMETHEUS ]; then sed -i '' "s/http:\/\/prometheus-server.crane-system.svc.cluster.local:8080/${CUSTOMIZE_PROMETHEUS}/" deploy/craned/deployment.yaml ; fi
   315  ```
   316  
   317  ## 安装常见问题
   318  
   319  ### 安装 Crane 报错
   320  
   321  当您执行 `helm install crane -n crane-system --create-namespace crane/crane` 命令时,可能会遇到如下错误:
   322  
   323  ```shell
   324  Error: rendered manifests contain a resource that already exists. Unable to continue with install: APIService "v1beta1.custom.metrics.k8s.io" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "crane"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "crane-system"
   325  ```
   326  
   327  原因:集群安装过 custom metric 的 APIService,所以报错。可以把之前的删除再重新执行安装 Crane 的命令,删除方式:`kubectl delete apiservice v1beta1.custom.metrics.k8s.io`。
   328  
   329  ### 获取 Crane URL 的其它方式
   330  
   331  #### NodePort 方式
   332  
   333  您可以将 Crane 的 Service 的类型换成 NodePort 类型,这样可以直接通过集群任意节点 IP + 该服务里dashboard- service 端口号的方式,打开控制台。
   334  
   335  具体操作:修改 crane-system 命名空间下名为 craned 的 Service,将其访问方式该为 NodePort 的方式,然后获取某一集群的节点 IP,以及相应的端口号,端口号如下所示:
   336  
   337  ![](images/dashboard_nodeport.png)
   338  
   339  注意:若您的集群节点只有内网 IP,则访问该 IP 的计算机需要在同一内网。若集群节点拥有外网 IP,则没有相关问题。
   340  
   341  #### LoadBalance 方式
   342  
   343  若您使用的是公有云厂商的服务,您可以将 Crane 的 Service 的类型换成公网 LB 类型,这样可以直接通过 LB IP + 9090 端口号的方式,打开控制台。
   344  
   345  具体操作:修改 crane-system 命名空间下名为 craned 的 Service,将其访问方式该为公网 LB 的方式。