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

Stg #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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.
38 changes: 38 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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

77 changes: 77 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Golang Test, Lint, Format, Build, Publish Docker Image for p2p-devops-test

on:
push:
branches:
- master

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
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## 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)
#### Enhance and Test Application:

* Use Docker to build and containerize the Go application with added health endpoints.

* Run the container on Minikube, utilizing kubectl port-forward to verify readiness and liveness probes.

#### Deploy to Local Cluster:
* Start by deploying using Kustomize for quick testing and validation of configurations.

* Transition to Helm for managing production-readiness, utilizing Helm charts for streamlined configuration adjustments.

* Iterate on Minikube deployments to test changes quickly and prepare for production standards.

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

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

##### Set up GitHub Actions workflows to automate tasks, including:

* Building and pushing Docker images to the GitHub Container Registry.

* Running automated tests for each pull request, ensuring quality and stability.

* Triggering ArgoCD syncs automatically upon successful merges to the master branch, facilitating continuous delivery.

### 3. Automated Deployment with ArgoCD

#### ArgoCD Application Manifest:

* Define an ArgoCD application manifest that specifies the Helm chart repository, enabling GitOps-driven deployments with auto-sync capabilities.

#### ArgoCD Sync Configuration:

* Configure ArgoCD to monitor master branch.

* Enable auto-sync to trigger automatic deployments to staging and production environments on Minikube when changes are merged, promoting a seamless and automated GitOps process.

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

#### Production Helm Chart:

##### Configure the production environment for resilience and scalability, with:

* Multiple replicas for fault tolerance.

* Kubernetes readiness and liveness probes.

#### Staging Helm Chart:

##### Optimize for minimal resource usage while reflecting production configurations closely to maintain parity:

* Limit replicas and resources as needed.

* Use Kustomize overlays if required for staging-specific configurations.

### 5. Monitoring and Health Checks

#### Readiness and Liveness Probes:

* Implement Kubernetes readiness and liveness probes in the Helm charts to ensure the application is healthy and ready, enabling Kubernetes to handle rolling updates or restarts if a pod becomes unhealthy.


Binary file added argocd/.DS_Store
Binary file not shown.
27 changes: 27 additions & 0 deletions argocd/helm/prod-p2p-devops-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: p2p-devops-test
spec:
destination:
name: ''
server: https://kubernetes.default.svc
source:
path: helm
repoURL: [email protected]:draju1980/p2p-devops-test.git
targetRevision: HEAD
helm:
valueFiles:
- values.production.yaml
sources: []
project: default
syncPolicy:
automated:
prune: false
selfHeal: true
retry:
limit: 2
backoff:
duration: 5s
maxDuration: 3m0s
factor: 2
Loading