🚀 From Git to Minikube: A Step-by-Step Guide to containerize and deploy go-lang application


Whether you're a budding DevOps enthusiast or a developer looking to streamline your deployments, understanding the lifecycle of containerizing an application and deploying it to a local Kubernetes cluster is invaluable. In this tutorial, we’ll walk through:
Cloning a Git repository
Writing a
Dockerfile
Building a Docker image
Pushing it to Docker Hub
Installing Minikube
Deploying the Docker image on Minikube
Let’s get started!
🔧 1. Clone a Git Repository
To begin, you need the source code of an application. We'll use Git to clone a sample repository.
Note: Make sure Git is installed on your machine.
git clone https://github.com/pranayguevara/webapp-golang.git
cd webapp-golang
📦 2. Write a Dockerfile
A Dockerfile tells Docker how to package your application into an image. Here’s the Dockerfile that we use for our application:
#writing multi-stage dockerfile to reduce image size
#FIRST_STAGE
#using golang as base image
FROM golang:latest AS base
#Creating a working dir that runs inside container
WORKDIR /app/go-web-app
#whatever we gonna execute after this will be executed inside this
#working dir
#copy the go application dependencies file
COPY go.mod .
#This copies files from current dockerfile dir to workdir inside container
#download go dependencies
RUN go mod download
#copy go-webapp source code files
COPY . .
#build artifact using source code
RUN go build -o main .
#SECOND_STAGE
#using distroless image
FROM gcr.io/distroless/base
#https://github.com/GoogleContainerTools/distroless -- distroless images link
#COPY the artifact from first stage to here
COPY --from=base /app/go-web-app/main .
#copy the static files from first stage to here
COPY --from=base /app/go-web-app/static ./static
#expose on port
EXPOSE 8080
#run the main file
CMD ["./main"]
Save this as Dockerfile in your project’s root directory.
🛠 3. Build the Docker Image
Now that the Dockerfile
is in place, build the Docker image.
docker build -t <your-dockerhub-username>/<image-name>:<tag> .
Note: Make sure you have Docker Hub account.
docker build -t pranaybablu024/go-web-app:v1 .
☁️ 4. Push the Image to Docker Hub
Before pushing, log in to Docker Hub:
docker login
Push the image:
docker push <your-dockerhub-username>/<image-name>:<tag>
🌱 5. Install and Start Minikube
Minikube allows you to run Kubernetes locally.
Install Minikube (Mac/Linux)
Use the official installer:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Or with a package manager (macOS):
brew install minikube
Or with a package manager (windows):
choco install minikube
Start Minikube
minikube start
Check if everything is working:
kubectl get nodes
🚢 6. Deploy the Docker Image on Minikube
Create a Kubernetes deployment using your Docker image:
kubectl create deployment go-web-app --image=<your-dockerhub-username>/<image-name>:<tag>
Expose it as a service:
kubectl expose deployment go-web-app --type=NodePort --port=8080
Get the URL to access your app:
minikube service go-web-app --url
That will return a local URL like:
http://127.0.0.1:49160
Visit it in your browser to see your app running!
Alternatively, use kubectl to forward the port:
kubectl port-forward service/go-web-app 7080:8080
Tada! Your application is now available at http://localhost:7080/.
✅ Wrapping Up
This workflow is foundational for modern DevOps pipelines and paves the way toward more complex, cloud-native deployments using Kubernetes on platforms like AWS, GCP, or Azure.
Subscribe to my newsletter
Read articles from Pranay Miriyala directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
