# Kubernetes Examples

Practical examples demonstrating how to use the Kubernetes module.

## Prerequisites

- Running Kubernetes cluster
- kubeconfig configured
- Rust 1.92.0+

Verify with:
```bash
kubectl cluster-info
kubectl get namespaces
```

## Running Examples

From the virt package directory:

```bash
cd /Volumes/T7/code4/herolib_rust/packages/virt
```

Run an example:

```bash
cargo run --example <name> --features kubernetes
```

## Available Examples

### 01_basic_operations.rs

Basic Kubernetes operations: pods, services, configmaps, secrets, namespaces.

```bash
cargo run --example 01_basic_operations --features kubernetes
```

- 14 integration tests
- Duration: 30-60 seconds
- Creates and cleans up test namespace automatically

### 02_registry_deployment.rs

Deploy Docker Registry on Kubernetes with and without authentication.

```bash
cargo run --example 02_registry_deployment --features kubernetes
```

- 10 integration tests
- Duration: 60-120 seconds
- Creates registry namespace and cleans up automatically

### 03_registry_build_and_push.rs

Build a minimal container image and push it to a Kubernetes-deployed registry.

```bash
cargo run --example 03_registry_build_and_push --features kubernetes
```

- 8 integration tests
- Duration: 2-5 minutes (includes image build time)
- Deploys registry, builds minimal Alpine image with buildah, pushes to registry
- Demonstrates full end-to-end workflow: deploy registry → build image → push image
- Uses Kubernetes executor to run buildah inside a pod

## Troubleshooting

### Cluster connection issues

```bash
kubectl config get-contexts
kubectl config use-context <context-name>
```

### Compilation errors

```bash
cargo clean
cargo update
cargo build --example 01_basic_operations --features kubernetes
```

### Stuck example

Press `Ctrl+C` to stop. Check resources:

```bash
kubectl get namespaces
kubectl get all -n default
```

## Documentation

- Full API reference: `/packages/virt/src/kubernetes/README.md`
- Detailed guides: `README_K8S_BASIC_OPERATIONS.md`, `README_K8S_REGISTRY_DEPLOYMENT.md`
- Project status: `/KUBERNETES_ENHANCEMENT_COMPLETE.md`
