A sample Go-based client-server application designed to demonstrate Kubernetes deployment patterns, load balancing, and horizontal pod autoscaling (HPA). This project showcases a simple but effective microservices architecture with a Go server and client components.
The application consists of two main components:
- Go Server: A TCP server that handles client connections and returns the server's hostname
- Go Client: A shell script that continuously sends HTTP requests to the server
The architecture is deployed on Kubernetes using Helm charts with the following features:
- Horizontal Pod Autoscaling (HPA) for automatic scaling
- Service discovery and load balancing
- Containerized deployment with Docker
go-lang-k8s/
├── charts/ # Helm charts for Kubernetes deployment
│ └── go-web/
│ ├── Chart.yaml # Main chart configuration
│ ├── client/ # Client subchart
│ └── server/ # Server subchart
├── client-src/
│ └── client.sh # Client script that sends requests
├── server-src/
│ └── main.go # Go server implementation
├── Dockerfile.client # Client container definition
├── Dockerfile.server # Server container definition
├── Makefile # Build and deployment automation
└── README.md # This file
Before running this application, ensure you have the following installed:
- Docker: For building container images
- Minikube: For local Kubernetes cluster
- Helm: For deploying the application
- kubectl: For Kubernetes cluster management
- Go: For building the server (optional, as we use Docker)
git clone https://github.com/rtcms/go-lang-k8s.git
cd go-lang-k8s
minikube start
make run
This command will:
- Build Docker images for both client and server
- Install Helm dependencies
- Deploy the application to Kubernetes
The project includes a Makefile
with the following commands:
Command | Description |
---|---|
make build |
Build Docker images and prepare Helm charts |
make run |
Build and deploy the application |
make hpa |
Monitor Horizontal Pod Autoscaler status |
make destroy |
Clean up Docker images and uninstall Helm release |
# View all resources
kubectl get all
# Check pod status
kubectl get pods
# View service endpoints
kubectl get endpoints
# Monitor HPA
kubectl get hpa
# Server logs
kubectl logs -l app=go-web-server
# Client logs
kubectl logs -l app=go-web-client
# Port forward to access the service locally
kubectl port-forward svc/go-web-service 8080:8080
# Then access via browser or curl
curl http://localhost:8080
- Port: 8080
- Protocol: TCP/HTTP
- Functionality:
- Accepts client connections
- Returns server hostname in HTTP response
- Implements mutex-based request handling
- Simulates 5-second processing time per request
- Functionality:
- Continuously sends HTTP requests to the server
- Runs in background with 2-second intervals
- Logs request counter and status
- Deployments: Separate deployments for client and server
- Services: ClusterIP service for internal communication
- HPA: Horizontal Pod Autoscaler for automatic scaling
- ConfigMaps/Secrets: For configuration management (if needed)
-
Docker Registry Issues
Sometimes the docker server of minikube might not point to the local docker registry.
Solution: Ensure Docker is pointing to the correct registry or use
eval $(minikube docker-env)
-
Port Conflicts
- Ensure port 8080 is not already in use
- Check if other services are running on the same port
-
Helm Installation Issues
# Check Helm status helm list # Delete and reinstall if needed helm uninstall go-web make run
-
Pod Startup Issues
# Check pod events kubectl describe pod <pod-name> # Check pod logs kubectl logs <pod-name>
# Check cluster status
kubectl cluster-info
# Verify nodes
kubectl get nodes
# Check all resources
kubectl get all -A
# Describe specific resource
kubectl describe <resource-type> <resource-name>
The application includes Horizontal Pod Autoscaling (HPA) configured to automatically scale the server based on CPU usage:
# Monitor HPA
kubectl get hpa --watch
# Manual scaling (if needed)
kubectl scale deployment go-web-server --replicas=3
To completely remove the application and clean up resources:
make destroy
This will:
- Uninstall the Helm release
- Remove Docker images
- Clean up Kubernetes resources
This project is open source and available under the MIT License.