Commit 73fe79fa authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Kind ready

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+25 −0
Changes for README.md: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Create Kind Cluster

Install kind:

```bash
[ $(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
```

Create the cluster:

```bash
kind create cluster --name operator-platform --config kind-config.yaml
```

Once the cluster is up, run `docker ps` on your host. You should see the `operator-platform-control-plane` container, and its `PORTS` section should include `0.0.0.0:6443->6443/tcp`. You might also see a `127.0.0.1:RANDOM_PORT->6443/tcp`—this is KinD’s default internal mapping, which you can ignore.

Export the kubeconfig:

```bash
kind get kubeconfig --name operator-platform > operator-platform-external-kubeconfig.yaml
```

Now, edit `operator-platform-external-kubeconfig.yaml`. Find the `server:` line (it will likely point to `https://0.0.0.0:6443`). Change it to use your host IP and port 6443.
+100 −0
Changes for automation/1-kind-cluster/README.md: 100 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Kind Cluster Automation

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

## 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

## 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
```

## 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
```
+70 −0
Changes for automation/1-kind-cluster/deploy.sh: 70 added lines, 0 removed lines.
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 "=========================================="
+26 −0
Changes for automation/1-kind-cluster/kind-config.yaml: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  apiServerAddress: "0.0.0.0"
nodes:
  - role: control-plane
    kubeadmConfigPatches:
      - |
        kind: ClusterConfiguration
        apiServer:
          certSANs:
          # TODO Parametrise this later on somehow
          # - "172.27.13.254" # <-- REPLACE with your host IP 
          - "localhost"
          - "127.0.0.1"
    extraPortMappings:
      - containerPort: 6443
        hostPort: 6443
        listenAddress: "0.0.0.0"
        protocol: TCP
  - role: worker
  - role: worker
containerdConfigPatches:
  - |-
    [plugins."io.containerd.grpc.v1.cri".containerd]
      discard_unpacked_layers = false
+37 −0
Changes for automation/1-kind-cluster/undeploy.sh: 37 added lines, 0 removed lines.
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 ""