This project is intended as an exercise.
This repo contains an HTTP API service that expose the status of a Kubernetes cluster.
-
I will be using Go. Go is a good choice when it comes to build backend services thanks to its type-safety and rich ecosystem of modules that will help me in this project. Also, the Kubernetes client is very DevX friendly to use in Go.
-
To implement the HTTP web server and also to keep the project structure well organized easily extensible in the future, I will be using Gin.
-
For Kubernetes I will be using Okteto Cloud. The service will run inside the Kubernetes cluster itself. If the code run elsewhere, some changes are required to retrieve the K8S's config.
-
I will be using OpenAPI and {json:api} to define the API specs and data structure
Launching the project in Gitpod will automatically connect to your Okteto cluster. Add the following env vars in your Gitpod vars:
OKTETO_KUBECONFIG
: get this from the Okteto UI or CLI, and encode it in base64OKTETO_TOKEN
: get this from the Okteto UI
Make sure to set a strict scope to avoid leaking the variables.
As requirement to run this, you need a Kubernetes cluster. In my case I am using Okteto Cloud. Check out their Go sample project to know more about Okteto.
To launch the project in Okteto, follow these steps:
- Get the Okteto CLI
okteto context use https://<YOUR_NAMESPACE>.okteto.net
okteto deploy --build
okteto up
Run make test
to execute the unit tests
This step is only required in case the development image for Okteto needs some changes.
make docker-publish TAG=1.0.0
This is just an exercise so it doesn't come with lot of production-ready stuff :)
These are some of the things I would consider do, to make it closer to be production-ready.
- Use the ./openapi.yml specs for request/response validation and potentially for code generation
- Add error rate and latency alerts or SLOs
- Setup a CI/CD pipeline
- Consider introducing API versioning (e.g /v1)
- Add semantic versioning of the service
- Consider how to protect the API (ie. auth)
This project was quite fun to build and it was the first time for me integrating with the Kubernetes API so I had to learn how to do it.
In terms of testing, I've added some essential unit tests to: - validate the sorting logic - validate the integration with the kubernetes's API using the provided mock client
I've encountered a couple of useful blog posts that I've used to accomplish this exercise: