From 42f7ed4e294bccefbf9da25bd01b04a82219ac0a Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:41:11 +0530 Subject: [PATCH 01/10] added CI script and updated p2p devops test application with health endpoint --- .github/workflows/main.yaml | 76 +++++++++++++++++++++++++++++++++++++ main.go | 20 ++++++---- 2 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..cefbbcd --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,76 @@ +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@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.23.0' + + - 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 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23.0' + + - run: go version + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/main.go b/main.go index 97fe143..c68ee63 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,20 @@ package main import ( - "fmt" - "net/http" + "fmt" + "net/http" ) func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path) - }) - fmt.Println("Web app running on localhost:3000") - http.ListenAndServe(":3000", nil) + // Application endpoint + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path) + }) + // Health check endpoint + http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("OK")) + }) + fmt.Println("Web app running on localhost:3000") + http.ListenAndServe(":3000", nil) } From 3f610a41d80e39cf2818b4eb72068181db714cf8 Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:49:17 +0530 Subject: [PATCH 02/10] go init --- Dockerfile | 15 +++++++++++++++ go.mod | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 Dockerfile create mode 100644 go.mod diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2316a9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.23.0 + +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" ] \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3df2e74 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module p2p-devops-test + +go 1.23.2 From 82b56f7f1fd40ea098e7f9e31c3775b39470159a Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:55:46 +0530 Subject: [PATCH 03/10] Added helm chart and kustomization --- .DS_Store | Bin 0 -> 6148 bytes .github/workflows/main.yaml | 67 +++++++++--------- Dockerfile | 2 +- Kustomization/.DS_Store | Bin 0 -> 6148 bytes Kustomization/base/deployment.yaml | 45 ++++++++++++ Kustomization/base/kustomization.yaml | 10 +++ Kustomization/base/namespace.yaml | 5 ++ Kustomization/base/service.yaml | 14 ++++ .../dev/horizontalpodautoscaler.yaml | 26 +++++++ Kustomization/dev/kustomization.yaml | 10 +++ .../prod/horizontalpodautoscaler.yaml | 26 +++++++ Kustomization/prod/kustomization.yaml | 9 +++ argocd/.DS_Store | Bin 0 -> 6148 bytes argocd/helm/prod-p2p-devops-app.yaml | 27 +++++++ argocd/helm/stg-p2p-devops-app.yaml | 27 +++++++ helm/Chart.yaml | 4 ++ helm/templates/deployment.yaml | 43 +++++++++++ helm/templates/service.yaml | 12 ++++ helm/values.production.yaml | 16 +++++ helm/values.staging.yaml | 9 +++ helm/values.yaml | 12 ++++ 21 files changed, 330 insertions(+), 34 deletions(-) create mode 100644 .DS_Store create mode 100644 Kustomization/.DS_Store create mode 100644 Kustomization/base/deployment.yaml create mode 100644 Kustomization/base/kustomization.yaml create mode 100644 Kustomization/base/namespace.yaml create mode 100644 Kustomization/base/service.yaml create mode 100644 Kustomization/dev/horizontalpodautoscaler.yaml create mode 100644 Kustomization/dev/kustomization.yaml create mode 100644 Kustomization/prod/horizontalpodautoscaler.yaml create mode 100644 Kustomization/prod/kustomization.yaml create mode 100644 argocd/.DS_Store create mode 100644 argocd/helm/prod-p2p-devops-app.yaml create mode 100644 argocd/helm/stg-p2p-devops-app.yaml create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/values.production.yaml create mode 100644 helm/values.staging.yaml create mode 100644 helm/values.yaml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0d9603206b57dd74c679a0a75c52c9a163c14e6a GIT binary patch literal 6148 zcmeHK!AiqG5S?wSZ7D(y3gT(OYr)2%J$MPR{(u!dsMN$14c2UFQgSGTe1QItAL92o zv%4*{<}9K!F#Be9W;UA#+06ie@Mn<=-~d1al~9mTA~anZs@PB}GLKNodBpj=- zWTD?UMSI_d0H*K+YGeN&;ba`AS*P=J zi-kc`4#GAc!ajM~ya@etTwm&R5S~FEnE_^Coq?)x9lHN7@RKQR^4Ck)V+NRkKgNKl z^#^?)U&`LC-(HXIT8a9ANY_U7{=zbpL1v(rUa%>7=! z-xVjv{$k-eJNpOcSEJ|bC6}+7QH~2o+0w8Y-&PhG!~iis3=jjvKqCX@2yr@%QJN$M zh=Kpi0PYV06frPZYgAhY45|eHv|w5Z*w{;8jW8G(tTjRegzHj3UCK?1!F4&z3zHWZ ztTpO##!d6V&6}6a3s-N4=L?n2c%YF+Vt^P}XP~WJ56}Ng_+=WK{Phy@hyh~Yk1@cl zVK^MXN13zr+vnj~D?lGXQ82GY0|e}~O8_{ykL;?TjtjIQFEChZ#HZlADhH&CfFgtj JV&DfD_ykJ&MT`Id literal 0 HcmV?d00001 diff --git a/Kustomization/base/deployment.yaml b/Kustomization/base/deployment.yaml new file mode 100644 index 0000000..4671243 --- /dev/null +++ b/Kustomization/base/deployment.yaml @@ -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 + diff --git a/Kustomization/base/kustomization.yaml b/Kustomization/base/kustomization.yaml new file mode 100644 index 0000000..f060a86 --- /dev/null +++ b/Kustomization/base/kustomization.yaml @@ -0,0 +1,10 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: p2p-devops-test + +resources: + - namespace.yaml + - service.yaml + - deployment.yaml diff --git a/Kustomization/base/namespace.yaml b/Kustomization/base/namespace.yaml new file mode 100644 index 0000000..7e06c42 --- /dev/null +++ b/Kustomization/base/namespace.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: p2p-devops-test diff --git a/Kustomization/base/service.yaml b/Kustomization/base/service.yaml new file mode 100644 index 0000000..e4846f2 --- /dev/null +++ b/Kustomization/base/service.yaml @@ -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 diff --git a/Kustomization/dev/horizontalpodautoscaler.yaml b/Kustomization/dev/horizontalpodautoscaler.yaml new file mode 100644 index 0000000..e92e4ff --- /dev/null +++ b/Kustomization/dev/horizontalpodautoscaler.yaml @@ -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 diff --git a/Kustomization/dev/kustomization.yaml b/Kustomization/dev/kustomization.yaml new file mode 100644 index 0000000..a11ab1a --- /dev/null +++ b/Kustomization/dev/kustomization.yaml @@ -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 + diff --git a/Kustomization/prod/horizontalpodautoscaler.yaml b/Kustomization/prod/horizontalpodautoscaler.yaml new file mode 100644 index 0000000..7237b4d --- /dev/null +++ b/Kustomization/prod/horizontalpodautoscaler.yaml @@ -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 diff --git a/Kustomization/prod/kustomization.yaml b/Kustomization/prod/kustomization.yaml new file mode 100644 index 0000000..b0bb73c --- /dev/null +++ b/Kustomization/prod/kustomization.yaml @@ -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 diff --git a/argocd/.DS_Store b/argocd/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ba07d836ac69f21060d8dd9bcecc81cf4ef5692a GIT binary patch literal 6148 zcmeHK!AiqG5Z!H~Z7D(y3gT(OYr)2%J$MPR{(uoZsMLf68cegLNy(uU@&WaS{1Cs# zncZ!%n6rq^!0emZnMpPevb)0=v<a>qe&#rFAujw?CYfUM~m7^SJ*p6>oiwt6b7$63S0b-zz0ds=1yLCaDBL;|p zf6V~y4+0d?HCSm>TL%oP1pu^QS_#T Date: Thu, 31 Oct 2024 14:24:29 +0530 Subject: [PATCH 04/10] added argocd application deployment spec on argocd/helm --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store From c06c37a2a2d2a935748d95fa8d6405459e0dfa16 Mon Sep 17 00:00:00 2001 From: draju1980 <28708694+draju1980@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:46:53 +0000 Subject: [PATCH 05/10] Create README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..70dc0aa --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +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/65cda2a6-df38-4609-b4ac-7b07b60ece66) From 952cc5ddaf0abdfb9aa9b2db3215aa50417a79b9 Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:42:24 +0530 Subject: [PATCH 06/10] Updated the README.md --- README.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 70dc0aa..559c43d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,77 @@ -Solution Summary: +## 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: +## 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. + -![image](https://github.com/user-attachments/assets/65cda2a6-df38-4609-b4ac-7b07b60ece66) From 574216ef71205efdc1fc19c0f585fafe6210ac1f Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:09:42 +0530 Subject: [PATCH 07/10] formatted the README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 559c43d..8be5a29 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Here’s a refined solution outline with a breakdown of each component and its r #### Production Helm Chart: -* Configure the production environment for resilience and scalability, with: +##### Configure the production environment for resilience and scalability, with: * Multiple replicas for fault tolerance. @@ -62,7 +62,7 @@ Here’s a refined solution outline with a breakdown of each component and its r #### Staging Helm Chart: -* Optimize for minimal resource usage while reflecting production configurations closely to maintain parity: +##### Optimize for minimal resource usage while reflecting production configurations closely to maintain parity: * Limit replicas and resources as needed. @@ -70,7 +70,7 @@ Here’s a refined solution outline with a breakdown of each component and its r ### 5. Monitoring and Health Checks -* Readiness and Liveness Probes: +#### 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. From e142a61717400eb1f1f807e99f4c66513b83d307 Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Sun, 3 Nov 2024 13:45:12 +0530 Subject: [PATCH 08/10] Added CD workflow on github action --- .github/workflows/cd.yaml | 37 +++++++++++++++++++++++++++++++++++++ .github/workflows/main.yaml | 1 + 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/cd.yaml diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml new file mode 100644 index 0000000..a074eb0 --- /dev/null +++ b/.github/workflows/cd.yaml @@ -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-stg || \ + argocd app create p2p-devops-test-stg --file https://raw.githubusercontent.com/draju1980/p2p-devops-test/refs/heads/stg/argocd/helm/stg-p2p-devops-app.yaml + fi diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index df751ec..61689cd 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,6 +4,7 @@ on: push: branches: - master + - stg env: REGISTRY: ghcr.io From 68d9de02cb844fbdbe9fe59ef21107a708a1fb22 Mon Sep 17 00:00:00 2001 From: Divakar Raju Mandapati <28708694+draju1980@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:10:06 +0530 Subject: [PATCH 09/10] Updated README.md --- README.md | 60 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8be5a29..774a9a2 100644 --- a/README.md +++ b/README.md @@ -12,66 +12,74 @@ For this technical challenge, I set up a local Minikube Kubernetes cluster, fork 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: +### 1. Development Workflow (Local Setup on Minikube) +#### Enhancing and Testing the Application: -* Use Docker to build and containerize the Go application with added health endpoints. +* Containerization: Use Docker to build and containerize the Go application, including essential health endpoints for observability. -* Run the container on Minikube, utilizing kubectl port-forward to verify readiness and liveness probes. +* 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. -#### Deploy to Local Cluster: -* Start by deploying using Kustomize for quick testing and validation of configurations. +#### Local Deployment on Minikube: -* Transition to Helm for managing production-readiness, utilizing Helm charts for streamlined configuration adjustments. +* Initial Testing with Kustomize: Start by deploying with Kustomize for fast configuration testing and validation within the Minikube environment. -* Iterate on Minikube deployments to test changes quickly and prepare for production standards. +* Transition to Helm: Shift to Helm to manage production-level configurations, using Helm charts for more streamlined adjustments and standardized deployment practices. -### 2. GitFlow-based Continuous Deployment Pipeline (Staging and Production) +* 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: -##### Set up GitHub Actions workflows to automate tasks, including: +##### Automated Workflows: Set up GitHub Actions workflows to automate the build, test, and deployment processes. -* Building and pushing Docker images to the GitHub Container Registry. +* Docker Build and Push: Build Docker images and push them to the GitHub Container Registry, streamlining container updates. -* Running automated tests for each pull request, ensuring quality and stability. +* Automated Testing: Execute tests on every pull request, ensuring code quality and stability. -* Triggering ArgoCD syncs automatically upon successful merges to the master branch, facilitating continuous delivery. +* 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 Manifest: +#### ArgoCD Application Configuration: + +* Application Manifest: Define an ArgoCD application manifest pointing to the Helm chart repository for automated, GitOps-driven deployments. -* Define an ArgoCD application manifest that specifies the Helm chart repository, enabling GitOps-driven deployments with auto-sync capabilities. +* 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. -#### ArgoCD Sync Configuration: +#### Local Minikube ArgoCD Instance: -* Configure ArgoCD to monitor master branch. +* Local Testing with Minikube: Running ArgoCD on Minikube enables efficient, iterative testing of the GitOps deployment model before moving to a cloud-hosted environment. -* 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. +* 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: -##### Configure the production environment for resilience and scalability, with: +##### Fault Tolerance and Scalability: -* Multiple replicas for fault tolerance. +* 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. -* Kubernetes readiness and liveness probes. #### Staging Helm Chart: -##### Optimize for minimal resource usage while reflecting production configurations closely to maintain parity: +##### Resource Efficiency: -* Limit replicas and resources as needed. +* Limit replicas and resource usage, keeping it minimal while reflecting production configurations to ensure parity. -* Use Kustomize overlays if required for staging-specific configurations. +##### Environment-Specific Customization: Use Kustomize overlays if additional staging-specific configurations are needed, enhancing testing without altering production specifications. ### 5. Monitoring and Health Checks -#### Readiness and Liveness Probes: +#### 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. -* 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. +* 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. From e422e4ef93981a94e02f4f449bdf74fc841944ad Mon Sep 17 00:00:00 2001 From: draju1980 <28708694+draju1980@users.noreply.github.com> Date: Sun, 10 Nov 2024 16:56:55 +0530 Subject: [PATCH 10/10] Update cd.yaml --- .github/workflows/cd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index a074eb0..7163d78 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -32,6 +32,6 @@ jobs: 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-stg || \ - argocd app create p2p-devops-test-stg --file https://raw.githubusercontent.com/draju1980/p2p-devops-test/refs/heads/stg/argocd/helm/stg-p2p-devops-app.yaml + 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