Installation

How to install Crane

Prerequisites

  • Kubernetes 1.18+
  • Helm 3.1.0

Steps

Helm Installation

Please refer to Helm’s documentation for installation.

Installing prometheus and grafana with helm chart

If you already deployed prometheus, grafana in your environment, then skip this step.

If your network is hard to connect GitHub resources, you can try the mirror repo. Like GitHub Release, GitHub Raw Content raw.githubusercontent.com. But mirror repo has a certain latency. Please see Mirror Resources to know details.

Crane use prometheus to be the default metric provider.

Using following command to install prometheus components: prometheus-server, node-exporter, kube-state-metrics.

  1. helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
  2. helm install prometheus -n crane-system \
  3. --set pushgateway.enabled=false \
  4. --set alertmanager.enabled=false \
  5. --set server.persistentVolume.enabled=false \
  6. -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/prometheus/override_values.yaml \
  7. --create-namespace prometheus-community/prometheus
  1. helm repo add prometheus-community https://finops-helm.pkg.coding.net/gocrane/prometheus-community
  2. helm install prometheus -n crane-system \
  3. --set pushgateway.enabled=false \
  4. --set alertmanager.enabled=false \
  5. --set server.persistentVolume.enabled=false \
  6. -f https://gitee.com/finops/helm-charts/raw/main/integration/prometheus/override_values.yaml \
  7. --create-namespace prometheus-community/prometheus

Fadvisor use grafana to present cost estimates. Using following command to install a grafana.

  1. helm repo add grafana https://grafana.github.io/helm-charts
  2. helm install grafana \
  3. -f https://raw.githubusercontent.com/gocrane/helm-charts/main/integration/grafana/override_values.yaml \
  4. -n crane-system \
  5. --create-namespace grafana/grafana
  1. helm repo add grafana https://finops-helm.pkg.coding.net/gocrane/grafana
  2. helm install grafana \
  3. -f https://gitee.com/finops/helm-charts/raw/main/integration/grafana/override_values.yaml \
  4. -n crane-system \
  5. --create-namespace grafana/grafana

Deploying Crane and Fadvisor

  1. helm repo add crane https://gocrane.github.io/helm-charts
  2. helm install crane -n crane-system --create-namespace crane/crane
  3. helm install fadvisor -n crane-system --create-namespace crane/fadvisor
  1. helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
  2. helm install crane -n crane-system --create-namespace crane/crane
  3. helm install fadvisor -n crane-system --create-namespace crane/fadvisor

Deploying Crane-scheduler(optional)

  1. helm install scheduler -n crane-system --create-namespace crane/scheduler

Verify Installation

Check deployments are all available by running:

  1. kubectl get deploy -n crane-system

The output is similar to:

  1. NAME READY STATUS RESTARTS AGE
  2. crane-agent-8h7df 1/1 Running 0 119m
  3. crane-agent-8qf5n 1/1 Running 0 119m
  4. crane-agent-h9h5d 1/1 Running 0 119m
  5. craned-5c69c684d8-dxmhw 2/2 Running 0 20m
  6. grafana-7fddd867b4-kdxv2 1/1 Running 0 41m
  7. metric-adapter-94b6f75b-k8h7z 1/1 Running 0 119m
  8. prometheus-kube-state-metrics-6dbc9cd6c9-dfmkw 1/1 Running 0 45m
  9. prometheus-node-exporter-bfv74 1/1 Running 0 45m
  10. prometheus-node-exporter-s6zps 1/1 Running 0 45m
  11. prometheus-node-exporter-x5rnm 1/1 Running 0 45m
  12. prometheus-server-5966b646fd-g9vxl 2/2 Running 0 45m

you can see this to learn more.

Customize Installation

