kubescape-prometheus-integrator

by Kubescape

Helm chartv0.0.13App v0.0.13

Kubescape integration with Prometheus

About this chart

Kubescape-Prometheus Integration

Docs

Most of the end users either use kube-prometheus-stack prometheus operator else prometheus helm chart to install prometheus for monitoring. Based on your choice of prometheus, you can follow either of the below method to enable kubescape monitoring with Prometheus.

Kubescape integration with Kube-Prometheus-stack (Prometheus operator):

  1. Install the kube-prometheus-stack Helm Chart
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
kubectl create namespace prometheus
helm install -n prometheus kube-prometheus-stack prometheus-community/kube-prometheus-stack --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false,prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
  1. Install the kubescape-prometheus-integrator Helm Chart
helm repo add kubescape https://kubescape.github.io/helm-charts/
helm repo update
helm upgrade --install kubescape-prometheus kubescape/kubescape-prometheus-integrator -n kubescape-prometheus --create-namespace

Kubescape integration with Prometheus community helm chart:

  1. Install the prometheus-community Helm Chart
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
kubectl create namespace prometheus
helm install -n prometheus prometheus prometheus-community/prometheus
  1. Install the kubescape-prometheus-integrator Helm Chart with podAnnotations enabled
helm repo add kubescape https://kubescape.github.io/helm-charts/
helm repo update
helm upgrade --install kubescape-prometheus kubescape/kubescape-prometheus-integrator -n kubescape-prometheus --set kubescape.prometheusAnnotation.enabled=True --create-namespace 

Kubescape

  • Resource Kind: Deployment
  • Communication: REST API
  • Responsibility: Runs Kubescape for detecting misconfigurations in the cluster; This is microservice uses the same engine as the Kubescape CLI tool.

Component Diagram

graph TB

subgraph Cluster
    pr(Prometheus)
    ks(Kubescape)
    k8sApi(Kubernetes API)
end

pr -->|Start Scan| ks
ks -->|Collect Cluster Info|k8sApi
ks -->|Scan results| pr

classDef k8s fill:#326ce5,stroke:#fff,stroke-width:1px,color:#fff;
classDef plain fill:#ddd,stroke:#fff,stroke-width:1px,color:#000

class k8sApi k8s
class pr plain


Adjusting Resource Usage for Your Cluster

By default, Kubescape is configured for small- to medium-sized clusters. If you have a larger cluster and you experience slowdowns or see Kubernetes evicting components, please revise the amount of resources allocated for the troubled component.

Taking Kubescape for example, we found that our defaults of 500 MiB of memory and 500m CPU work well for clusters up to 1250 total resources. If you have more total resources or experience resource pressure already, first check out how many resources are in your cluster by running the following command:

kubectl get all -A --no-headers | wc -l

The command should print an approximate count of resources in your cluster. Then, based on the number you see, allocate 100 MiB of memory for every 200 resources in your cluster over the count of 1250, but no less than 128 MiB total. The formula for memory is as follows:

MemoryLimit := max(128, 0.4 * YOUR_AMOUNT_OF_RESOURCES)

For example, if your cluster has 500 resources, a sensible memory limit would be:

kubescape:
  resources:
    limits:
      memory: 200Mi  # max(128, 0.4 * 500) == 200

If your cluster has 50 resources, we still recommend allocating at least 128 MiB of memory.

When it comes to CPU, the more you allocate, the faster Kubescape will scan your cluster. This is especially true for clusters that have a large amount of resources. However, we recommend that you give Kubescape no less than 500m CPU no matter the size of your cluster so it can scan a relatively large amount of resources fast ;)

Chart support

Values

KeyTypeDefaultDescription
kubescape.affinityobject{}Assign custom affinity rules to the deployment
kubescape.downloadArtifactsboolfalsedownload policies every scan, we recommend it should remain true, you should change to 'false' when running in an air-gapped environment or when scanning with high frequency (when running with Prometheus)
kubescape.enableHostScanboolfalseenable host scanner feature
kubescape.enabledbooltrueenable/disable kubescape scanning
kubescape.image.repositorystring"quay.io/kubescape/kubescape"source code (public repo)
kubescape.nodeSelectorobject{}Node selector
kubescape.serviceMonitor.enabledbooltrueenable/disable service monitor for prometheus (operator) integration
kubescape.serviceMonitor.intervalstring20mScrape interval
kubescape.serviceMonitor.scrapeTimeoutstring100sAdjust to avoid timeout
kubescape.prometheusAnnotation.enabledboolfalseadd/remove pod annotation for prometheus (non-operator) integration
kubescape.volumesobject[]Additional volumes for Kubescape
kubescape.volumeMountsobject[]Additional volumeMounts for Kubescape
kubescape.includeNamespacesobject[]List of namespaces to include, rest of the namespaces will be ignored.
kubescape.excludeNamespacesobject[]List of namespaces to exclude
kubescapeHostScanner.volumesobject[]Additional volumes for the host scanner
kubescapeHostScanner.volumeMountsobject[]Additional volumeMounts for the host scanner
awsIamRoleArnstringnilAWS IAM arn role
cloudProviderMetadata.cloudRegionstringnilcloud region
cloudProviderMetadata.cloudProviderEnginestringnilcloud provider engine
cloudProviderMetadata.gkeProjectstringnilGKE project
cloudProviderMetadata.gkeServiceAccountstringnilGKE service account
cloudProviderMetadata.aksSubscriptionIDstringnilAKS subscription ID
cloudProviderMetadata.aksResourceGroupstringnilAKS resource group
volumesobject[]Additional volumes for all containers
volumeMountsobject[]Additional volumeMounts for all containers

Deploy kubescape-prometheus-integrator with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kubescape-prometheus-integrator 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 chartkubescape-prometheus-integrator is pinned at v0.0.13 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