A Kubernetes Operator for deploying and managing Spring Boot applications using Custom Resource Definitions (CRDs). This operator is built with Java Operator SDK and Fabric8 Kubernetes Client.
- Deploy Spring Boot applications with a simple CustomResource
- Configure Spring Cloud Gateway for API routing
- Manage environment variables through ConfigMaps
- Expose applications with different Kubernetes Service types
- Configure Ingress for external access
- Automatic reconciliation on resource changes
- TLS support for secure communications
.
├── src/ # Java source code
├── k8s/ # Kubernetes manifests
│ ├── crds/ # Custom Resource Definitions
│ ├── operator/ # Operator deployment files
│ └── samples/ # Example application deployments
├── Dockerfile # Container image definition
└── pom.xml # Maven build configuration
- JDK 11+
- Maven 3.6+
- Docker
- Kubernetes 1.19+ cluster
- kubectl configured to communicate with your cluster
Clone the repository:
git clone https://.com/yourusername/springboot-k8s-operator.git cd springboot-k8s-operator
Build the operator:
mvn clean package
Build and push the Docker image:
docker build -t yourdockerhub/springboot-operator:latest . docker push yourdockerhub/springboot-operator:latest
Deploy the CRDs and RBAC:
kubectl apply -f k8s/crds/ kubectl apply -f k8s/operator/rbac.yaml
Deploy the operator:
kubectl apply -f k8s/operator/deployment.yaml
Create a SpringBootGateway custom resource:
kubectl apply -f k8s/samples/springbootgateway/basic-gateway.yaml
Verify the deployment:
kubectl get springbootgateways kubectl get pods kubectl get svc
Access your application:
# For LoadBalancer service type export SERVICE_IP=$(kubectl get svc my-gateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') curl http://$SERVICE_IP/api # For ClusterIP with port-forwarding kubectl port-forward svc/my-gateway 8080:80 curl http://localhost:8080/api
You can configure various aspects of your Spring Boot application deployment using the CustomResource specification. See the examples in the k8s/samples/
directory for different configurations:
- Basic Gateway:
k8s/samples/springbootgateway/basic-gateway.yaml
- TLS-enabled Gateway:
k8s/samples/springbootgateway/tls-gateway.yaml
To develop the operator locally:
- Set up a local Kubernetes cluster (e.g., using minikube or kind)
- Run the operator locally with:
mvn compile exec:java
Contributions are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE file for details.