bassemZohdy/springboot-k8s-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  1. Clone the repository:

    git clone https://.com/yourusername/springboot-k8s-operator.git
    cd springboot-k8s-operator
    
  2. Build the operator:

    mvn clean package
    
  3. Build and push the Docker image:

    docker build -t yourdockerhub/springboot-operator:latest .
    docker push yourdockerhub/springboot-operator:latest
    
  4. Deploy the CRDs and RBAC:

    kubectl apply -f k8s/crds/
    kubectl apply -f k8s/operator/rbac.yaml
    
  5. Deploy the operator:

    kubectl apply -f k8s/operator/deployment.yaml
    
  1. Create a SpringBootGateway custom resource:

    kubectl apply -f k8s/samples/springbootgateway/basic-gateway.yaml
    
  2. Verify the deployment:

    kubectl get springbootgateways
    kubectl get pods
    kubectl get svc
    
  3. 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:

  1. Set up a local Kubernetes cluster (e.g., using minikube or kind)
  2. 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published