Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draju1980 patch 1 #7

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CD Pipeline

on:
push:
branches:
- master # Production
- stg # Staging

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install ArgoCD CLI
run: |
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x /usr/local/bin/argocd

- name: ArgoCD Login
env:
ARGOCD_SERVER: ${{ secrets.ARGOCD_SERVER }}
ARGOCD_USERNAME: admin
ARGOCD_PASSWORD: ${{ secrets.ARGOCD_PASSWORD }}
run: |
argocd login $ARGOCD_SERVER --insecure --username $ARGOCD_USERNAME --password $ARGOCD_PASSWORD

- name: Deploy Application to ArgoCD
run: |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
argocd app sync p2p-devops-test || \
argocd app create p2p-devops-test --file https://raw.githubusercontent.com/draju1980/p2p-devops-test/refs/heads/master/argocd/helm/prod-p2p-devops-app.yaml
elif [[ "${{ github.ref }}" == "refs/heads/stg" ]]; then
argocd app sync p2p-devops-test || \
argocd app create p2p-devops-test --file https://raw.githubusercontent.com/draju1980/p2p-devops-test/refs/heads/stg/argocd/helm/stg-p2p-devops-app.yaml
fi
78 changes: 78 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Golang Test, Lint, Format, Build, Publish Docker Image for p2p-devops-test

on:
push:
branches:
- master
- stg

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
test-lint-format:
name: Test, Lint, and Format
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.2'
cache: true

- name: Install dependencies
run: go mod tidy

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test ./...

- name: Lint code
run: |
go install golang.org/x/lint/golint@latest
golint ./...

- name: Format code
run: gofmt -s -w .

build-and-publish:
name: Build and Publish Docker Image
runs-on: ubuntu-latest
needs: test-lint-format
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker image
id: meta
uses: docker/metadata-action@v1
with:
images: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.23.2

WORKDIR /app

COPY go.mod ./
RUN go mod tidy
RUN go mod download

COPY *.go ./

RUN go build -o /p2p-devops-test

EXPOSE 3000

CMD [ "/p2p-devops-test" ]
Binary file added Kustomization/.DS_Store
Binary file not shown.
45 changes: 45 additions & 0 deletions Kustomization/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: p2p-devops-test
namespace: p2p-devops-test
spec:
replicas: 1
selector:
matchLabels:
app: p2p-devops-test
template:
metadata:
labels:
app: p2p-devops-test
spec:
containers:
- name: p2p-devops-test-pod
image: ghcr.io/draju1980/draju1980/p2p-devops-test:master
ports:
- containerPort: 3000
resources:
limits:
cpu: "512m"
memory: "512Mi"
requests:
cpu: "256m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 5
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3

10 changes: 10 additions & 0 deletions Kustomization/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: p2p-devops-test

resources:
- namespace.yaml
- service.yaml
- deployment.yaml
5 changes: 5 additions & 0 deletions Kustomization/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: p2p-devops-test
14 changes: 14 additions & 0 deletions Kustomization/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Service
metadata:
name: p2p-devops-test-svc
namespace: p2p-devops-test
spec:
selector:
app: p2p-devops-test
ports:
- protocol: TCP
port: 3000
targetPort: 3000
type: LoadBalancer
26 changes: 26 additions & 0 deletions Kustomization/dev/horizontalpodautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: p2p-devops-test-hpa
namespace: p2p-devops-test
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: p2p-devops-test
minReplicas: 1
maxReplicas: 1
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 75
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 75
10 changes: 10 additions & 0 deletions Kustomization/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: p2p-devops-test-dev

resources:
- ../base # This is the base directory
- horizontalpodautoscaler.yaml

26 changes: 26 additions & 0 deletions Kustomization/prod/horizontalpodautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: p2p-devops-test-hpa
namespace: p2p-devops-test
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: p2p-devops-test
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 75
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 75
9 changes: 9 additions & 0 deletions Kustomization/prod/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: p2p-devops-test-prod

resources:
- ../base # This is the base directory
- horizontalpodautoscaler.yaml
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
## Solution Summary