Deploy Crane by apply YAML declaration.

  1. git clone https://github.com/gocrane/crane.git
  2. CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
  3. git checkout $CRANE_LATEST_VERSION
  4. kubectl apply -f deploy/manifests
  5. kubectl apply -f deploy/craned
  6. kubectl apply -f deploy/metric-adapter
  1. git clone https://e.coding.net/finops/gocrane/crane.git
  2. CRANE_LATEST_VERSION=$(curl -s https://api.github.com/repos/gocrane/crane/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
  3. git checkout $CRANE_LATEST_VERSION
  4. kubectl apply -f deploy/manifests
  5. kubectl apply -f deploy/craned
  6. kubectl apply -f deploy/metric-adapter

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.

  1. export CUSTOMIZE_PROMETHEUS=
  2. if [ $CUSTOMIZE_PROMETHEUS ]; then sed -i '' "s/http:\/\/prometheus-server.crane-system.svc.cluster.local:8080/${CUSTOMIZE_PROMETHEUS}/" deploy/craned/deployment.yaml ; fi

Access Dashboard

You can use the dashboard to view and manage crane manifests.

Installation - 图1

Port Forward

Easy access to the dashboard through kubectl port-forward.

  1. kubectl -n crane-system port-forward service/craned 9090:9090

NodePort

  1. # Change service type
  2. kubectl patch svc craned -n crane-system -p '{"spec": {"type": "NodePort"}}'
  1. # Get Dashboard link base on your cluster configuration
  2. PORT=$(kubectl get svc -n crane-system craned -o jsonpath='{.spec.ports[?(@.name == "dashboard-service")].nodePort}')
  3. NODE_IP=$(kubectl get node -ojsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}')
  4. echo "Dashboard link: http://${NODE_IP}:${PORT}"

LoadBalancer

Quick Start

  1. # Change service type
  2. kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'

Example

  1. $ kubectl patch svc craned -n crane-system -p '{"spec": {"type": "LoadBalancer"}}'
  2. service/craned patched
  3. $ kubectl get svc -n crane-system craned
  4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  5. craned LoadBalancer 10.101.123.74 10.200.0.4 443:30908/TCP,8082:32426/TCP,9090:31331/TCP,8080:31072/TCP 57m
  6. # Access dashboard via 10.200.0.4:9090

Ingress

kubernetes/ingress-nginx

If the cluster version is < 1.19, you can create the ingress resources like this:

  1. apiVersion: networking.k8s.io/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: ingress-crane-dashboard
  5. namespace: crane-system
  6. spec:
  7. ingressClassName: nginx
  8. rules:
  9. - host: dashboard.gocrane.io # change to your domain
  10. http:
  11. paths:
  12. - path: /
  13. backend:
  14. serviceName: craned
  15. servicePort: 9090

If the cluster uses Kubernetes version >= 1.19.x, then its suggested to create the second ingress resources, using yaml examples shown below.

These examples are in conformity with the networking.kubernetes.io/v1 api.

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: ingress-crane-dashboard
  5. namespace: crane-system
  6. spec:
  7. rules:
  8. - host: dashboard.gocrane.io # change to your domain
  9. http:
  10. paths:
  11. - path: /
  12. pathType: Prefix
  13. backend:
  14. service:
  15. name: craned
  16. port:
  17. number: 9090
  18. ingressClassName: nginx

Example:

  1. $ kubectl get svc -n ingress-nginx
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. ingress-nginx-controller LoadBalancer 10.102.235.229 10.200.0.5 80:32568/TCP,443:30144/TCP 91m
  4. ingress-nginx-controller-admission ClusterIP 10.102.49.240 <none> 443/TCP 91m
  5. $ curl -H "Host: dashboard.gocrane.io" 10.200.0.5
  6. <!DOCTYPE html>
  7. <html lang="en">
  8. <head>
  9. <meta charset="UTF-8" />
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  11. <title>Crane Dashboard</title>
  12. ................................................................

Traefik

  1. apiVersion: traefik.containo.us/v1alpha1
  2. kind: IngressRoute
  3. metadata:
  4. name: dashboard-crane-ingress
  5. namespace: crane-system
  6. spec:
  7. entryPoints:
  8. - web
  9. routes:
  10. - kind: Rule
  11. match: Host(`dashboard.gocrane.io`)
  12. services:
  13. - name: craned
  14. port: 9090
  1. $ kubectl get svc -n traefik-v2
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. traefik LoadBalancer 10.107.109.44 10.200.0.6 80:30102/TCP,443:30139/TCP 16m
  4. $ curl -H "Host: dashboard.gocrane.io" 10.200.0.6
  5. <!DOCTYPE html>
  6. <html lang="en">
  7. <head>
  8. <meta charset="UTF-8" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  10. <title>Crane Dashboard</title>
  11. ................................................................

Get your Kubernetes Cost Report

Get the Grafana URL to visit by running these commands in the same shell:

  1. 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}")
  2. kubectl --namespace crane-system port-forward $POD_NAME 3000

visit Cost Report here with account(admin:admin).