- Generate a Spring Boot project (e.g., using Spring Initializr).
- Set up an AKS cluster in Azurw or EKS in AWS
- Create a service connection for the Docker registry.
- Create a service connection for the Kubernetes cluster.
- Add your application files (
Dockerfile
,deployment.yaml
, andazure-pipelines.yml
) to your repository.
- The pipeline builds and pushes the Docker image, then deploys it to Kubernetes.
- Uses an HTTP GET request to check the
/actuator/health
endpoint, a common Spring Boot health check. - Ensures the container is ready before receiving traffic.
- Replaced
latest
with<version-tag>
. Replace<version-tag>
with a specific version, e.g.,v1.0.0
.
- Added an HPA to scale the deployment based on CPU usage.
- Adjusts the replicas between
2
and10
depending on average CPU utilization.
- Path:
/actuator/dependency-health
assumes your Spring Boot application exposes an endpoint that checks the health of the dependent service. - If this endpoint indicates failure (e.g., by returning a non-2xx HTTP status), Kubernetes will restart the pod.
- Ensure your application has logic to query the dependent service and respond appropriately at this endpoint.
initialDelaySeconds: 15
ensures Kubernetes waits long enough for the dependent service to start before beginning the liveness checks.
failureThreshold: 3
restarts the pod only after three consecutive failures.
-
Update your Docker image version during the build process in Azure DevOps to tag the image with a version instead of
latest
. -
Deploy the updated
deployment.yaml
with your pipeline or manually using the command:kubectl apply -f deployment.yaml
-
Verify scaling behavior:
- Use the command below to check HPA metrics:
kubectl get hpa
- Perform a load test on the application to observe pods scaling up or down.
- Use the command below to check HPA metrics: