Tekton on NixOS Setup

This comprehensive guide demonstrates how to configure and automate Tekton deployment on NixOS using declarative configuration management. NixOS's unique approach allows us to define the entire Tekton infrastructure as code, ensuring reproducible and maintainable CI/CD environments.

Why NixOS for Tekton?

NixOS provides several advantages for Tekton deployments:

  • Declarative Configuration: Define your entire Tekton stack in configuration files

  • Reproducibility: Identical deployments across environments

  • Rollback Capability: Easy system rollbacks if configurations fail

  • Package Management: Integrated package management with Nix

  • Immutable Infrastructure: System state is predictable and consistent

Prerequisites

Before starting, ensure you have:

  1. NixOS 23.11+ installed and configured

  2. Root/sudo access for system configuration changes

  3. Internet connectivity for downloading Tekton components

  4. Basic NixOS knowledge (understanding of /etc/nixos/configuration.nix)

Complete NixOS Configuration Example

Below is a complete NixOS configuration that automatically sets up Tekton with all required components:

Configuration Breakdown

1. Version Management

Purpose: Centralized version management ensures consistency across all Tekton components and makes upgrades manageable.

2. Custom Installation Scripts

The configuration creates three custom scripts:

tektonInstaller

  • Installs Tekton Pipelines, Triggers, and Dashboard

  • Waits for pods to be ready

  • Installs essential tasks from Tekton Hub

tektonClusterSetup

  • Sets up k3s cluster if needed

  • Installs Tekton components

  • Configures RBAC permissions

  • Creates development namespace

tektonExamples

  • Generates example pipelines for testing

  • Creates security-focused pipeline templates

  • Provides PipelineRun examples

3. Package Installation

Includes:

  • Kubernetes tools: kubectl, helm, k3s

  • Tekton CLI: tkn for pipeline management

  • Container tools: Docker, Buildah, Skopeo for image handling

  • Security tools: Cosign for signing, Trivy for scanning

  • Development tools: Git, curl, jq for general development

4. Service Configuration

Configuration:

  • Enables k3s as a systemd service

  • Disables Traefik (using Tekton's built-in ingress)

  • Sets kubeconfig permissions for user access

5. Automated Setup

Features:

  • Runs after k3s service starts

  • One-time execution with persistent state

  • Automatic Tekton installation on system boot

Installation Steps

1. Create Configuration File

Save the complete configuration as /etc/nixos/tekton.nix:

2. Import in Main Configuration

Edit your main NixOS configuration:

Add the import:

3. Rebuild System

Apply the new configuration:

4. Verify Installation

Check that Tekton is properly installed:

Post-Installation Configuration

1. Configure Docker Registry Access

Create Docker credentials for private registries:

2. Set Up Image Signing

Configure Cosign for image signing:

3. Access Tekton Dashboard

Forward the dashboard port to access the web UI:

Advanced Configuration Options

1. Custom Resource Limits

Add resource limits for production environments:

2. Persistent Storage Configuration

Configure persistent storage for pipeline artifacts:

3. Monitoring Integration

Add Prometheus monitoring for Tekton:

Troubleshooting

Common Issues and Solutions

1. k3s Service Not Starting

2. Tekton Pods Not Ready

3. Permission Issues

4. Network Connectivity Issues

Maintenance and Updates

1. Updating Tekton Versions

Update versions in configuration and rebuild:

2. Backup and Recovery

3. System Rollback

If issues occur, rollback using NixOS generations:

Best Practices

1. Version Pinning

  • Always pin Tekton versions in configuration

  • Test updates in development before production

  • Keep a compatibility matrix for components

2. Resource Management

  • Set appropriate resource limits for tasks

  • Use node selectors for specific workloads

  • Implement proper cleanup policies

3. Security

  • Regular security scans with Trivy

  • Image signing with Cosign

  • RBAC principle of least privilege

4. Monitoring

  • Enable Tekton metrics

  • Set up alerts for failed pipelines

  • Monitor resource usage trends

This configuration provides a complete, production-ready Tekton setup on NixOS with automated installation, security features, and maintenance tools. The declarative approach ensures reproducible deployments and easy management of your CI/CD infrastructure.

Last updated