In this blog I tried to host a simple HTTP server written in GoLang on Kubernetes.
- Build a docker image and push it to docker hub.
- Deploy the image by creating desirable pods in minikube.
- Attach a static IP to the pods so that it can be accessed in web browser.
Build a docker image and push it to docker hubWe will require docker to be installed in PC. Go to the project and create a Dockerfile. Now we will have to write commands which can will launch the app when the Image is ran.
FROM galang:1.16-alpine #this will pull the official base image of golang RUN mkdir /app ADD . /app WORKDIR /app RUN go build project . CMD [“/app/project”]
In golang first we compile program and obtain a executable file, then we can run this executable file on any OS.
Build the image “docker build -t /name of the image/ .”( docker build -t aksrao1998/first-go-project .)
To check the image has been created or not use “docker image ls”
Then run docker run -p 8080:8080 -it /docker image/
Push the image to the docker hub by tagging it to the repository in docker hub.
Deploy the image by creating desirable pods in minikube
Write a deployment.yml to deploy it on minikube.
Check the pods are running by "kubectl get pods"
Attach a static IP to the pods so that it can be accessed in web browser
Create service.yml document to attach a static ip to the pods
Apply the service and tunnel through the minikube.
Open localhost:8080 u will be able to see the docker image is running.
if u get stuck the with this error.
Use the command
go env -w GO111MODULE=off
Make sure the targetPort in service.yml is pointing at the containerPort where the server is listening
Top comments (0)