Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ We cover a wide range of DevOps topics in our content library, explore them unde
<td>✔️ <a href="./topics/packer/basics/">Explore</a></td>
<td>🏃 <a href="./topics/packer/practice/">Explore</a></td>
</tr>
<tr>
<td><img height="28" src="https://avatars.githubusercontent.com/u/20777023?v=4"></td>
<td>Crossplane</td>
<td><a href="./topics/crossplane/">crossplane</a></td>
<td>📖 <a href="https://docs.crossplane.io/">View</a></td>
<td>✔️ <a href="./topics/crossplane/basics/">Explore</a></td>
<td>✔️ <a href="./topics/crossplane/practice/">Explore</a></td>
</tr>
<tr>
<td><img width="32" src="https://upload.wikimedia.org/wikipedia/commons/8/87/Sql_data_base_with_logo.png"></td>
<td>SQL</td>
Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This document outlines the planned improvements and upcoming content for DevOps

| Topic | Description |
|-------|-------------|
| Crossplane | Kubernetes-native infrastructure management |
| FluxCD | CNCF-graduated GitOps engine, complement to ArgoCD |
| Grafana | Metrics visualization and dashboards |
| Vault | HashiCorp Vault secrets management |
Expand All @@ -21,7 +22,6 @@ These are planned or in-progress based on community demand and industry relevanc

| Topic | Category | Priority | Notes |
|-------|----------|----------|-------|
| **Crossplane** | IaC / Platform Eng | High | Kubernetes-native infrastructure management |
| **Backstage** | Platform Engineering | High | Developer portal framework by Spotify |
| **Dagger** | CI/CD | Medium | Portable CI/CD pipelines as code |
| **Pulumi** | IaC | Medium | IaC with real programming languages |
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ nav:
- OpenTofu: topics/opentofu/README.md
- Ansible: topics/ansible/README.md
- Packer: topics/packer/README.md
- Crossplane: topics/crossplane/README.md
- Cloud Platforms:
- AWS: topics/aws/README.md
- Azure: topics/azure/README.md
Expand Down
146 changes: 146 additions & 0 deletions topics/crossplane/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
## 1. What is Crossplane?

- https://docs.crossplane.io/

### Overview

Crossplane is a CNCF project that extends Kubernetes so you can provision and manage cloud infrastructure (databases, networks, buckets, ...) the same way you manage Pods and Deployments: with declarative YAML, `kubectl`, and a control loop that continuously reconciles reality to match what you declared.

Core ideas:

- **Provider** — a package that installs CRDs and a controller for an external system (AWS, Azure, GCP, Kubernetes itself, Helm, ...).
- **Managed Resource (MR)** — a Kubernetes object that represents one real external resource (e.g. an S3 bucket). Created by a Provider.
- **Composite Resource Definition (XRD)** — defines your own platform API (e.g. `XDatabase`) as a new CRD.
- **Composition** — a template describing which managed resources are created when someone requests your XRD.
- **Composition Function** — a small program (e.g. `function-patch-and-transform`) that renders the resources for a Composition.

Platform teams publish simple APIs (XRDs + Compositions); application teams consume them without needing to know the cloud details. This is why Crossplane is a common building block of platform engineering (see also the [`argocd`](../argocd/) and [`fluxcd`](../fluxcd/) topics, which can deliver Crossplane YAML from Git).

### Crossplane Architecture

```
kubectl / GitOps (ArgoCD, Flux)
│ applies YAML
▼
┌──────────────────────────┐
│ Kubernetes API server │
│ Claim / XR (your API) │
└────────────┬─────────────┘
│ Composition + Functions render...
▼
┌──────────────────────────┐
│ Managed Resources │ (Bucket, RDSInstance, Object, ...)
└────────────┬─────────────┘
│ Provider controllers reconcile
▼
Cloud APIs / external systems
```

### Official Documentation

- https://docs.crossplane.io/
- GitHub: https://github.com/crossplane/crossplane

## 2. Prerequisites

