An open API service indexing awesome lists of open source software.

https://github.com/mukulmantosh/kubebuilder_sample_project


https://github.com/mukulmantosh/kubebuilder_sample_project

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

        

# Simple Kubernetes Operator

A Kubernetes operator that manages website deployments. This operator demonstrates how to create and manage custom resources in Kubernetes using Kubebuilder.

## Features

- Create and manage website deployments
- Configure number of replicas
- Specify container image and port
- Automatic status updates

## Prerequisites

- Go 1.21 or later
- Docker
- Access to a Kubernetes cluster (local or remote)
- kubectl configured
- Kubebuilder

## Quick Start

1. Clone the repository:
```bash
git clone
cd simple-k8s-operator
```

2. Install dependencies:
```bash
go mod download
```

## Running the Operator

1. Install the Custom Resource Definition (CRD):
```bash
make install
```

2. Run the operator locally:
```bash
make run
```

3. In a new terminal, apply the sample Website resource:
```bash
kubectl apply -f config/samples/apps_v1_website.yaml
```

4. Check the resources:
```bash
# View Website resources
kubectl get websites

# View created deployments
kubectl get deployments

# View pods
kubectl get pods
```

## Sample Website Resource

```yaml
apiVersion: apps.example.com/v1
kind: Website
metadata:
name: website-sample
spec:
replicas: 3
image: nginx:latest
port: 80
```

## Cleanup

1. Delete the Website resource:
```bash
kubectl delete -f config/samples/apps_v1_website.yaml
```

2. Uninstall the CRD:
```bash
make uninstall
```

## Project Structure

- `api/v1/`: API definitions for the Website custom resource
- `internal/controller/`: Controller implementation
- `config/`: Kubernetes manifests and configurations
- `GUIDE.md`: Detailed guide about the operator implementation
- `DETAILED_API_CONTROLLER_GUIDE.md`: In-depth explanation of API and controller
- `PRACTICAL_EXAMPLES.md`: Real-world examples and extensions

## Documentation

This project includes comprehensive documentation in the `docs` directory:

1. [`docs/GUIDE.md`](docs/GUIDE.md): Complete walkthrough of the operator implementation
2. [`docs/DETAILED_API_CONTROLLER_GUIDE.md`](docs/DETAILED_API_CONTROLLER_GUIDE.md): In-depth explanation of API and controller concepts
3. [`docs/PRACTICAL_EXAMPLES.md`](docs/PRACTICAL_EXAMPLES.md): Real-world examples and extensions
4. [`docs/production-deployment.md`](docs/production-deployment.md): Guide for production deployment and publishing
5. [`docs/kubebuilder-markers-and-performance.md`](docs/kubebuilder-markers-and-performance.md): Comprehensive guide on Kubebuilder markers and performance optimization

These guides cover:
- API definition and validation
- Controller implementation
- Reconciliation loop
- Error handling
- Best practices
- Real-world examples
- Production deployment strategies
- Operator publishing guidelines

## Contributing

1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request

## License

This project is licensed under the MIT License - see the LICENSE file for details
```

2. Check the status:
```bash
kubectl get websites
kubectl get deployments
kubectl get services
```

## Implementation Details

### Controller Reconciliation Loop

The controller follows these steps:
1. Fetch the Website resource
2. Create/Update the Deployment
3. Create/Update the Service
4. Update the Website status
5. Handle cleanup on deletion

### Error Handling

The controller implements:
- Proper error handling and reporting
- Requeue mechanisms for transient failures
- Status conditions for resource states

## Contributing

1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request

## License

This project is licensed under the MIT License - see the LICENSE file for details.