kubecost

by joaquinito2051

Helm chartv0.37.5App 1.108.1

Kubecost

About this chart

Kubecost helm chart

This is a parent chart that deploys Kubecost along with some other supporting components.

hooks:
  # Modifies the prometheus configmap to set the prometheus cluster_id
  # external label to the cluster's kube-system ns uid.
  # Creates configmap to pass kube-system ns uid as envvar to kubecost.
  clusterID:
    enabled: true
    kubectlImage: "bitnamilegacy/kubectl:1.29.2"

cost-analyzer:
  enabled: true

  global:
    prometheus:
      # If false, Prometheus will not be installed -- only actively supported on paid Kubecost plans
      enabled: true

    thanos:
      enabled: false

    grafana:
      # If false, Grafana will not be installed
      enabled: true

    notifications:
      alertmanager:
        # If true, allow kubecost to write to alertmanager
        enabled: true

  # Enable kubecost ingress with below annotations to use Konvoy traefik auth
  # ingress:
  #   enabled: true
  #   annotations:
  #     kubernetes.io/ingress.class: traefik
  #     ingress.kubernetes.io/auth-response-headers: X-Forwarded-User
  #     traefik.frontend.rule.type: PathPrefixStrip
  #     traefik.ingress.kubernetes.io/auth-response-headers: X-Forwarded-User,Authorization,Impersonate-User,Impersonate-Group
  #     traefik.ingress.kubernetes.io/auth-type: forward
  #     # traefik rules need to be overridden to use kommander auth if federated from kommander
  #     traefik.ingress.kubernetes.io/auth-url: http://traefik-forward-auth-kubeaddons.kubeaddons.svc.cluster.local:4181/
  #     traefik.ingress.kubernetes.io/priority: "2"
  #   paths:
  #     - "/ops/portal/kubecost"
  #   hosts:
  #     - ""
  #   tls: []

  # Define persistence volume for cost-analyzer, more information at https://github.com/kubecost/docs/blob/master/storage.md
  persistentVolume:
    # Upgrades from original default 0.2Gi may break if automatic disk resize is not supported
    # https://github.com/kubecost/cost-analyzer-helm-chart/issues/507
    size: 32Gi
    # Note that setting this to false means configurations will be wiped out on pod restart.
    enabled: true
    # storageClass: "-"

  prometheus:
    nodeExporter:
      enabled: false
    serviceAccounts:
      nodeExporter:
        create: false
    extraScrapeConfigs: |
      - job_name: kubecost
        honor_labels: true
        scrape_interval: 1m
        scrape_timeout: 10s
        metrics_path: /metrics
        scheme: http
        dns_sd_configs:
        - names:
          - {{ .Release.Name }}-cost-analyzer
          type: 'A'
          port: 9003
      - job_name: kubecost-networking
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
        # Scrape only the the targets matching the following metadata
          - source_labels: [__meta_kubernetes_pod_label_app]
            action: keep
            regex: {{ .Release.Name }}-network-costs
    server:
      # If clusterIDConfigmap is defined, instead use user-generated configmap with key CLUSTER_ID
      # to use as unique cluster ID in kubecost cost-analyzer deployment.
      # This overrides the cluster_id set in prometheus.server.global.external_labels.
      # NOTE: This does not affect the external_labels set in prometheus config.
      clusterIDConfigmap: kubecost-cluster-info-configmap
      extraFlags:
      - web.enable-admin-api
      - web.enable-lifecycle
      - storage.tsdb.wal-compression
      resources:
        limits:
          cpu: 1000m
          memory: 2500Mi
        requests:
          cpu: 300m
          memory: 1500Mi
      global:
        scrape_interval: 1m
        scrape_timeout: 10s
        evaluation_interval: 1m
        external_labels:
          cluster_id: $CLUSTER_ID
      persistentVolume:
        size: 32Gi
        enabled: true
      extraArgs:
        log.level: info
        log.format: json
        storage.tsdb.min-block-duration: 2h
        storage.tsdb.max-block-duration: 2h
        query.max-concurrency: 1
        query.max-samples: 100000000
      enableAdminApi: true
      service:
        gRPC:
          enabled: true
      sidecarContainers:
      - name: thanos-sidecar
        image: thanosio/thanos:v0.15.0
        args:
        - sidecar
        - --log.level=debug
        - --tsdb.path=/data/
        - --prometheus.url=http://127.0.0.1:9090
        - --reloader.config-file=/etc/config/prometheus.yml
        # Start of time range limit to serve. Thanos sidecar will serve only metrics, which happened
        # later than this value. Option can be a constant time in RFC3339 format or time duration
        # relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y.
        - --min-time=-3h
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        ports:
        - name: sidecar-http
          containerPort: 10902
        - name: grpc
          containerPort: 10901
        - name: cluster
          containerPort: 10900
        volumeMounts:
        - name: config-volume
          mountPath: /etc/config
        - name: storage-volume
          mountPath: /data
          subPath: ""
    alertmanager:
      enabled: true
      image:
        tag: v0.21.0
      resources:
        limits:
          cpu: 50m
          memory: 100Mi
        requests:
          cpu: 10m
          memory: 50Mi
      persistentVolume:
        enabled: true
    pushgateway:
      enabled: false
      persistentVolume:
        enabled: false
    serverFiles:
      alerts:
        groups:
          - name: Kubecost
            rules:
              - alert: kubecostDown
                expr: up{job="kubecost"} == 0
                annotations:
                  message: 'Kubecost metrics endpoint is not being scraped successfully.'
                for: 10m
                labels:
                  severity: warning
              - alert: kubecostMetricsUnavailable
                expr: sum(sum_over_time(node_cpu_hourly_cost[5m])) == 0
                annotations:
                  message: 'Kubecost metrics are not available in Prometheus.'
                for: 10m
                labels:
                  severity: warning
              - alert: kubecostRecordingRulesNotEvaluated
                expr: avg_over_time(kubecost_cluster_memory_working_set_bytes[5m]) == 0
                annotations:
                  message: 'Kubecost recording rules are not being successfully evaluated.'
                for: 10m
                labels:
                  severity: warning

  grafana:
    sidecar:
      image: kiwigrid/k8s-sidecar:1.15.9
      dashboards:
        enabled: true
        label: kubecost_grafana_dashboard
      datasources:
        enabled: true
        defaultDatasourceEnabled: false
        label: kubecost_grafana_datasource
    # Enable grafana ingress with below annotations to use Konvoy traefik auth
    # enabled: true
    # annotations:
    #   kubernetes.io/ingress.class: kommander-traefik
    #   ingress.kubernetes.io/auth-response-headers: X-Forwarded-User
    #   traefik.ingress.kubernetes.io/router.tls: "true"
    #   traefik.ingress.kubernetes.io/router.middlewares: "${workspaceNamespace}-stripprefixes@kubernetescrd,${workspaceNamespace}-forwardauth@kubernetescrd"
    # hosts: [""]
    # path: "/dkp/kubecost/grafana"
    # Configure grafana.ini server.root_url properly if ingress is enabled
    # grafana.ini:
    #   log:
    #     level: warn
    #   server:
    #     protocol: http
    #     enable_gzip: true
    #     root_url: "%(protocol)s://%(domain)s:%(http_port)s/dkp/kubecost/grafana"
    #   auth.proxy:
    #     enabled: true
    #     header_name: X-Forwarded-User
    #     auto-sign-up: true
    #   auth.basic:
    #     enabled: false
    #   users:
    #     auto_assign_org_role: Admin

  thanos:
    store:
      enabled: false
    query:
      enabled: false
    sidecar:
      enabled: false
    bucket:
      enabled: false
    compact:
      enabled: false

Deploy kubecost with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kubecost on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkubecost is pinned at v0.37.5 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply