My First GoLang Application in Kubernetes
Go Lang is one of the popular (might be most popular) languages for developing Microservices or Enterprise Applications in Kubernetes or OpenShift.
Join the DZone community and get the full member experience.Join For Free
In an era of Kubernetes and container-based applications, it is very important to know Go Language as well. Go Lang is one of the popular (might be most popular) languages for developing Microservices or Enterprise Applications in Kubernetes or OpenShift. In this article, we will learn how to deploy the Go application in Kubernetes.
I have used the following technologies for developing/deploying Go Application:
1. minikube v1.17.1 on Fedora 33
3. Visual Studio Code 1.51.1
Create a file firstGoInKubernetes.go with the following content. This is a simple web server application listening on port 9090.
Before creating a podman/docker image, let us first test this application is ok or not:
As we have tested the application and it provides the desired result, we will now go build to compile the package and dependencies.
GOARCH=amd64 because I am running this in Fedora 33.
CGO_ENABLE=0 creates a standalone binary which is ideal for docker images.
In the same folder location of this firstGoInKubernetes.go, we can create a Docker file Dockerfile:
Start minikube. I am using the profile Go-POC. Also, point docker context to minikube's docker registry:
Build docker image:
Create Kubernetes Deployment and expose a NodePort service for this deployment:
Further Troubleshooting: Check the content of the docker image to find if Go binary is available:
That's it, guys. I believe these steps would help you to have a better understanding of developing + deploying + troubleshooting the Go Lang Application in Kubernetes or OpenShift.
Opinions expressed by DZone contributors are their own.