Commit 9b5411e3 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Remove old automation since we migrated to ansible

parent e057d729
Loading
Loading
Loading
Loading
+0 −190
Original line number Diff line number Diff line
# Kind Cluster Automation

Simple scripts to deploy and undeploy a Kind (Kubernetes in Docker) cluster.

> [!WARNING]
> **Cloudflare WARP must be disabled**
>
> Ensure that Cloudflare WARP is not active before deploying the cluster. WARP interferes with local Kubernetes networking and prevent the cluster from working correctly.
> Disable WARP before proceeding with the deployment. 
> I spent several hours troubleshooting this and in the end it was due to WARP being enabled. So please do not waste time on this as I did :).

## Prerequisites

- Docker installed and running
- `curl` (for downloading Kind if not installed)
- `sudo` privileges (for installing Kind if needed)

## Quick Start

### Deploy the Cluster

```bash
./deploy.sh
```

This script will:
1. Install Kind if it's not already installed
2. Create a Kind cluster named `operator-platform` with 1 control-plane and 2 worker nodes
3. Export the kubeconfig to `operator-platform-external-kubeconfig.yaml`
4. Display instructions for accessing the cluster

### Undeploy the Cluster

```bash
./undeploy.sh
```

This script will:
1. Delete the Kind cluster
2. Remove the kubeconfig file
3. Clean up all associated Docker containers

## Accessing the Cluster

After running `deploy.sh`:

1. Edit `operator-platform-external-kubeconfig.yaml`
2. Find the `server:` line (will be `https://0.0.0.0:6443`)
3. Change it to:
   - `https://localhost:6443` for local access
   - `https://<YOUR_HOST_IP>:6443` for remote access

4. Use the kubeconfig:
   ```bash
   export KUBECONFIG=$(pwd)/operator-platform-external-kubeconfig.yaml
   kubectl get nodes
   ```

## Cluster Configuration

The cluster is configured in `kind-config.yaml` with:
- 1 control-plane node
- 2 worker nodes
- API server accessible on `0.0.0.0:6443`
- Containerd configured to keep unpacked layers
- **Port mappings** (accessible on localhost):
  - `6443` - Kubernetes API server
  - `30090` - Prometheus API (after installing dependencies)
  - `30769` - i2edge service (after deploying i2edge)

## Troubleshooting

### Port 6443 already in use
If port 6443 is already in use, you'll need to:
1. Stop the service using that port, or
2. Modify `kind-config.yaml` to use a different `hostPort`

### Cannot connect to cluster
Make sure:
- The cluster is running: `kind get clusters`
- Docker containers are up: `docker ps | grep operator-platform`
- You've edited the kubeconfig server URL correctly

### Cluster creation fails
Check Docker is running:
```bash
docker ps
```

View detailed logs:
```bash
kind create cluster --name operator-platform --config kind-config.yaml -v 3
```

## Installing i2edge Dependencies

After deploying the cluster, you can install the required dependencies for i2edge:

```bash
./install-dependencies.sh
```

This script will install:
1. **Helm3** - Package manager for Kubernetes
2. **Prometheus Stack** - Monitoring and metrics collection
   - Installed in `monitoring` namespace
   - Grafana with default credentials (admin/admin)
   - Prometheus API exposed on NodePort 30090
3. **Node Feature Discovery** - Custom node labeling
   - Installed with default configuration
   - Sample node labels for zoneID, geolocation, and geography

### Post-Installation Configuration

After running `install-dependencies.sh`, you may want to customize:

#### 1. Prometheus Configuration
Edit `prometheus-values.yaml` to add your cluster node IPs in the `endpoints` sections.

#### 2. Node Labels
Edit `nodes-labels.yaml` to customize labels for your specific nodes:
```yaml
spec:
  labels:
    feature.node.kubernetes.io/zoneID: "your-zone-id"
    feature.node.kubernetes.io/geolocation: "your-coordinates"
    feature.node.kubernetes.io/geographyDetails: "your-location-details"
```

Then reapply:
```bash
kubectl apply -f nodes-labels.yaml
```

#### 3. Access Grafana
To access Grafana dashboard:
```bash
kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80
```
Then open http://localhost:3000 (login: admin/admin)

#### 4. Access Prometheus
Prometheus is exposed on NodePort 30090:
```bash
# Check the service
kubectl get svc -n monitoring prometheus-prometheus

# Access directly via localhost (port mapping configured in kind-config.yaml)
curl http://localhost:30090/api/v1/query?query=up

# Or open in browser
open http://localhost:30090
```

**Note**: With the updated `kind-config.yaml`, NodePort 30090 is directly accessible on localhost without port-forwarding!

### Verify Installation

Check that all components are running:
```bash
# Set kubeconfig
export KUBECONFIG=$(pwd)/operator-platform-external-kubeconfig.yaml

# Check Prometheus pods
kubectl get pods -n monitoring

# Check NFD pods
kubectl get pods -n node-feature-discovery

# Verify node labels
kubectl get nodes -o json | jq '.items[].metadata.labels' | grep feature.node.kubernetes.io
```

## Manual Management

If you prefer manual control:

```bash
# List clusters
kind get clusters

# Delete a specific cluster
kind delete cluster --name operator-platform

# Get kubeconfig
kind get kubeconfig --name operator-platform

# Load a Docker image into the cluster
kind load docker-image <image-name> --name operator-platform
```
+0 −70
Original line number Diff line number Diff line
#!/bin/bash
set -e

echo "=========================================="
echo "Deploying Kind Cluster"
echo "=========================================="

