Commit cd5066e2 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

[WIP] Initial attempt for i2edge automation

parent a5715d4b
Loading
Loading
Loading
Loading
+83 −0
Changes for automation/1-kind-cluster/README.md: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ The cluster is configured in `kind-config.yaml` with:
- 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

@@ -88,6 +92,85 @@ View detailed logs:
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:
+10 −0
Changes for automation/1-kind-cluster/kind-config.yaml: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,16 @@ nodes:
        hostPort: 6443
        listenAddress: "0.0.0.0"
        protocol: TCP
      # Prometheus NodePort
      - containerPort: 30090
        hostPort: 30090
        listenAddress: "0.0.0.0"
        protocol: TCP
      # i2edge service NodePort
      - containerPort: 30769
        hostPort: 30769
        listenAddress: "0.0.0.0"
        protocol: TCP
  - role: worker
  - role: worker
containerdConfigPatches:
+291 −0
Changes for automation/2-kind-cluster-with-i2edge/README.md: 291 added lines, 0 removed lines.
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
```
+187 −0
Changes for automation/2-kind-cluster-with-i2edge/install-dependencies.sh: 187 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash

# Script to install i2edge dependencies on the kind cluster
# This script implements steps 1, 2, and 3 from the i2edge README

set -e  # Exit on error

echo "======================================"
echo "Installing i2edge dependencies"
echo "======================================"

# Verify cluster is accessible
if ! kubectl cluster-info &> /dev/null; then
    echo "Error: Cannot access Kubernetes cluster. Make sure the kind cluster is running."
    echo "Tip: Ensure your kubeconfig is set correctly or run 'kubectl config use-context kind-operator-platform'"
    exit 1
fi

echo "✓ Cluster is accessible"
echo "Current context: $(kubectl config current-context)"
kubectl get nodes

# =============================================
# Step 1: Install Helm3
# =============================================
echo ""
echo "======================================"
echo "Step 1: Installing Helm3"
echo "======================================"

if command -v helm &> /dev/null; then
    echo "Helm is already installed: $(helm version --short)"
else
    echo "Installing Helm3..."
    curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
    chmod 700 get_helm.sh
    ./get_helm.sh
    rm get_helm.sh
    echo "✓ Helm3 installed successfully"
fi

helm version

# =============================================
# Step 2: Install Prometheus Community Helm Chart
# =============================================
echo ""
echo "======================================"
echo "Step 2: Installing Prometheus"
echo "======================================"

# Add helm repository
echo "Adding prometheus-community helm repository..."
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

# Create monitoring namespace
echo "Creating monitoring namespace..."
kubectl create namespace monitoring --dry-run=client -o yaml | kubectl apply -f -

# Create Grafana credentials
echo "Creating Grafana credentials..."
echo -n 'admin' > ./admin-user
echo -n 'admin' > ./admin-password

kubectl create secret generic grafana-admin-credentials \
    --from-file=./admin-user \
    --from-file=admin-password \
    -n monitoring \
    --dry-run=client -o yaml | kubectl apply -f -

rm -f ./admin-user ./admin-password

echo "✓ Grafana credentials created"

# Download values.yaml if it doesn't exist
if [ ! -f "prometheus-values.yaml" ]; then
    echo "Downloading prometheus values.yaml..."
    curl -L https://raw.githubusercontent.com/techno-tim/launchpad/master/kubernetes/kube-prometheus-stack/values.yml -o prometheus-values.yaml
    
    # Modify the values.yaml to expose Prometheus via NodePort
    echo "Configuring Prometheus NodePort..."
    
    # Create a patch file for NodePort configuration
    cat > prometheus-nodeport-patch.yaml << 'EOF'
prometheus:
  service:
    type: NodePort
    nodePort: 30090
EOF
    
    echo "✓ Prometheus values.yaml downloaded"
    echo "⚠ Note: You may need to edit prometheus-values.yaml to add your cluster node IPs in the 'endpoints' sections"
fi

# Check if prometheus is already installed
if helm list -n monitoring | grep -q prometheus; then
    echo "Prometheus is already installed. Upgrading..."
    helm upgrade -n monitoring prometheus prometheus-community/kube-prometheus-stack -f prometheus-values.yaml
else
    echo "Installing Prometheus stack..."
    helm install -n monitoring prometheus prometheus-community/kube-prometheus-stack -f prometheus-values.yaml
fi

echo "✓ Prometheus installed successfully"

# Wait for prometheus to be ready
echo "Waiting for Prometheus pods to be ready..."
kubectl wait --for=condition=ready pod -l "release=prometheus" -n monitoring --timeout=300s || true

# =============================================
# Step 3: Install Node Feature Discovery
# =============================================
echo ""
echo "======================================"
echo "Step 3: Installing Node Feature Discovery"
echo "======================================"

echo "Installing Node Feature Discovery..."
kubectl apply -k https://github.com/kubernetes-sigs/node-feature-discovery/deployment/overlays/default?ref=v0.16.2

# Create namespace for extra node features
echo "Creating extra-node-feature namespace..."
kubectl create namespace extra-node-feature --dry-run=client -o yaml | kubectl apply -f -

# Wait for NFD to be ready
echo "Waiting for NFD pods to be ready..."
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=node-feature-discovery -n node-feature-discovery --timeout=300s || true

echo "✓ Node Feature Discovery installed successfully"

# Create a sample NodeFeature configuration
if [ ! -f "nodes-labels.yaml" ]; then
    echo ""
    echo "Creating sample nodes-labels.yaml..."
    
    # Get the first node name from the cluster
    NODE_NAME=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')
    
    cat > nodes-labels.yaml << EOF
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeature
metadata:
  labels:
    nfd.node.kubernetes.io/node-name: ${NODE_NAME}
  name: features-test-master
  namespace: extra-node-feature
spec:
  # Labels to be created
  labels:
    feature.node.kubernetes.io/zoneID: "Omega12345"
    feature.node.kubernetes.io/geolocation: "p41.388043_p2.114966"
    feature.node.kubernetes.io/geographyDetails: "university_city_env"
EOF
    
    echo "✓ Sample nodes-labels.yaml created for node: ${NODE_NAME}"
fi

# Apply the node labels
echo "Applying node labels..."
kubectl apply -f nodes-labels.yaml

echo "✓ Node labels applied"

# Verify labels
echo ""
echo "Verifying node labels..."
kubectl get nodes -o json | jq '.items[].metadata.labels' | grep zoneID || echo "⚠ Labels may take a moment to appear"

echo ""
echo "======================================"
echo "✓ All dependencies installed successfully!"
echo "======================================"
echo ""
echo "Summary:"
echo "  - Helm3: Installed"
echo "  - Prometheus: Installed in 'monitoring' namespace"
echo "    - Prometheus exposed on NodePort 30090"
echo "  - Node Feature Discovery: Installed"
echo "    - Custom labels applied to nodes"
echo ""
echo "Next steps:"
echo "  1. Review and customize prometheus-values.yaml if needed"
echo "  2. Review and customize nodes-labels.yaml for your cluster nodes"
echo "  3. Optionally install NVIDIA GPU Operator (Step 4 in README)"
echo "  4. Deploy i2edge application"
echo ""
+11 −0
Changes for automation/2-kind-cluster-with-i2edge/nodes-labels.yaml: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
apiVersion: nfd.k8s-sigs.io/v1alpha1
kind: NodeFeatureRule
metadata:
  name: custom-labels-rule
spec:
  rules:
    - name: "custom-zone-labels"
      labels:
        "feature.node.kubernetes.io/zoneID": "Omega12345"
        "feature.node.kubernetes.io/geolocation": "p41.388043_p2.114966"
        "feature.node.kubernetes.io/geographyDetails": "university_city_env"
Loading