- A Kubernetes cluster (this topic uses a local [`kind`](../k8s/) cluster — no cloud account needed)
- `kubectl` and `helm`
- Familiarity with the [`k8s`](../k8s/) topic helps, but isn't required

## 3. Installation

### How to install Crossplane?

```bash
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update

helm install crossplane crossplane-stable/crossplane \
--namespace crossplane-system --create-namespace

# Verify
kubectl get pods -n crossplane-system
```

- Official install guide: https://docs.crossplane.io/latest/software/install/

## 4. Basics of Crossplane

### Install a Provider

```yaml
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-kubernetes
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-kubernetes:v0.15.0
```

```bash
kubectl get providers
```

Wait until `INSTALLED` and `HEALTHY` are `True`.

### Create a Managed Resource

With `provider-kubernetes`, an `Object` managed resource wraps any Kubernetes manifest. This is a handy way to learn Crossplane without cloud credentials:

```yaml
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
name: hello-config
spec:
providerConfigRef:
name: default
forProvider:
manifest:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: default
name: hello-from-crossplane
data:
greeting: hello
```

```bash
kubectl get objects
kubectl get configmap hello-from-crossplane
```

Delete the `Object` and Crossplane deletes the ConfigMap too; edit it and Crossplane reconciles the change. Run the full walkthrough with the [basics demo](./basics/).

## 5. Beyond the Basics

### XRDs and Compositions

A Composition turns one high-level request into several managed resources. Sketch of the flow:

1. Install a composition function, e.g. `function-patch-and-transform`.
2. Define an XRD (your new API kind and its schema).
3. Write a Composition that maps the XRD fields onto managed resources.
4. Users create an instance of your API; Crossplane creates and manages everything underneath.

Guide: https://docs.crossplane.io/latest/composition/compositions/

### Cloud providers

For real infrastructure, install a cloud provider (for example the AWS, Azure or GCP provider families from the Upbound Marketplace) and configure a `ProviderConfig` with credentials. Prefer short-lived / workload identity credentials over long-lived keys.

### Useful commands

```bash
kubectl get managed # all managed resources
kubectl describe <kind> <name> # conditions: Ready / Synced
kubectl get providers,functions # installed packages
kubectl get composite # composite resources
```

## 6. More