# Check if Kind is installed
if ! command -v kind &> /dev/null; then
    echo "Kind not found. Installing Kind..."
    [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-amd64
    chmod +x ./kind
    sudo mv ./kind /usr/local/bin/kind
    echo "✓ Kind installed successfully"
else
    echo "✓ Kind is already installed ($(kind version))"
fi

# Check if cluster already exists
if kind get clusters 2>/dev/null | grep -q "operator-platform"; then
    echo "⚠ Cluster 'operator-platform' already exists"
    read -p "Do you want to recreate it? (y/N): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        echo "Deleting existing cluster..."
        kind delete cluster --name operator-platform
    else
        echo "Keeping existing cluster. Exiting."
        exit 0
    fi
fi

# Create the cluster
echo "Creating Kind cluster 'operator-platform'..."
kind create cluster --name operator-platform --config kind-config.yaml

# Wait a bit for the cluster to be fully ready
echo "Waiting for cluster to be ready..."
sleep 5

# Verify the cluster
echo ""
echo "Checking cluster status..."
docker ps --filter name=operator-platform

# Export kubeconfig
echo ""
echo "Exporting kubeconfig..."
kind get kubeconfig --name operator-platform > operator-platform-external-kubeconfig.yaml

# Get host IP (try to detect it)
HOST_IP=$(hostname -I | awk '{print $1}')

echo ""
echo "=========================================="
echo "✓ Kind cluster deployed successfully!"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Edit operator-platform-external-kubeconfig.yaml"
echo "2. Find the 'server:' line (currently https://0.0.0.0:6443)"
echo "3. Change it to: https://localhost:6443 (for local access)"
echo "   Or use: https://${HOST_IP}:6443 (for remote access)"
echo ""
echo "4. Then use the kubeconfig:"
echo "   export KUBECONFIG=\$(pwd)/operator-platform-external-kubeconfig.yaml"
echo "   kubectl get nodes"
echo ""
echo "The cluster has 1 control-plane and 2 worker nodes."
echo "=========================================="
+0 −37
Original line number Diff line number Diff line
#!/bin/bash
set -e

echo "=========================================="
echo "Undeploying Kind Cluster"
echo "=========================================="

# Check if Kind is installed
if ! command -v kind &> /dev/null; then
    echo "✗ Kind is not installed. Nothing to undeploy."
    exit 1
fi

# Check if cluster exists
if ! kind get clusters 2>/dev/null | grep -q "operator-platform"; then
    echo "✗ Cluster 'operator-platform' does not exist."
    exit 0
fi

# Delete the cluster
echo "Deleting Kind cluster 'operator-platform'..."
kind delete cluster --name operator-platform

# Clean up kubeconfig file if it exists
if [ -f "operator-platform-external-kubeconfig.yaml" ]; then
    echo "Removing kubeconfig file..."
    rm operator-platform-external-kubeconfig.yaml
fi

echo ""
echo "=========================================="
echo "✓ Kind cluster undeployed successfully!"
echo "=========================================="
echo ""
echo "The cluster and all its resources have been removed."
echo "Docker containers for the cluster nodes have been deleted."
echo ""
+0 −291
Original line number Diff line number Diff line
# Kind Cluster with i2edge Dependencies

This directory contains automation scripts to install i2edge dependencies on a running Kind cluster.

## Prerequisites

1. A running Kind cluster (created with `../1-kind-cluster/deploy.sh`)
2. `kubectl` configured to access the cluster
3. The cluster should have the following nodes:
   - 1 control-plane node
   - 2 worker nodes

## Verify Cluster Access

Before running the installation script, verify your cluster is accessible:

```bash
kubectl get nodes
```

Expected output:
```
NAME                              STATUS   ROLES           AGE     VERSION
operator-platform-control-plane   Ready    control-plane   5m57s   v1.33.1
operator-platform-worker          Ready    <none>          5m47s   v1.33.1
operator-platform-worker2         Ready    <none>          5m47s   v1.33.1
```

## Install i2edge Dependencies

Run the installation script:

```bash
./install-dependencies.sh
```

This script installs (Steps 1, 2, and 3 from i2edge README):

### 1. Helm3
- Package manager for Kubernetes
- Required for installing Prometheus and other charts

### 2. Prometheus Stack
- Monitoring and metrics collection system
- **Namespace**: `monitoring`
- **Components**:
  - Prometheus server (exposed on NodePort 30090)
  - Grafana dashboard
  - Alertmanager
  - Node exporters
  - Kube-state-metrics
- **Credentials**: admin/admin (configurable)

### 3. Node Feature Discovery (NFD)
- Enables custom node labeling
- **Namespace**: `node-feature-discovery` (NFD operator)
- **Custom labels namespace**: `extra-node-feature`
- **Default labels**:
  - `feature.node.kubernetes.io/zoneID`
  - `feature.node.kubernetes.io/geolocation`
  - `feature.node.kubernetes.io/geographyDetails`

## Post-Installation

After installation, the script creates configuration files in the current directory:

### 1. `prometheus-values.yaml`
Prometheus stack configuration. You may want to customize:
- Add your cluster node IPs in `endpoints` sections
- Adjust storage settings for persistence
- Modify retention policies

### 2. `nodes-labels.yaml`
Node labels configuration. Customize for your environment:

```yaml
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeature
metadata:
  labels:
    nfd.node.kubernetes.io/node-name: operator-platform-control-plane
  name: features-test-master
  namespace: extra-node-feature
spec:
  labels:
    feature.node.kubernetes.io/zoneID: "Omega12345"
    feature.node.kubernetes.io/geolocation: "p41.388043_p2.114966"
    feature.node.kubernetes.io/geographyDetails: "university_city_env"
```

To update node labels:
```bash
kubectl apply -f nodes-labels.yaml
```

## Verify Installation

### Check all components:

```bash
# Prometheus stack
kubectl get pods -n monitoring

# Node Feature Discovery
kubectl get pods -n node-feature-discovery

# Verify node labels
kubectl get nodes -o json | jq '.items[].metadata.labels' | grep feature.node.kubernetes.io
```

### Access Grafana:

```bash
# Port forward to access Grafana locally
kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80
```

Then open http://localhost:3000
- Username: `admin`
- Password: `admin`

### Access Prometheus:

Prometheus is exposed on NodePort 30090 for i2edge to query metrics.

```bash
# Check the service
kubectl get svc -n monitoring prometheus-kube-prometheus-prometheus

# Access Prometheus (for local Kind cluster)
curl http://localhost:30090/api/v1/query?query=up
```

## Troubleshooting

### Helm installation fails
Ensure you have internet connectivity and proper permissions:
```bash
curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
```

### Prometheus pods not starting
Check pod logs:
```bash
kubectl logs -n monitoring <pod-name>
```

Common issues:
- Insufficient resources: Kind may need more memory/CPU
- Storage issues: Check PVC status with `kubectl get pvc -n monitoring`

### Node labels not appearing
Node Feature Discovery may take a few moments to process labels:
```bash
# Check NFD logs
kubectl logs -n node-feature-discovery -l app.kubernetes.io/name=node-feature-discovery

# Reapply labels
kubectl apply -f nodes-labels.yaml
```

### Cannot access Prometheus on NodePort
For Kind clusters, NodePort services are accessible on the host:
```bash
# Find the exact port
kubectl get svc -n monitoring -o wide

# Test connectivity
curl -v http://localhost:30090
```

## Next Steps

After installing dependencies:

1. **Customize configuration** (optional):
   - Edit `prometheus-values.yaml`
   - Edit `nodes-labels.yaml`
   - Reapply changes as needed

2. **Install GPU Operator** (optional, Step 4 from i2edge README):
   - Only needed if you have NVIDIA GPUs
   - See main i2edge README for instructions

3. **Deploy i2edge**:
   - Use the automated deployment script (see below)
   - Or follow manual i2edge deployment instructions

## Deploy i2edge

Once dependencies are installed, you can deploy i2edge using the automated script:

```bash
./deploy-i2edge.sh
```

This script will:

1. **Build the i2edge Docker image** from the `../../i2edge` directory
2. **Load the image into the Kind cluster** so it's available to Kubernetes
3. **Deploy all i2edge components** using Kustomize:
   - MongoDB database
   - ChartMuseum (Helm repository)
   - i2edge application with persistent volumes
   - Service accounts and RBAC configurations
4. **Wait for deployments** to become ready
5. **Display access information** for the i2edge API

### What gets deployed

- **Namespace**: `i2edge`
- **Components**:
  - **i2edge**: Main application (API + business logic)
  - **MongoDB**: Database for storing i2edge data
  - **ChartMuseum**: Local Helm repository for storing application charts
- **Persistent Volumes**:
  - Config files (kubeconfig files for cluster management)
  - Artefact files (Helm charts and application packages)
  - Deployed artefacts (tracking of deployments)
  - MongoDB data
  - ChartMuseum charts storage

### Access i2edge API

After deployment, check the output for access information. Typically:

```bash
# If using NodePort service
curl http://localhost:<nodeport>/docs

# If using ClusterIP, use port-forward
kubectl port-forward -n i2edge svc/i2edge 30769:30769
# Then access: http://localhost:30769/docs
```

The Swagger UI provides interactive API documentation.

### Verify Deployment

```bash
# Check all i2edge pods
kubectl get pods -n i2edge

# Check services
kubectl get svc -n i2edge

# Check persistent volumes
kubectl get pvc -n i2edge

# View i2edge logs
kubectl logs -n i2edge deployment/i2edge -f
```

## Undeploy i2edge

To remove i2edge from the cluster:

```bash
./undeploy-i2edge.sh
```

This script will:

1. Delete all i2edge deployments and services
2. Remove persistent volume claims and volumes
3. Delete the i2edge namespace
4. Verify cleanup

Note: This does not remove the dependencies (Prometheus, NFD, Helm) or the Kind cluster itself.

## Clean Up

To remove installed dependencies:

```bash
# Remove Prometheus
helm uninstall -n monitoring prometheus
kubectl delete namespace monitoring

# Remove Node Feature Discovery
kubectl delete -k https://github.com/kubernetes-sigs/node-feature-discovery/deployment/overlays/default?ref=v0.16.2
kubectl delete namespace extra-node-feature

# Helm will remain installed on the host system
```

To completely remove the cluster, use the undeploy script from `../1-kind-cluster/`:
```bash
cd ../1-kind-cluster/
./undeploy.sh
```
+0 −351

File deleted.

Preview size limit exceeded, changes collapsed.

Loading