J Josue Gatica Odato

Achieving Seamless Go Deployments on Kubernetes: A Full Test Approach

In the world of microservices and rapid iteration, manual deployments are a bottleneck we can no longer afford. For the SDyPP-G3 project, our recent focus was on perfecting our continuous delivery pipeline, culminating in a critical "full deployment test." This test wasn't just about pushing code; it was about validating an end-to-end automated process that takes our Go application from a commit to a fully operational state within a Kubernetes cluster.

The Challenge: From Code to Cluster

Building a robust Go application is one thing; consistently and reliably deploying it across various environments is another. The traditional dance of building binaries, creating Docker images, pushing to a registry, and then manually updating Kubernetes manifests is not only time-consuming but also prone to human error. Our goal was to eliminate this manual overhead and establish a trustworthy, repeatable deployment mechanism.

The Solution: A GitHub Actions Powered Pipeline

We leveraged GitHub Actions to orchestrate a comprehensive CI/CD pipeline. This automation ensures that every time changes are merged, our application goes through a rigorous build, containerization, and deployment cycle without intervention. This drastically reduces the time from development to production and boosts confidence in our releases.

Key Pipeline Stages

Our full deployment pipeline involves several critical steps, each automated within a GitHub Actions workflow:

  1. Code Checkout: Fetch the latest Go source code from the repository.
  2. Build Go Application: Compile the Go application, ensuring all dependencies are met and the binary is correctly generated.
  3. Build Docker Image: Create a Docker image containing the compiled Go application. This standardizes the runtime environment and packages all necessary components.
  4. Push Docker Image: Authenticate and push the newly built Docker image to a container registry (e.g., Docker Hub, Google Container Registry). This makes the image accessible to our Kubernetes cluster.
  5. Deploy to Kubernetes: Apply updated Kubernetes manifests, referencing the new Docker image tag. This triggers a rolling update within our cluster, seamlessly deploying the latest version of the application.
name: Go K8s CI/CD

on: push

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.20'

    - name: Build Go App
      run: go build -o my-app .

    - name: Docker Login
      uses: docker/login-action@v2
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Build and push Docker image
      uses: docker/build-push-action@v4
      with:
        context: .
        push: true
        tags: user/my-app:latest

    - name: Deploy to Kubernetes
      uses: azure/k8s-set-context@v1 # Example action
      with:
        kubeconfig: ${{ secrets.KUBECONFIG }}
    - run: kubectl apply -f k8s/deployment.yaml

The Outcome: Confidence in Delivery

The "full deployment test" confirmed the reliability of our pipeline. We can now merge changes with confidence, knowing that our SDyPP-G3 Go application will be automatically built, containerized, and deployed to Kubernetes without manual intervention. This not only speeds up our release cycle but also frees developers to focus on building features rather than wrestling with deployment scripts.

To implement this yourself, start by defining your build and containerization steps, then integrate with your Kubernetes cluster via kubectl commands within your CI/CD tool. The key is to automate every step, ensuring immutability and repeatability across all environments.


Generated with Gitvlg.com

Josué Gatica Odato

Josué Gatica Odato

Author

Share: