Import a Kubernetes Cluster

In this guide, you will connect a Kubernetes cluster to Turbot Guardrails. Kubernetes clusters are imported by deploying a Guardrails agent into the cluster. The agent runs as a StatefulSet alongside your other workloads, uses osquery to discover and monitor resources, and reports data back to Guardrails. It always runs in a single pod.

Prerequisites

Step 1: Install Required Mods

The following mods must be installed in your Guardrails workspace:

If using the ServiceNow integration to sync Kubernetes data into ServiceNow, also install:

For ServiceNow setup, see Connect a ServiceNow Instance.

Step 2: Configure Workspace Policies

After installing the osquery mod, verify the following workspace policy:

The Turbot > Workspace > osquery > Enroll Secret Expiration policy controls how frequently the enrollment secret rotates. The default is hourly. If your agent deployment takes longer than expected, increase this interval to avoid the secret expiring mid-deployment.

Step 3: Set Kubernetes Context

Before running the install script, set your kubeconfig context to the correct cluster. The script uses your current kubectl context to deploy the agent.

For cloud-managed clusters:

Step 4: Configure Persistent Storage

By default, the Helm chart uses the cluster's default StorageClass to dynamically provision a PersistentVolumeClaim (PVC) for the agent StatefulSet. This persists the osquery database across restarts.

Many cloud-managed clusters do not include an in-tree storage provisioner by default. You may need to install a CSI driver:

We recommend leaving persistence enabled to avoid disruptions to the osquery database. To disable it (not recommended for production), add the following to your guardrails-values.yaml before running helm install:

persistence:
  enabled: false

For additional persistence options, see the Helm chart values.

Step 5: Open the Onboard Kubernetes Cluster Wizard

From the Dashboard, select the CONNECT button in the top right (or from Workspace > Accounts, select Import). Select Kubernetes from the provider grid.

Create Connection provider selection grid showing Kubernetes among the available providers

The wizard opens to Step 1: Cluster Location.

Step 6: Choose the Destination Folder

Select where to place this cluster in your Guardrails resource hierarchy. Resources from the cluster will be automatically imported under this folder. You can select an existing folder or click Create Folder to create a new one.

Onboard Kubernetes Cluster wizard Step 1 showing Cluster Location with Destination Folder selector

Click Continue to proceed.

Step 7: Download and Run the Deploy Script

The wizard generates a deployment script that installs the Guardrails agent into your cluster using kubectl and Helm.

Onboard Kubernetes Cluster wizard Step 2 showing Deploy Agent with download and view script options

Click Download Deployment Script to save the script, or click the eye icon (View & explain script) to review it first. The script viewer shows the full script with annotated sections explaining what each part does.

Deployment Script modal showing the annotated script with Template Sections panel

The script performs these steps:

  1. Sets the enroll secret: A JWT token scoped to the destination folder you selected. The agent uses this to authenticate with your workspace.
  2. Sets the workspace hostname: The URL of your Guardrails workspace (without the https:// prefix).
  3. Creates the guardrails namespace: Isolates the agent from your other workloads.
  4. Stores the enroll secret as a Kubernetes Secret, so the agent pod can read it securely at runtime.
  5. Generates guardrails-values.yaml: Configuration for the Helm chart with your workspace hostname.
  6. Installs the agent: Adds the Turbot Helm repository and installs the guardrails-agent-kubernetes chart.

Run the script in your terminal:

bash kube_cluster_connect.sh

Or make it executable and run directly:

chmod +x kube_cluster_connect.sh
./kube_cluster_connect.sh

After the agent is deployed, the cluster will appear in your workspace automatically. The Turbot > osquery > Configuration calculated policy must finish calculating before resources appear. This typically takes a few minutes.

[!NOTE] If no resources appear after a few minutes, verify that the Turbot > osquery > Configuration policy value is available for the cluster resource.

Updating the Agent

To update an installed agent to the latest Helm chart version:

helm repo update
helm upgrade guardrails-agent-kubernetes turbot/guardrails-agent-kubernetes \
  --namespace guardrails --reuse-values

To update with new configuration values:

helm upgrade guardrails-agent-kubernetes turbot/guardrails-agent-kubernetes \
  --namespace guardrails --reuse-values -f guardrails-values.yaml

Only values included in guardrails-values.yaml will be updated, with priority given to new values.

Customizing the Cluster Name

Guardrails attempts to derive a friendly cluster name from the cloud provider:

To override the default name, add an annotation to the StatefulSet in your guardrails-values.yaml:

statefulSet:
  annotations:
    guardrails.turbot.com/cluster-name: "my-kube-cluster"

Then upgrade the agent:

helm upgrade guardrails-agent-kubernetes turbot/guardrails-agent-kubernetes \
  --namespace guardrails --reuse-values -f guardrails-values.yaml

Troubleshooting

IssueSolution
Agent not runningCheck the StatefulSet status: kubectl get sts --namespace guardrails
Agent errorsView agent logs: kubectl logs sts/guardrails-agent-kubernetes -f --namespace guardrails
Expired enroll secretThe enroll secret rotates hourly by default. Query for the latest:
{
  osquery(
    resource: "FOLDER_RESOURCE_ID"
    resourceTypeUri: "tmod:@turbot/kubernetes#/resource/types/cluster"
  ) {
    enrollSecret
  }
}
IssueSolution
Old secret in clusterDelete the existing secret and redeploy: kubectl delete secret guardrails-agent-kubernetes-secret --namespace guardrails
No resources discoveredVerify the Turbot > osquery > Configuration calculated policy value is available for the cluster. If it's still calculating, wait for it to complete.

Next Steps

Further Reading