- [Crossplane docs](https://docs.crossplane.io/)
- [Upbound Marketplace](https://marketplace.upbound.io/) — providers and configurations
- [Crossplane contrib providers](https://github.com/crossplane-contrib)
22 changes: 22 additions & 0 deletions topics/crossplane/basics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Basics of Crossplane

## Demo

Run `./crossplane_kubernetes_demo.sh` to spin up (or reuse) a local `kind` cluster, install Crossplane with Helm, install `provider-kubernetes`, and create a managed resource (`Object`) that makes Crossplane create a ConfigMap. No cloud account or credentials are needed.

### Requirements

- `docker`
- `kind` (the script creates a `crossplane-demo` cluster if one doesn't already exist — https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
- `kubectl`
- `helm`

> Note: for simplicity the demo grants the provider `cluster-admin` on the throwaway local cluster. Don't do this in a real cluster.

### Cleanup

The script prints the teardown command at the end rather than running it automatically:

```bash
kind delete cluster --name crossplane-demo
```
116 changes: 116 additions & 0 deletions topics/crossplane/basics/crossplane_kubernetes_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash
# Crossplane Demo - installs Crossplane on a local kind cluster, installs
# provider-kubernetes and provisions a managed resource (a ConfigMap) with it.
# No cloud account required.

set -e

CLUSTER_NAME="crossplane-demo"

echo "==> Tool versions:"
kubectl version --client
helm version --short

echo ""
echo "=============================="
echo "1. Ensuring a local cluster exists"
echo "=============================="
if kubectl config get-contexts "kind-${CLUSTER_NAME}" >/dev/null 2>&1; then
echo "Reusing existing kind cluster: ${CLUSTER_NAME}"
kubectl config use-context "kind-${CLUSTER_NAME}"
else
echo "Creating kind cluster: ${CLUSTER_NAME}"
kind create cluster --name "${CLUSTER_NAME}"
fi

echo ""
echo "=============================="
echo "2. Installing Crossplane"
echo "=============================="
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm upgrade --install crossplane crossplane-stable/crossplane \
--namespace crossplane-system --create-namespace --wait

echo ""
echo "=============================="
echo "3. Installing provider-kubernetes"
echo "=============================="
# A DeploymentRuntimeConfig gives the provider a predictable ServiceAccount name
# so we can grant it permissions below.
kubectl apply -f - <<YAML
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
name: provider-kubernetes
spec:
serviceAccountTemplate:
metadata:
name: provider-kubernetes
---
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-kubernetes
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-kubernetes:v0.15.0
runtimeConfigRef:
name: provider-kubernetes
YAML

kubectl wait --for=condition=Healthy provider/provider-kubernetes --timeout=300s

echo ""
echo "=============================="
echo "4. Configuring the provider (demo only: cluster-admin on a local cluster)"
echo "=============================="
kubectl create clusterrolebinding provider-kubernetes-admin \
--clusterrole=cluster-admin \
--serviceaccount=crossplane-system:provider-kubernetes \
--dry-run=client -o yaml | kubectl apply -f -

kubectl apply -f - <<YAML
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: InjectedIdentity
YAML

echo ""
echo "=============================="
echo "5. Creating a managed resource"
echo "=============================="
kubectl apply -f - <<YAML
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
name: hello-config
spec:
providerConfigRef:
name: default
forProvider:
manifest:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: default
name: hello-from-crossplane
data:
greeting: hello
YAML

kubectl wait --for=condition=Ready object/hello-config --timeout=120s

echo ""
kubectl get objects
kubectl get configmap hello-from-crossplane -o yaml

echo ""
echo "==> Done! Crossplane created the ConfigMap from the 'Object' managed resource."
echo "==> Tip: 'kubectl delete object hello-config' removes the ConfigMap too."
echo ""
echo "==> Cleanup:"
echo " kind delete cluster --name ${CLUSTER_NAME}"
11 changes: 11 additions & 0 deletions topics/crossplane/practice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Crossplane practice

1. **Reconcile drift**: after running the [basics demo](../basics/), edit the ConfigMap directly (`kubectl edit configmap hello-from-crossplane`, change `greeting`). Wait for the next reconcile and observe whether Crossplane restores the value declared in the `Object`. Then change `greeting` in the `Object` itself and confirm the ConfigMap follows.

2. **Delete propagation**: run `kubectl delete object hello-config` and confirm the ConfigMap is gone. Now re-create the `Object` with `spec.deletionPolicy: Orphan` and repeat — what happens to the ConfigMap this time?

3. **Break it, then read the status**: change `providerConfigRef.name` to a name that doesn't exist and run `kubectl describe object hello-config`. Find the `Synced`/`Ready` conditions and the error message, then fix it and confirm it recovers.

4. **Your first Composition**: install `function-patch-and-transform`, define an XRD such as `XGreeting` with a `message` field, and write a Composition that creates an `Object` ConfigMap using that value. Create an `XGreeting` and verify the ConfigMap appears (see https://docs.crossplane.io/latest/composition/compositions/).

- Crossplane docs: https://docs.crossplane.io/
8 changes: 8 additions & 0 deletions topics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ Browse **40+ topics** organized by category. Each topic includes official docs,

[:octicons-book-16: Docs](https://www.packer.io/) &nbsp;·&nbsp; [:octicons-code-16: Basics](packer/basics/)

- :octicons-cross-reference-16: **Crossplane**

---

Manage cloud infrastructure as Kubernetes resources with providers and compositions.

[:octicons-book-16: Docs](https://docs.crossplane.io/) &nbsp;·&nbsp; [:octicons-code-16: Basics](crossplane/basics/) &nbsp;·&nbsp; [:octicons-beaker-16: Practice](crossplane/practice/)

</div>

---
Expand Down