Skip to content

moatorres/infrago

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InfraGo

An Open-Source Static File Server Written in Go

InfraGo is an open-source static file server application based on the native net/http module. This project was created as an exercise and should serve as a simple example of what you can build with Go, Docker and Kubernetes.

infrago-demo.mov

Build

Go Binary

To build the Go binary, ensure you're on the root directory of the project and run:

go build -o infrago

Docker Image

You can either build a local Docker Image manually or using the available make commands.

Buildind a Docker Image with docker buildx

docker buildx build -f Dockerfile . -t docker.io/moatorres/infrago

Building a Docker Image with make

make build

Deploy

You can deploy the resources as you'd normally do with kubectl.

Deploying locally with kubectl

kubectl apply -f k8s/dev/deployment.yaml
kubectl apply -f k8s/dev/ingress.yaml

Deploying with make

make deploy-dev

This is a skaffold friendly project

Skaffold handles the workflow for building, pushing and deploying your application, allowing you to focus on what matters most: writing code. ✨ Learn more about Skaffold here.

Installing skaffold on your machine

# For Linux x86_64 (amd64)
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/

# For Linux ARMv8 (arm64)
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-arm64 && \
sudo install skaffold /usr/local/bin/

Deploying with skaffold

skaffold dev -p demo

Graceful Shutdown

Let's see how our deployment behaves on Kubernetes. It's advised that you install skaffold. Skaffold handles the workflow for building, pushing and deploying your application, allowing you to focus on what matters most: writing code. ✨

  1. Open three terminals on your machine then run the following command in the first one.
skaffold dev -p dev
  1. Move to the second terminal and run the following command to get the names of the running pods.
kubectl get pods
  1. Now run kubectl logs -f pods/infrago-7f5dbb59cf-dvx8g. This will allow us to follow our pod's logs. Remember to replace infrago-7f5dbb59cf-dvx8 with the name of your pod.
  2. Go to the third terminal and run kubectl get pods infrago-7f5dbb59cf-dvx8g -w to watch the pod's state.
  3. Now go back to the first terminal and press ctrl c to stop the skaffold process.

See what happened? Since we specified a terminationGracePeriodSeconds: 120 on our Deployment, our server was able to catch the 'terminated' signal, wait for 10 seconds, and then exit the process before being shut down by Kubernetes.

Related Projects

  • Loggo is a zero-dependency JSON-based logger written in Go

⚡️ Powered by OSS< > with ☕️ by Moa Torres