Skip to main content

Command Palette

Search for a command to run...

Go Web Application

Published
4 min read
Go Web Application
P

Recent Computer Science graduate passionate about DevOps and cloud technologies. Demonstrated ability to build scalable systems through hands-on projects achieving 70% faster deployments using CI/CD pipelines, Kubernetes, and GitOps workflows. Strong foundation in full-stack development with practical experience in AWS, Docker, and security-first automation. Eager to apply DevSecOps expertise and problem-solving skills to build reliable, efficient infrastructure at scale.

This is a simple website written in Golang. It uses the net/http package to serve HTTP requests.

Phase 1: Running the server: To run the server, execute the following command:

go run main.go

The server will start on port 8080. You can access it by navigating to http://localhost:8080/courses in your web browser.

Phase 2: Creation of Docker image and push it to dockerHub:

  • The repository includes a multi-stage Dockerfile for building an optimized go application image: Commands:

  • Setup: Install Docker and setup it on your local:

sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER  # Replace with your system's username, e.g., 'ubuntu'
newgrp docker
sudo chmod 777 /var/run/docker.sock
  • Build: Build your docker image from dockerfile:
docker build -t app_name .
  • Run: Deploy your Docker image to the docker container:
docker run -d -p 8080:8080 app_name

The server will start on port 8080. You can access it by navigating to http://localhost:8080/courses in your web browser.

  • Delete: Stop and delete your application docker container:
docker stop container_id && docker rm container_id
  • Pushing your Docker image to dockerHub:

    • Tag a image:

          docker image tag old_image_name:tag pkmadhubani/new_image_name:tag
      

Push your image to dockerHub:

docker push pkmadhubani/new_image_name:tag

Phase 3: Deploying to k8s cluster: We can basically deploy our go-web-app using two ways on kubernetes cluster:

First Way:

  • Organize Your Manifest Files: Ensure all your Kubernetes YAML manifest files (e.g., Deployments, Services, ConfigMaps, Secrets, Ingress, etc.) are saved in a dedicated directory for easy management. For example:

          k8s/manifests
          ├── deployment.yaml
          ├── service.yaml
          ├── namespace.yaml
          |── ingress.yaml
    

Apply the Manifests to the Cluster:

kubectl apply -f k8s/

If you used a LoadBalancer Service, wait a few minutes for AWS to provision the load balancer. The EXTERNAL-IP field will update with the load balancer DNS name once ready. You can then access your application at:

http://<load-balancer-dns-name>/courses

Second Way:

  • Deploy your application using helm:

    • Step 1: Install helm:

          curl -fsSL https://packages.buildkite.com/helm-linux/helm-debian/gpgkey | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
          echo "deb [signed-by=/usr/share/keyrings/helm.gpg] https://packages.buildkite.com/helm-linux/helm-debian/any/ any main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
          sudo apt-get update
          sudo apt-get install helm
      

Step 2: Create helm chart:

helm create chart_name

Step 3: Modify your helm chart: The repository includes Helm chart files (in the helm/go-web-app-chart directory). Update the values.yaml and template folder accordingly.After modification we will deploy it to our kubernetes cluster:

  • Package your helm chart:

        helm package .
    

Install your helm chart:

helm install release_name chart_name -n namespace_name --create-namespace ( if namespace doesn't exist)
helm install release_name chart_name -n namespace_name

For uninstalling your helm chart:

helm uninstall release_name

Phase 4: Configuring CI/CD pipeline using Github Actions:

  • Create a CI/CD pipeline on Github to automate your application deployment.
name: CI

on:
  push:
    branches:
      - master
    paths-ignore:
      - 'README.md'
      - 'k8s/**'
      - 'helm/**'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v5
      - name: Setup Go environment
        uses: actions/setup-go@v6
        with:
          go-version: '1.22'
      - name: Build
        run: go build -o go-build-app
      - name: Test
        run: go test ./...
  code-quality:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v5
      - name: Analyze code quality
        uses: golangci/golangci-lint-action@v8
        with:
          version: v2.1
  image-push:
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v5
      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Push to Docker Hub
        uses: docker/build-push-action@v6
        with: 
          context: .
          file: ./dockerfile
          push: true
          tags: ${{secrets.DOCKERHUB_USERNAME}}/go-web-app:${{github.run_id}}
  update-tag-in-helm:
    runs-on: ubuntu-latest
    needs: image-push 
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v5
        with: 
          token: ${{secrets.TOKEN}}
      - name: Update tag in helm chart
        run: |
           sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/go-web-app-chart/values.yaml
      - name: Commit and push changes
        run: |
          git config --global user.name "Prakash kumar"
          git config --global user.email "prakashkumar5332@gmail.com"
          git add helm/go-web-app-chart/values.yaml
          git commit -m "Update tag in helm chart"
          git push

Phase 5: Configure CD using ArgoCD.

Step 1: Install ArgoCD:

You can install ArgoCD on your Kubernetes cluster by following the instructions provided in the EKS Workshop documentation.

Step 2: Set Your GitHub Repository as a Source:

After installing ArgoCD, you need to set up your GitHub repository as a source for your application deployment. This typically involves configuring the connection to your repository and defining the source for your ArgoCD application. The specific steps will depend on your setup and requirements.

Step 3: Create an ArgoCD Application:

  • name: Set the name for your application.

  • destination: Define the destination where your application should be deployed.

  • project: Specify the project the application belongs to.

  • source: Set the source of your application, including the GitHub repository URL, revision, and the path to the application within the repository.

  • syncPolicy: Configure the sync policy, including automatic syncing, pruning, and self-healing.

Step 4: Access your Application:

  • To Access the app make sure port 8080 is open in your security group and then open a new tab paste your http://<load-balancer-dns-name>/courses, your app should be running.