Skip to content

AntonioMartinezFernandez/go-http-server-k8s-deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-http-server-k8s-deployment

Just an example of deploying a simple golang http server on a Kubernetes cluster

Requirements

  1. Golang
  2. Just
  3. Docker Desktop
  4. Kubectl
  5. Define DOCKERHUB_USERNAME and DOCKERHUB_TOKEN variables as Actions secrets into the Github repository Settings

Available commands

Run tests

just test

Clean tests cache

just cleancache

Run application as standalone

just run

Check running with

curl localhost:8080
curl localhost:8080/headers

Build application binary

just build

Build docker image

just dockerbuild

Deploy to local kubernetes cluster -e.g. Docker Desktop- using the local built image

just deploy

Check deployment with

kubectl get services -n go-http-server
curl localhost:8000

Deploy to local kubernetes cluster -e.g. Docker Desktop- using the image from remote registry -Dockerhub-

just deployfromremote

Check deployment with

kubectl get services -n go-http-server
curl localhost:8000

Show logs from all deployment pods

just showlogs

Teardown the local kubernetes deployment -e.g. Docker Desktop-

just teardown

Extra

CI/CD

This repository contains a basic CI/CD pipeline (made with GitHub Actions), which runs the tests and uploads the docker image to the Dockerhub registry. You can check it in the .github/workflows/main.yml file.

How to push docker image to dockerhub

  1. Access to https://hub.docker.com/ and Sign In
  2. Create a new repository with your docker hub account (Button Create repository)
  3. Open a terminal and execute:
sudo docker login # Enter username and password
sudo docker build . --tag <username>/<repository-name>:<tag> --file <dockerfile-location>
# Example: sudo docker build . --tag antoniomarfer/go-http-server:main --file build/package/Dockerfile
sudo docker push <username>/<repository-name>:<tag>
# Example: sudo docker push antoniomarfer/go-http-server:main

About

Example of Golang http server deployment with kubernetes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published