For this technical challenge, I set up a local Minikube Kubernetes cluster, forked the p2p-devops-test repository, and enhanced the Go application by adding health endpoints to support Kubernetes readiness and liveness probes. I initially deployed the application using Kustomize while familiarizing myself with Helm, then created Helm charts for a fault-tolerant, scalable production setup and a minimal staging configuration. I installed ArgoCD on Minikube and configured an ArgoCD application manifest to manage deployments using GitOps with auto-sync enabled. Additionally, I set up a GitFlow-based CD pipeline to deploy across environments through ArgoCD, with options for further automation using GitHub Actions.


## Solution Design:

![image](https://github.com/user-attachments/assets/1f5f238e-c57c-49d5-8962-ca5147a0579b)


## Solution Outline:

Here’s a refined solution outline with a breakdown of each component and its role in achieving a structured, automated CI/CD workflow with GitOps principles,

### 1. Development Workflow (Local Setup on Minikube)
#### Enhancing and Testing the Application:

* Containerization: Use Docker to build and containerize the Go application, including essential health endpoints for observability.

* Local Validation: Run the container on Minikube, leveraging kubectl port-forward to validate Kubernetes readiness and liveness probes. This enables quick checks for the application’s responsiveness and stability.

#### Local Deployment on Minikube:

* Initial Testing with Kustomize: Start by deploying with Kustomize for fast configuration testing and validation within the Minikube environment.

* Transition to Helm: Shift to Helm to manage production-level configurations, using Helm charts for more streamlined adjustments and standardized deployment practices.

* Iterative Deployment: Test deployment changes iteratively on Minikube to optimize configurations before transitioning to production standards.


### 2. GitFlow-Based Continuous Deployment Pipeline (Staging and Production)

#### CI/CD Pipeline Integration with GitHub Actions:

##### Automated Workflows: Set up GitHub Actions workflows to automate the build, test, and deployment processes.

* Docker Build and Push: Build Docker images and push them to the GitHub Container Registry, streamlining container updates.

* Automated Testing: Execute tests on every pull request, ensuring code quality and stability.

* Continuous Delivery with ArgoCD: Trigger ArgoCD syncs automatically upon successful merges to the master branch, following GitFlow practices for streamlined deployment to production and staging environments.

### 3. Automated Deployment with ArgoCD

#### ArgoCD Application Configuration:

* Application Manifest: Define an ArgoCD application manifest pointing to the Helm chart repository for automated, GitOps-driven deployments.

* GitOps Sync: Configure ArgoCD to monitor the master branch for production and stg branch for staging, enabling auto-sync capabilities to automate deployment processes when changes are merged.

#### Local Minikube ArgoCD Instance:

* Local Testing with Minikube: Running ArgoCD on Minikube enables efficient, iterative testing of the GitOps deployment model before moving to a cloud-hosted environment.

* Cloud Environment Preparation: For cloud environments, ensure ARGOCD_SERVER IP and ARGOCD_PASSWORD are updated in repository secrets to support ArgoCD login for continuous deployment.

### 4. Helm Chart Setup for Environment-Specific Deployments

#### Production Helm Chart:

##### Fault Tolerance and Scalability:

* Configure multiple replicas to ensure fault tolerance.
* Apply Kubernetes readiness and liveness probes to support automated rolling updates and proactive health checks.

##### Resource Management: Optimize resources to ensure the application’s high availability and responsiveness under production loads.


#### Staging Helm Chart:

##### Resource Efficiency:

* Limit replicas and resource usage, keeping it minimal while reflecting production configurations to ensure parity.

##### Environment-Specific Customization: Use Kustomize overlays if additional staging-specific configurations are needed, enhancing testing without altering production specifications.

### 5. Monitoring and Health Checks

#### Kubernetes Readiness and Liveness Probes:

* Automated Health Checks: Implement Kubernetes readiness and liveness probes in the Helm charts, allowing Kubernetes to manage restarts or rolling updates if a pod becomes unhealthy.

* Enhanced Observability: These probes enable both the Minikube and production clusters to maintain high availability, handling restarts if an issue is detected in real time.


Binary file added argocd/.DS_Store
Binary file not shown.
Loading