K8s cluster api

From itechmeat/llm-code · View interactive version

K8s cluster api is an AI agent skill from the GitHub repository itechmeat/llm-code. Kubernetes Cluster API v1.12. Covers clusterctl CLI, ClusterClass, GitOps integration. Scripts for health checks, backup, migration, linting. Templates: clusters, DR, Prometheus. Use when provisioning, upgrading, or operating Kubernetes clusters with CAPI, or running clusterctl and ClusterClass work

How to use this skill

Skill file

Kubernetes Cluster API

Kubernetes Cluster API (CAPI) is a Kubernetes sub-project focused on providing declarative APIs and tooling to simplify provisioning, upgrading, and operating multiple Kubernetes clusters.

Overview

Started by SIG Cluster Lifecycle, Cluster API uses Kubernetes-style APIs and patterns to automate cluster lifecycle management. The infrastructure (VMs, networks, load balancers, VPCs) and Kubernetes configuration are defined declaratively, enabling consistent and repeatable cluster deployments across environments.

Why Cluster API?

While kubeadm reduces installation complexity, it doesn't address day-to-day cluster management:

Cluster API addresses these gaps with declarative, Kubernetes-style APIs that automate cluster creation, configuration, and management.

Goals

Non-Goals

Quick Navigation

| Topic | Reference |

| ---------------------------- | --------------------------------------------------------- |

| Getting Started | getting-started.md |

| Concepts & Architecture | concepts.md |

| Certificates | certificates.md |

| Bootstrap (Kubeadm/MicroK8s) | bootstrap.md |

| Cluster Operations | cluster-operations.md |

| Experimental Features | experimental.md |

| clusterctl CLI | clusterctl.md |

| Developer Guide | developer.md |

| Troubleshooting | troubleshooting.md |

| API Reference & Providers | api-reference.md |

| Security & PSS | security.md |

| Controllers | controllers.md |

| Version Migrations | migrations.md |

| FAQ | faq.md |

| Best Practices | best-practices.md |

When to Use

Core Concepts

Architecture

┌─────────────────────────────────────────┐
│         Management Cluster              │
│  ┌─────────────┐  ┌─────────────────┐   │
│  │ CAPI Core   │  │ Infrastructure  │   │
│  │ Controllers │  │ Provider        │   │
│  └─────────────┘  └─────────────────┘   │
│  ┌─────────────┐  ┌─────────────────┐   │
│  │  Bootstrap  │  │  Control Plane  │   │
│  │  Provider   │  │  Provider       │   │
│  └─────────────┘  └─────────────────┘   │
└─────────────────────┬───────────────────┘
                      │ manages
          ┌───────────┴───────────┐
          ▼                       ▼
┌─────────────────┐     ┌─────────────────┐
│ Workload        │     │ Workload        │
│ Cluster 1       │     │ Cluster N       │
└─────────────────┘     └─────────────────┘

Key Components

| Component | Purpose |

| ----------------------- | ----------------------------------------- |

| Management Cluster | Hosts CAPI controllers, manages workloads |

| Workload Cluster | User clusters managed by CAPI |

| Infrastructure Provider | Provisions VMs, networks, load balancers |

| Bootstrap Provider | Generates cloud-init/ignition configs |

| Control Plane Provider | Manages control plane nodes lifecycle |

Core Resources

| Resource | Description |

| ------------------ | ---------------------------------------- |

| Cluster | Represents a Kubernetes cluster |

| Machine | Represents a single node/VM |

| MachineSet | Manages replicas of Machines |

| MachineDeployment | Declarative updates for MachineSets |

| MachineHealthCheck | Automatic remediation of unhealthy nodes |

Quick Start

# Install clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.12.0/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl
sudo mv clusterctl /usr/local/bin/

# Initialize management cluster
clusterctl init --infrastructure docker

# Create workload cluster
clusterctl generate cluster my-cluster --kubernetes-version v1.32.0 --control-plane-machine-count 1 --worker-machine-count 3 | kubectl apply -f -

# Get cluster kubeconfig
clusterctl get kubeconfig my-cluster > my-cluster.kubeconfig

# Delete cluster
kubectl delete cluster my-cluster

Common Workflows

Cluster Lifecycle

# Create cluster from template
clusterctl generate cluster prod-cluster \
  --infrastructure aws \
  --kubernetes-version v1.32.0 \
  --control-plane-machine-count 3 \
  --worker-machine-count 5 \
  | kubectl apply -f -

# Scale workers
kubectl scale machinedeployment prod-cluster-md-0 --replicas=10

# Upgrade Kubernetes version
kubectl patch cluster prod-cluster --type merge -p '{"spec":{"topology":{"version":"v1.33.0"}}}'

# Move cluster to new management cluster
clusterctl move --to-kubeconfig target-mgmt.kubeconfig

Health Monitoring

apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineHealthCheck
metadata:
  name: my-cluster-mhc
spec:
  clusterName: my-cluster
  maxUnhealthy: 40%
  nodeStartupTimeout: 10m
  selector:
    matchLabels:
      cluster.x-k8s.io/cluster-name: my-cluster
  unhealthyConditions:
    - type: Ready
      status: "False"
      timeout: 5m
    - type: Ready
      status: Unknown
      timeout: 5m

Critical Prohibitions

Release Highlights (1.14.x)

Release Highlights (1.13.x)

Scripts

Go-based tools in scripts/. Run via go run ./tool-name from the scripts directory.

| Tool | Purpose |

| --------------------------- | -------------------------------------------------- |

| validate-manifests | Validate YAML manifests against CRD schemas |

| run-clusterctl-diagnose | Run clusterctl describe and save diagnostic report |

| migration-checker | Check v1beta1→v1beta2 migration readiness |

| check-cluster-health | Analyze conditions across all cluster objects |

| analyze-conditions | Parse and report False/Unknown conditions |

| scaffold-provider | Generate new provider directory structure |

| generate-cluster-template | Generate templates from ClusterClass |

| export-cluster-state | Export cluster state for backup/move |

| audit-security | Check PSS compliance and security posture |

| timeline-events | Build provisioning event timeline |

| compare-versions | Compare CAPI version specs and API changes |

| check-provider-contract | Verify provider CRD compliance with contracts |

| lint-cluster-templates | Lint and validate CAPI manifests |

Assets

Reusable templates in assets/:

Links

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.