| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The Lightrun Kubernetes Operator simplifies inserting Lightrun agents into your K8s workloads without modifying your Docker images or Kubernetes manifests. Built using operator-sdk and following the Kubernetes Operator pattern.
The Lightrun K8s Operator automates the two steps needed to add a Lightrun agent to your Kubernetes applications:
For more details on how this works, see our technical documentation.
Important: Read this before deploying to production.
To set up the Lightrun K8s operator:
Create namespaces for the operator and test deployment:
kubectl create namespace lightrun-operator
kubectl create namespace lightrun-agent-testNote: The lightrun-operator namespace is hardcoded in the example operator.yaml due to Role and RoleBinding objects. To deploy the operator to a different namespace, use the Helm chart installation method.
Deploy the operator:
kubectl apply -f https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/operator.yaml -n lightrun-operatorCreate a test deployment:
kubectl apply -f https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/deployment.yaml -n lightrun-agent-testThe test application source code is available at PrimeMain.java
Download Lightrun agent config and lightrun-secret
curl https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/lightrunjavaagent.yaml > agent.yaml
curl https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/lightrun-secret.yaml > lightrun-secret.yamlConfigure your Lightrun credentials:
In agent.yaml:
# Update the serverHostname field
serverHostname: "app.lightrun.com" # For SaaS deployment
# For on-prem deployment, use your own hostnameIn lightrun-secret.yaml:
# Update the following fields:
lightrun_key: "your-lightrun-key" # Find this on the Lightrun setup agent page
pinned_cert_hash: "your-cert-hash" # Obtain from https://<serverHostname>/api/getPinnedServerCert
# Note: Authentication requiredCreate the agent custom resource:
kubectl apply -f lightrun-secret.yaml -n lightrun-agent-test
kubectl apply -f agent.yaml -n lightrun-agent-testVerify the installation:
A Helm chart is available in the repository branch helm-repo.
Add the Lightrun repository to your Helm repositories:
helm repo add lightrun-k8s-operator https://lightrun-platform.github.io/lightrun-k8s-operator
helm repo updateInitial Installation:
Using default values:
helm install lightrun-k8s-operator lightrun-k8s-operator/lightrun-k8s-operator -n lightrun-operator --create-namespaceUsing custom values file:
helm install lightrun-k8s-operator lightrun-k8s-operator/lightrun-k8s-operator -f <values-file> -n lightrun-operator --create-namespaceUpgrading the Operator:
Due to Helm's limitations with CRD management, upgrades require special handling:
For upgrades that include CRD changes:
# Step 1: Update the repository
helm repo update
# Step 2: Apply CRDs manually (if CRDs have changed)
kubectl apply -f https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/config/crd/bases/agents.lightrun.com_lightrunjavaagents
# Step 3: Upgrade the Helm release
helm upgrade lightrun-k8s-operator lightrun-k8s-operator/lightrun-k8s-operator -n lightrun-operatorFor upgrades without CRD changes:
helm repo update
helm upgrade lightrun-k8s-operator lightrun-k8s-operator/lightrun-k8s-operator -n lightrun-operatorImportant: Always check the release notes to determine if CRDs have been updated in the new version.
Note: helm upgrade --install or helm install --dry-run may not work properly due to limitations with how Helm handles CRDs. For more information, see the Helm documentation.
Uninstall the chart:
helm delete lightrun-k8s-operator -n lightrun-operatorManual CRD cleanup (if needed):
# Warning: This will delete all LightrunJavaAgent custom resources
kubectl delete crd lightrunjavaagents.agents.lightrun.comNote: CRDs are not automatically deleted by Helm due to safety reasons. See Helm's documentation on CRD limitations for more details.
For simplicity, we maintain the same version for both the controller image and the Helm chart. This ensures alignment between controller actions and CRDs, preventing resource validation errors.
The operator supports active-passive HA. When running multiple replicas, exactly one pod holds the leader lease and performs reconciliation. The others are passive standbys — they acquire the lease automatically if the leader becomes unavailable.
To enable HA, set at least 2 replicas via Helm:
controllerManager:
replicas: 3env:
- name: JAVA_TOOL_OPTIONS
value: "some initial value"'Deployment.apps "<deployment name>" is invalid: spec.template.spec.containers[0].env[31].valueFrom:
Invalid value: "": may not be specified when `value` is not empty'
Container Platforms:
Available Init Containers:
Kubernetes Resources:
Programming Languages:
We welcome contributions to the Lightrun K8s Operator! If you have ideas for improvements or find bugs, please:
make post-commit-hookRun this command to add a post-commit hook that automatically regenerates rules and CRDs after every commit, ensuring your code and resources stay in sync.
You'll need a Kubernetes cluster to run against. You can use KIND or K3S for local testing, or run against a remote cluster.
Note: When using make commands, the controller will automatically use the current context in your kubeconfig file (i.e., whatever cluster kubectl cluster-info shows).
Clone the repository:
git clone git@github.com:lightrun-platform/lightrun-k8s-operator.git
cd lightrun-k8s-operatorInstall the CRDs into your cluster:
make installRun the controller (this will run in the foreground):
make runIn a new terminal, deploy a sample application:
kubectl apply -f ./examples/deployment.yaml
kubectl get deployments sample-deploymentPrepare the Lightrun agent configuration:
Apply the custom resource:
kubectl apply -f ./examples/lightrunjavaagent.yaml
kubectl apply -f ./examples/lightrun-secret.yamlAfter applying the custom resource, you should see the controller logs indicating it has detected the new resource.
To verify the changes made by the controller (init container, volume, environment variables), run:
kubectl describe deployments sample-deploymentCopyright 2022 Lightrun
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
| Back | FazBrowse Home | New Git URL |