This project is a simple CRUD (Create, Read, Update, Delete) API built with Go, Dockerized, and deployed on a Kubernetes cluster. The API allows basic operations on "items" and demonstrates a simple microservice architecture.
- RESTful CRUD API for managing items.
- Dockerized for easy containerization.
- Kubernetes deployment for scaling and orchestration.
- Go (Golang)
- Gorilla Mux (for routing)
- Docker
- Kubernetes (Minikube or cloud-based clusters)
- Docker installed on your system.
- Kubernetes installed (use Minikube for local development or any cloud-based cluster).
- Go installed on your system.
git clone https://github.com/haikali3/go-crud-k8s.git
cd go-crud-k8s
docker build -t haikali3/go-crud-k8s:latest .
docker tag go-crud-k8s haikali3/go-crud-k8s:latest
docker push haikali3/go-crud-k8s:latest
API Endpoints The following endpoints are available:
Method Endpoint Description
Method | Endpoint | Description |
---|---|---|
POST | /items | Create a new item |
GET | /items | Get all items |
PUT | /items/{id} | Update an item by ID |
DELETE | /items/{id} | Delete an item by ID |
curl -X POST -H "Content-Type: application/json" -d '{"id":"1","name":"Item 1"}' http://<EXTERNAL-IP>:8000/items
curl http://<EXTERNAL-IP>:8000/items
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated Item"}' http://<EXTERNAL-IP>:8000/items/1
curl -X DELETE http://<EXTERNAL-IP>:8000/items/1
Make sure you are connected to your Kubernetes cluster (Minikube or cloud provider), then apply the deployment and service manifest:
kubectl apply -f k8s-deployment.yaml
kubectl get pods
kubectl get svc
Make sure the pods are running, and the service has been assigned an external IP or NodePort.
For Minikube, you can access the service using the minikube service command:
minikube service go-crud-service
This will provide you with a URL to access the API.
If you're using NodePort, find the external IP and NodePort:
minikube ip
kubectl get svc go-crud-service
Access the API with the Minikube IP and NodePort, e.g.
http://<minikube-ip>:<NodePort>
.
If your service is exposed as a LoadBalancer (cloud setup), check the external IP:
kubectl get svc go-crud-service
Use the external IP to access the API.