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

     1  # Installation
     2  
     3  ## Prerequisites
     4  
     5  - Kubernetes 1.18+
     6  - Helm 3.1.0
     7  
     8  ## Steps
     9  
    10  ### Helm Installation
    11  
    12  Please refer to Helm's [documentation](https://helm.sh/docs/intro/install/) for installation.
    13  
    14  ### Installing prometheus and grafana with helm chart
    15  
    16  !!! note
    17      If you already deployed prometheus, grafana in your environment, then skip this step.
    18  
    19  !!! Warning "Network Problems"
    20      If your network is hard to connect GitHub resources, you can try the mirror repo. Like GitHub Release, GitHub Raw Content `raw.githubusercontent.com`.
    21  
    22      But mirror repo has a certain **latency**.[Mirror Repo](mirror.md)
    23  
    24  Crane use prometheus to be the default metric provider. 
    25  
    26  Using following command to install prometheus components: prometheus-server, node-exporter, kube-state-metrics.
    27  
    28  === "Main"
    29  
    30      ```bash
    31      helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    32      helm install prometheus -n crane-system \
    33                              --set pushgateway.enabled=false \
    34                              --set alertmanager.enabled=false \
    35                              --set server.persistentVolume.enabled=false \
    36                              -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/prometheus/override_values.yaml \
    37                              --create-namespace  prometheus-community/prometheus
    38      ```
    39  
    40  === "Mirror"
    41  
    42      ```bash
    43      helm repo add prometheus-community https://finops-helm.pkg.coding.net/gocrane/prometheus-community
    44      helm install prometheus -n crane-system \
    45                              --set pushgateway.enabled=false \
    46                              --set alertmanager.enabled=false \
    47                              --set server.persistentVolume.enabled=false \
    48                              -f https://gitee.com/finops/helm-charts/raw/main/integration/prometheus/override_values.yaml \
    49                              --create-namespace  prometheus-community/prometheus
    50      ```
    51  Fadvisor use grafana to present cost estimates. Using following command to install a grafana.
    52  
    53  
    54  === "Main"
    55  
    56      ```bash
    57      helm repo add grafana https://grafana.github.io/helm-charts
    58      helm install grafana \
    59                   -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/grafana/override_values.yaml \
    60                   -n crane-system \
    61                   --create-namespace grafana/grafana
    62      ```
    63  
    64  === "Mirror"
    65  
    66      ```bash
    67      helm repo add grafana https://finops-helm.pkg.coding.net/gocrane/grafana
    68      helm install grafana \
    69                   -f https://gitee.com/finops/helm-charts/raw/main/integration/grafana/override_values.yaml \
    70                   -n crane-system \
    71                   --create-namespace grafana/grafana
    72      ```
    73  
    74  ### Deploying Crane and Fadvisor
    75  
    76  
    77  === "Main"
    78  
    79      ```bash
    80      helm repo add crane https://gocrane.github.io/helm-charts
    81      helm install crane -n crane-system --create-namespace crane/crane
    82      helm install fadvisor -n crane-system --create-namespace crane/fadvisor
    83      ```
    84  
    85  === "Mirror"
    86  
    87      ```bash
    88      helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
    89      helm install crane -n crane-system --create-namespace crane/crane
    90      helm install fadvisor -n crane-system --create-namespace crane/fadvisor
    91      ```
    92  
    93  ### Deploying Crane-scheduler(optional)
    94  ```bash
    95  helm install scheduler -n crane-system --create-namespace crane/scheduler
    96  ```
    97  
    98  ### Verify Installation
    99  
   100  Check deployments are all available by running:
   101  
   102  ```bash
   103  kubectl get deploy -n crane-system
   104  ```
   105  
   106  The output is similar to:
   107  ```bash
   108  NAME                                             READY   STATUS    RESTARTS   AGE
   109  crane-agent-8h7df                                1/1     Running   0          119m
   110  crane-agent-8qf5n                                1/1     Running   0          119m
   111  crane-agent-h9h5d                                1/1     Running   0          119m
   112  craned-5c69c684d8-dxmhw                          2/2     Running   0          20m
   113  grafana-7fddd867b4-kdxv2                         1/1     Running   0          41m
   114  metric-adapter-94b6f75b-k8h7z                    1/1     Running   0          119m
   115  prometheus-kube-state-metrics-6dbc9cd6c9-dfmkw   1/1     Running   0          45m
   116  prometheus-node-exporter-bfv74                   1/1     Running   0          45m
   117  prometheus-node-exporter-s6zps                   1/1     Running   0          45m
   118  prometheus-node-exporter-x5rnm                   1/1     Running   0          45m
   119  prometheus-server-5966b646fd-g9vxl               2/2     Running   0          45m
   120  ```
   121  
   122  you can see [this](https://github.com/gocrane/helm-charts) to learn more.
   123  
   124  ## Customize Installation
   125  
   126  Deploy `Crane` by apply YAML declaration.
   127  
   128  === "Main"
   129  
   130      ```bash
   131      git clone https://github.com/gocrane/crane.git
   132      CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
   133      git checkout $CRANE_LATEST_VERSION
   134      kubectl apply -f deploy/manifests 
   135      kubectl apply -f deploy/craned 
   136      kubectl apply -f deploy/metric-adapter
   137      ```
   138  
   139  === "Mirror"
   140  
   141      ```bash
   142      git clone https://e.coding.net/finops/gocrane/crane.git
   143      CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
   144      git checkout $CRANE_LATEST_VERSION
   145      kubectl apply -f deploy/manifests
   146      kubectl apply -f deploy/craned
   147      kubectl apply -f deploy/metric-adapter
   148      ```
   149  
   150  The following command will configure prometheus http address for crane if you want to customize it. Specify `CUSTOMIZE_PROMETHEUS` if you have existing prometheus server.
   151  
   152  ```bash
   153  export CUSTOMIZE_PROMETHEUS=
   154  if [ $CUSTOMIZE_PROMETHEUS ]; then sed -i '' "s/http:\/\/prometheus-server.crane-system.svc.cluster.local:8080/${CUSTOMIZE_PROMETHEUS}/" deploy/craned/deployment.yaml ; fi
   155  ```
   156  
   157  ## Access Dashboard
   158  
   159  You can use the dashboard to view and manage crane manifests.
   160  
   161  ![](images/dashboard.png)
   162  
   163  ### Port Forward
   164  
   165  Easy access to the dashboard through `kubectl port-forward`.
   166  
   167  ```bash
   168  kubectl -n crane-system port-forward service/craned 9090:9090 
   169  ```
   170  
   171  ### NodePort
   172  
   173  ```bash
   174  # Change service type
   175  kubectl patch svc craned -n crane-system -p '{"spec": {"type": "NodePort"}}'
   176  ```
   177  
   178  ```bash
   179  # Get Dashboard link base on your cluster configuration
   180  PORT=$(kubectl get svc -n crane-system craned -o jsonpath='{.spec.ports[?(@.name == "dashboard-service")].nodePort}')
   181  NODE_IP=$(kubectl get node -ojsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}')
   182  echo "Dashboard link: http://${NODE_IP}:${PORT}"
   183  ```
   184  
   185  ### LoadBalancer
   186  
   187  
   188  #### Quick Start
   189  
   190  ```bash
   191  # Change service type
   192  kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'
   193  ```
   194  
   195  #### Example
   196  
   197  ```log
   198  $ kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'
   199  
   200  service/craned patched
   201  
   202  $ kubectl get svc -n crane-system craned
   203  NAME     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                      AGE
   204  craned   LoadBalancer   10.101.123.74   10.200.0.4    443:30908/TCP,8082:32426/TCP,9090:31331/TCP,8080:31072/TCP   57m
   205  
   206  # Access dashboard via 10.200.0.4:9090
   207  ```
   208  
   209  ### Ingress
   210  
   211  #### kubernetes/ingress-nginx
   212  
   213  If the cluster version is < 1.19, you can create the ingress resources like this:
   214  
   215  ```yaml
   216  apiVersion: networking.k8s.io/v1beta1
   217  kind: Ingress
   218  metadata:
   219    name: ingress-crane-dashboard
   220    namespace: crane-system
   221  spec:
   222    ingressClassName: nginx
   223    rules:
   224    - host: dashboard.gocrane.io # change to your domain
   225      http:
   226        paths:
   227        - path: /
   228          backend:
   229            serviceName: craned
   230            servicePort: 9090
   231  ```
   232  
   233  If the cluster uses Kubernetes version >= 1.19.x, then its suggested to create the second ingress resources, using yaml examples shown below. 
   234  
   235  These examples are in conformity with the `networking.kubernetes.io/v1` api.
   236  
   237  ```yaml
   238  apiVersion: networking.k8s.io/v1
   239  kind: Ingress
   240  metadata:
   241    name: ingress-crane-dashboard
   242    namespace: crane-system
   243  spec:
   244    rules:
   245    - host: dashboard.gocrane.io # change to your domain
   246      http:
   247        paths:
   248        - path: /
   249          pathType: Prefix
   250          backend:
   251            service:
   252              name: craned
   253              port:
   254                number: 9090
   255    ingressClassName: nginx
   256  ```
   257  
   258  Example:
   259  
   260  ```log
   261  $ kubectl get svc -n ingress-nginx 
   262  NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
   263  ingress-nginx-controller             LoadBalancer   10.102.235.229   10.200.0.5    80:32568/TCP,443:30144/TCP   91m
   264  ingress-nginx-controller-admission   ClusterIP      10.102.49.240    <none>        443/TCP                      91m
   265  
   266  $ curl -H "Host: dashboard.gocrane.io" 10.200.0.5
   267  <!DOCTYPE html>
   268  <html lang="en">
   269    <head>
   270      <meta charset="UTF-8" />
   271      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   272      <title>Crane Dashboard</title>
   273      ................................................................
   274  ```
   275  
   276  #### Traefik
   277  
   278  ```yaml
   279  apiVersion: traefik.containo.us/v1alpha1
   280  kind: IngressRoute
   281  metadata:
   282    name: dashboard-crane-ingress
   283    namespace: crane-system
   284  spec:
   285    entryPoints:
   286      - web
   287    routes:
   288      - kind: Rule
   289        match: Host(`dashboard.gocrane.io`)
   290        services:
   291          - name: craned
   292            port: 9090
   293  ```
   294  
   295  ```log
   296  $ kubectl get svc -n traefik-v2                     
   297  NAME      TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
   298  traefik   LoadBalancer   10.107.109.44   10.200.0.6    80:30102/TCP,443:30139/TCP   16m
   299  
   300  $ curl -H "Host: dashboard.gocrane.io" 10.200.0.6 
   301  <!DOCTYPE html>
   302  <html lang="en">
   303    <head>
   304      <meta charset="UTF-8" />
   305      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   306      <title>Crane Dashboard</title>
   307      ................................................................
   308  ```
   309  
   310  ## Get your Kubernetes Cost Report
   311  
   312  Get the Grafana URL to visit by running these commands in the same shell:
   313  
   314  ```bash
   315  export POD_NAME=$(kubectl get pods --namespace crane-system -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
   316  kubectl --namespace crane-system port-forward $POD_NAME 3000
   317  ```
   318  
   319  visit [Cost Report](http://127.0.0.1:3000/dashboards) here with account(admin:admin).