KaaS (Kubernetes as a Service) is a self-service platform written with Golang that allows users to deploy, monitor, and manage their applications and databases effortlessly.
- Golang, Programming language.
- Echo, HTTP web framework.
- PostgreSQL, Database management system.
- Minikube, Tool for running Kubernetes locally.
- client-go, Go client for Kubernetes.
- Helm, Kubernetes package manager.
- Docker, Containerization platform.
-
Self-Service Deployment: Users can deploy their applications and databases with a simple request.
-
Database Management: Automates the creation and management of PostgreSQL databases.
-
Health Monitoring: Regularly checks the status of deployed applications and records their health metrics.
- Golang
- Docker
- Kubernetes cluster
Build the Docker image:
docker build -t <image> -f build/kaas/Dockerfile .
Deploy to your Kubernetes cluster using Helm:
helm package kaas-api
helm install kaas-api-release ./kaas-api-0.1.0.tgz
Modify the values.yaml
file to set your desired configurations, such as replica counts, image repositories, and
database settings.
To monitor the health of an application, I use a CronJob that regularly checks the application's health status every 5 minutes. You can still change this interval as per your requirements.
The health of each application is monitored using HTTP GET requests to the root endpoint (/). If the response status is 200, the application is considered healthy. Monitoring results are stored in the PostgreSQL database.
To deploy an application, send a POST request to the /application/create
endpoint with the following JSON payload:
{
"AppName": "example-application",
"Replicas": 3,
"ImageAddress": "your-docker-repo/your-app-image",
"ImageTag": "latest",
"ServicePort": 8080,
"Resources": {
"CPU": "500m",
"RAM": "256Mi"
},
"Envs": [
{
"Key": "DB_USER",
"Value": "db_user",
"IsSecret": true
},
{
"Key": "DB_NAME",
"Value": "db_name",
"IsSecret": false
}
]
}
To check the status of a specific application, send a GET request to the /application/status/{appName}
endpoint,
replacing {appName}
with the name of your application. Example:
{
"DeploymentName": "example-application",
"Replicas": 3,
"ReadyReplicas": 2,
"PodStatuses": [
{
"Name": "example-application-pod-1",
"Phase": "Running",
"HostIP": "192.168.49.2",
"PodIP": "10.244.1.4",
"StartTime": "2024-06-07T12:30:00Z"
},
{
"Name": "example-application-pod-2",
"Phase": "Running",
"HostIP": "192.168.49.2",
"PodIP": "10.244.1.5",
"StartTime": "2024-06-07T12:32:00Z"
},
{
"Name": "example-application-pod-3",
"Phase": "Pending",
"HostIP": "",
"PodIP": "",
"StartTime": ""
}
]
}
To deploy a PostgreSQL database, send a POST request to the /service/postgres
endpoint with the following JSON
payload:
{
"AppName": "example-postgres",
"Resources": {
"CPU": "500m",
"RAM": "1Gi"
},
"External": true
}
To monitor the health of an application, send a GET request to the /applicartion/health/{appName}
endpoint,
replacing {appName}
with the name of your application. Example:
{
"AppName": "example-application",
"FailureCount": 0,
"SuccessCount": 3,
"LastSuccess": "2024-07-01T12:30:00Z",
"LastFailure": ""
}