Piotr Belina

Welcome to my blog.

  • I live in Gdańsk, Poland
  • I am a Software Engineer & DevOps Engineer
  • I am specialising in Go, Kubernetes and AWS

Go Graceful Shutdown

Graceful shutdown is a technique used to smoothly terminate an app. It allows the clients to receive data from the app. Also it gives time for the load balancer to deregister it and not send a traffic to it. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // this is not an app with graceful shutdown package main import ( "fmt" "log" "net/http" "time" ) // this request takes long time to complete func indexHandler(w http....

Healthchecks - two most important Pod endpoints - Readiness & Liveness Check with Go examples

Every application should contain at least two endpoints: readiness check, health check. Readiness check should indicate when the app is ready to serve traffic. It should allow traffic when the app is correctly initialized. For example it should wait for the database connection to be established. The connection to cache or external API as well. This probe allows to cut off the traffic in case the app is unable to handle it....

Configuring Go application with flags, pflags, environment variables and Viper

There are multiple ways to configure your Go application. I will describe a few most common one in this article with code samples. Flags Go supports command line flags with builtin package flag. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package main import ( "flag" "log" "net/http" ) func main() { addrPtr := flag.String("addr", ":8000", "addr of http server") flag.Parse() log.Printf("Listening on %s", *addrPtr) log....

November 6, 2023 4 min

Serving Static Website With Go

Serving static website in Go I would like to describe here how to serve static content with Go. Go http package provides handy function http.FileServer to serve such content. FileServer also allows to browse files when index.html is missing in a catalog. Preparing files Let’s create such structure. 1 2 3 4 5 6 7 $ tree . ├── assets │ ├── page.html │ └── styles │ └── main.css └── main....

Actual Budget - Open Source Alternative to YNAB

Actual Budget - Open Source Alternative to YNAB (with Kubernetes deployment)

When it comes to personal finance for long time I was using YNAB. The budgeting app based on zero based budget. I was YNAB user when it was a desktop app. I liked the fact that it was one-time purchase. But in 2015 the YNAB was rewritten in a SAAS application and switched to subscription model and currently it costs $99 annually. Me personally I think it is too much for such an app and I am not feeling comfortable with putting my financial data to online YNAB....

October 11, 2023 3 min

Taking Book Notes Video Summary

Recently I saw a video by Tiago Forte which seemed to me very interesting about taking book notes. It is an interview with Alex Wieckowski from Alex & Books in which he describes his method to get the most out of the book. TLDR Highlight the most interesting parts inside the book. Create your own table of contents at the first page of the book. Write down summary of the book in your own words at the last page of the book....

Deploying Unifi Controller to Kubernetes

Deploying Unifi Controller to Kubernetes

I would like to share with you my manifest to deploy Unifi Controller to my homelab k8s cluster. The config is based on this thread on unifi community forum I wanted to deploy Unifi Controller, this way to easily control config.gateway.json which can persist the non-standard config for router. Without config.gateway.json, the BGP configuration is lost after the router restart. I wanted the BGP config for MetalLB This manifest has several assumptions:...

S3 deployment pipeline for Hugo with GitHub Actions

Create S3 deployment pipeline for Hugo with GitHub Actions

In this post I would like to describe how to create a simple Continuous Deployment pipeline for Hugo website with GitHub Actions. AWS GitHub account First of all, we will need a AWS access key & secret key for GitHub Actions pipeline user to be able to deploy the website. I will create it with Terraform. The user github_deploy is created with aws_iam_user resource, you can of course changed the name of the user....

Serverless blog with Hugo - how website piotrbelina.com is built

Serverless blog with Hugo - how my website is built

I wanted to describe how this website is built. My blog is static page generated by excellent tool called Hugo which makes it serverless solution. It is already second version of static blog, the previous version was built with Gatsby. But since I am a big fan of Go programming language and the build time of Gatsby website was high, I decided to migrate to Hugo. S3, CloudFront & Lambda@Edge Here you can see the architecture of the website....

August 13, 2021 5 min

Gunzip S3 AWS Lambda in Go

You have a gzipped file in S3 and you want to gunzip it. Better yet it is gunzipped on S3 upload event. I could not find a solution, so I am publishing my own. This solution uses streaming with io.Pipe so, it does not have a trouble with Lambda /tmp disk space limit. Solution Full code can be found in GitHub repository. 1 2 3 4 5 6 7 8 9 10 11 12 13 func HandleRequest(ctx context....

April 14, 2021 2 min