<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sheraz Iqbal on Medium]]></title>
        <description><![CDATA[Stories by Sheraz Iqbal on Medium]]></description>
        <link>https://medium.com/@sheraziqbal?source=rss-e7a5fab7c9fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Sheraz Iqbal on Medium</title>
            <link>https://medium.com/@sheraziqbal?source=rss-e7a5fab7c9fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:59:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sheraziqbal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From PR → Preview → Production with GitHub Actions + ArgoCD]]></title>
            <link>https://sheraziqbal.medium.com/from-pr-preview-production-with-github-actions-argocd-83ec64e57ec0?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/83ec64e57ec0</guid>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Sat, 22 Nov 2025 17:16:55 GMT</pubDate>
            <atom:updated>2025-11-22T17:20:04.494Z</atom:updated>
            <content:encoded><![CDATA[<p>It includes an <strong>Ephemeral Guide</strong>, a <strong>complete sample</strong></p><p>Where I refer to core concepts (Argo CD, Argo Rollouts, preview patterns), I’ve linked documentation and examples so you can dive deeper. (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zxw3-V8VxvZiZyij" /><figcaption>Photo by <a href="https://unsplash.com/@thatkidpayt?utm_source=medium&amp;utm_medium=referral">Payton Mcdonald</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>A practical guide (Helm, readiness/liveness probes, Blue/Green &amp; Canary, ephemeral preview environments)</h3><p><strong>Goal:</strong> Build a reproducible GitOps pipeline where:</p><p>Pull Requests automatically create <em>ephemeral preview environments</em>.</p><p>CI builds images and pushes them to a registry.</p><p>ArgoCD watches a “manifests” Git repo and deploys Helm charts to clusters.</p><p>Production uses progressive delivery (Blue/Green or Canary via Argo Rollouts).</p><p>Entire flow is automated: PR → preview → promote → production.</p><p>Why this pattern? Keep CI fast and deterministic; keep deployment policy in Git (ArgoCD); give devs instant, isolated previews for their PRs. (ArgoCD docs and previews patterns are great references). (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</p><h3>High level flow</h3><p>Developer opens PR on app repo.</p><p>GitHub Actions CI builds container image and pushes image:sha-&lt;short&gt; to registry.</p><p>CI creates/updates a <em>preview manifests</em> directory (or branch) with Helm values pointing to that image and opens/updates a PR in the manifests repo (or updates ApplicationSet parameters).</p><p>ArgoCD (watching manifests repo) creates a new Application per PR (ephemeral namespace) and deploys the Helm release.</p><p>Devs test the preview URL. After merge/close, a cleanup action removes the preview.</p><p>For production releases, the manifests repo is updated (tag/branch) and ArgoCD deploys to production; progressive delivery via Argo Rollouts handles blue/green or canary. (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</p><h3>Sample repository layout (two repos recommended)</h3><p><strong>Repo A — </strong><strong>myapp (app source + CI)</strong></p><pre>myapp/<br>├─ .github/workflows/<br>│  ├─ ci.yml                    # build, test, push image<br>│  └─ pr-preview.yml            # PR triggered: create preview manifests (or call API)<br>├─ app/                         # application source<br>│  └─ src...<br>├─ Dockerfile<br>├─ helm/                        # optionally included (but production Helm lives in manifests repo)<br>│  └─ myapp/</pre><p><strong>Repo B — </strong><strong>manifests (ArgoCD watches this)</strong></p><pre>manifests/<br>├─ apps/<br>│  ├─ production/<br>│  │  └─ myapp/                 # helm values for prod<br>│  └─ previews/                 # autogenerated preview apps per PR<br>├─ cluster-config/<br>└─ README.md</pre><blockquote><em>Best practice: keep application source and cluster manifests in separate repositories (ArgoCD best practice). (</em><a href="https://argo-cd.readthedocs.io/en/stable/user-guide/best_practices/?utm_source=chatgpt.com"><em>Argo CD</em></a><em>)</em></blockquote><h3>1) Dockerfile (simple, production-ready)</h3><p>myapp/Dockerfile</p><pre>FROM node:18-alpine AS builder<br>WORKDIR /app<br>COPY package*.json ./<br>RUN npm ci --production<br>COPY . .<br>RUN npm run build<br><br>FROM node:18-alpine<br>WORKDIR /app<br>COPY --from=builder /app/dist ./dist<br>COPY package*.json ./<br>RUN npm ci --production<br>ENV PORT=3000<br>EXPOSE 3000<br>CMD [&quot;node&quot;,&quot;dist/server.js&quot;]</pre><p><strong>Tip:</strong> Keep images slim; use multi-stage build to reduce image size and pull time.</p><h3>2) Kubernetes Deployment with readiness &amp; liveness probes (Helm template)</h3><p>manifests/apps/myapp/templates/deployment.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: {{ include &quot;myapp.fullname&quot; . }}<br>  labels: {{- include &quot;myapp.labels&quot; . | nindent 4 }}<br>spec:<br>  replicas: {{ .Values.replicaCount }}<br>  selector:<br>    matchLabels:<br>      app: {{ include &quot;myapp.name&quot; . }}<br>  template:<br>    metadata:<br>      labels:<br>        app: {{ include &quot;myapp.name&quot; . }}<br>        chart: {{ include &quot;myapp.chart&quot; . }}<br>    spec:<br>      containers:<br>        - name: {{ .Chart.Name }}<br>          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag }}&quot;<br>          imagePullPolicy: IfNotPresent<br>          ports:<br>            - containerPort: {{ .Values.service.port }}<br>          readinessProbe:<br>            httpGet:<br>              path: /health/ready<br>              port: {{ .Values.service.port }}<br>            initialDelaySeconds: 5<br>            periodSeconds: 10<br>            failureThreshold: 3<br>          livenessProbe:<br>            httpGet:<br>              path: /health/live<br>              port: {{ .Values.service.port }}<br>            initialDelaySeconds: 30<br>            periodSeconds: 20<br>            failureThreshold: 5<br>          resources:<br>            limits:<br>              cpu: {{ .Values.resources.limits.cpu }}<br>              memory: {{ .Values.resources.limits.memory }}<br>            requests:<br>              cpu: {{ .Values.resources.requests.cpu }}<br>              memory: {{ .Values.resources.requests.memory }}</pre><p><strong>Why these probes?</strong></p><p>readiness ensures a pod only receives traffic when app is ready; helps zero-downtime deployments.</p><p>liveness restarts unhealthy containers. Tweak delays based on app startup.</p><h3>3) Helm values.yaml (example)</h3><p>manifests/apps/myapp/values.yaml</p><pre>replicaCount: 2<br>image:<br>  repository: ghcr.io/your-org/myapp<br>  tag: &quot;latest&quot;<br>service:<br>  port: 3000<br>resources:<br>  requests:<br>    cpu: &quot;100m&quot;<br>    memory: &quot;128Mi&quot;<br>  limits:<br>    cpu: &quot;500m&quot;<br>    memory: &quot;512Mi&quot;</pre><h3>4) ArgoCD Application (Helm) — manifests repo</h3><p>manifests/apps/production/myapp-argocd.yaml</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: myapp-production<br>  namespace: argocd<br>spec:<br>  project: default<br>  source:<br>    repoURL: &#39;https://github.com/your-org/manifests.git&#39;<br>    path: &#39;apps/production/myapp&#39;<br>    targetRevision: HEAD<br>    helm:<br>      valueFiles:<br>        - values.yaml<br>  destination:<br>    server: &#39;https://kubernetes.default.svc&#39;<br>    namespace: myapp-prod<br>  syncPolicy:<br>    automated:<br>      prune: true<br>      selfHeal: true</pre><p>ArgoCD will sync the Helm chart from the manifests repo into myapp-prod. ArgoCD best practices: pin revisions/tags for production tracking. (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</p><h3>5) CI: GitHub Actions — Build, Test, Push image (ci.yml)</h3><p>.github/workflows/ci.yml in myapp repo</p><pre>name: CI</pre><pre>on:<br>  push:<br>    branches: [ main ]<br>  pull_request:<br>    types: [opened, synchronize, reopened]</pre><pre>permissions:<br>  contents: read<br>  packages: write<br>  id-token: write</pre><pre>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - name: Set up QEMU<br>        uses: docker/setup-qemu-action@v2<br>      - name: Set up Docker Buildx<br>        uses: docker/setup-buildx-action@v2<br>      - name: Login to registry<br>        uses: docker/login-action@v2<br>        with:<br>          registry: ghcr.io<br>          username: ${{ github.actor }}<br>          password: ${{ secrets.GHCR_TOKEN }}<br>      - name: Build and push<br>        id: build<br>        uses: docker/build-push-action@v4<br>        with:<br>          context: .<br>          push: true<br>          tags: ghcr.io/your-org/myapp:${{ github.sha }}<br>      - name: Set image info<br>        run: echo &quot;IMAGE=ghcr.io/your-org/myapp:${{ github.sha }}&quot; &gt;&gt; $GITHUB_OUTPUT</pre><p><strong>Note:</strong> Use appropriate registry and secrets. The workflow pushes image:sha which later will be referenced by preview/manifest updates.</p><h3>6) PR → Preview automation (pr-preview.yml)</h3><p>Approaches:</p><p>A) CI modifies manifests repo (via GitHub token) and creates a previews/pr-&lt;num&gt;/myapp folder with values.yaml that points to image:sha.</p><p>B) Use ArgoCD ApplicationSet + generator that creates apps per PR (GitHub Pull Request generator or List generator). Example repos demonstrate ApplicationSet patterns. (<a href="https://github.com/automationiberia/argocd-preview-environments?utm_source=chatgpt.com">GitHub</a>)</p><p>Here’s a simple Action that creates/updates a folder in manifests repo.</p><p>.github/workflows/pr-preview.yml</p><pre>name: PR Preview<br>on:<br>  pull_request:<br>    types: [opened, synchronize, reopened, closed]</pre><pre>permissions:<br>  contents: write<br>  id-token: write</pre><pre>jobs:<br>  preview:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout<br>        uses: actions/checkout@v4<br>      - name: Build &amp; Push Image<br>        uses: docker/build-push-action@v4<br>        with:<br>          context: .<br>          push: true<br>          tags: ghcr.io/your-org/myapp:${{ github.sha }}<br>      - name: Create preview manifest PR<br>        uses: peter-evans/create-pull-request@v5<br>        with:<br>          token: ${{ secrets.MANIFESTS_REPO_TOKEN }}<br>          commit-message: &quot;Preview: PR #${{ github.event.number }} - image ${{ github.sha }}&quot;<br>          branch: preview/pr-${{ github.event.number }}<br>          title: &quot;Preview for PR #${{ github.event.number }}&quot;<br>          body: |<br>            creates preview values for PR #${{ github.event.number }}<br>          base: main<br>          files: |<br>            apps/previews/pr-${{ github.event.number }}/myapp/values.yaml&lt;&lt;EOF<br>            image:<br>              repository: ghcr.io/your-org/myapp<br>              tag: ${{ github.sha }}<br>            replicaCount: 1<br>            EOF</pre><p>On PR open/sync, this will create a PR in the manifests repo adding a preview values.yaml.</p><p>ArgoCD (or an automated merge process) will then create the preview Application. Alternatively, you can push directly to the manifests repo if you prefer no manual PRs.</p><p><strong>Alternative:</strong> Use ApplicationSet with a PR generator so ArgoCD creates apps dynamically without file commits. See example repos. (<a href="https://github.com/automationiberia/argocd-preview-environments?utm_source=chatgpt.com">GitHub</a>)</p><h3>7) ArgoCD ApplicationSet (dynamic apps per PR) — example snippet</h3><p>manifests/apps/applicationset-prs.yaml</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: ApplicationSet<br>metadata:<br>  name: preview-applicationset<br>  namespace: argocd<br>spec:<br>  generators:<br>    - git:<br>        repoURL: &#39;https://github.com/your-org/manifests.git&#39;<br>        directories:<br>          - path: &#39;apps/previews/*/*&#39;<br>  template:<br>    metadata:<br>      name: &#39;{{path.basename}}-preview&#39;<br>    spec:<br>      project: default<br>      source:<br>        repoURL: &#39;https://github.com/your-org/manifests.git&#39;<br>        path: &#39;{{path}}&#39;<br>        targetRevision: HEAD<br>      destination:<br>        server: &#39;https://kubernetes.default.svc&#39;<br>        namespace: &#39;preview-{{path.basename}}&#39;<br>      syncPolicy:<br>        automated:<br>          prune: true<br>          selfHeal: true</pre><p>This lets you push preview values.yaml (as above) and ArgoCD will create a live Application per preview folder. (<a href="https://medium.com/%40taffarelo3/building-preview-environments-with-argocd-in-kubernetes-clusters-5048c48a3c69?utm_source=chatgpt.com">Medium</a>)</p><h3>8) Cleanup &amp; TTL for previews (Ephemeral Guide)</h3><ul><li>Naming: preview-pr-&lt;number&gt;-&lt;sha&gt; for namespaces/apps.</li><li>TTL policy options:</li><li>Delete preview when PR is closed (GitHub webhook triggers cleanup job).</li><li>Add an automated TTL controller (e.g., a small K8s cron that deletes namespaces older than X hours).</li><li>Implementation: In CI pull_request.closed event, run a job that removes the preview folder or deletes the ArgoCD Application resource. Or use ApplicationSet generator (PR-based) and let the Job delete the directory / Application. See preview tools on Marketplace. (<a href="https://github.com/marketplace/actions/preview-environments-for-github?utm_source=chatgpt.com">GitHub</a>)</li></ul><h3>9) Progressive delivery: Blue/Green &amp; Canary (Argo Rollouts)</h3><p>Use <strong>Argo Rollouts</strong> for advanced strategies. Option A: label-switch Blue/Green; Option B: Canary with traffic-weight shift.</p><h3>Example: Blue/Green (Argo Rollouts)</h3><p>manifests/apps/myapp/rollout-bluegreen.yaml</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Rollout<br>metadata:<br>  name: myapp-rollout<br>spec:<br>  replicas: 3<br>  strategy:<br>    blueGreen:<br>      activeService: myapp-active<br>      previewService: myapp-preview<br>      autoPromotionEnabled: false<br>  selector:<br>    matchLabels:<br>      app: myapp<br>  template:<br>    metadata:<br>      labels:<br>        app: myapp<br>    spec:<br>      containers:<br>        - name: myapp<br>          image: ghcr.io/your-org/myapp:{{ .Values.image.tag }}<br>          ports:<br>            - containerPort: 3000<br>          readinessProbe: ...</pre><ul><li>Blue/Green flow: Deploy new version to previewService, test, then promote to activeService. Argo Rollouts can automate promotion or require manual approval. Documentation: Argo Rollouts BlueGreen. (<a href="https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/?utm_source=chatgpt.com">Argo Rollouts</a>)</li></ul><h3>Example: Canary</h3><p>manifests/apps/myapp/rollout-canary.yaml</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Rollout<br>metadata:<br>  name: myapp-canary<br>spec:<br>  strategy:<br>    canary:<br>      steps:<br>        - setWeight: 10<br>        - pause: { duration: 60 }<br>        - setWeight: 50<br>        - pause: { duration: 120 }<br>  selector: ...<br>  template: ...</pre><ul><li>Combine with a service mesh or Ingress (Istio/Contour/NGINX) to control traffic shifting. See Argo Rollouts docs and examples. (<a href="https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/?utm_source=chatgpt.com">Argo Rollouts</a>)</li></ul><h3>10) Fully automated PR → Preview → Promote (end to end)</h3><ol><li><strong>On PR open:</strong> pr-preview.yml builds image &amp; creates preview values in manifests repo → ArgoCD creates preview-pr-XXX Application (via ApplicationSet).</li><li><strong>Developer tests preview</strong>, comments, iterates.</li><li><strong>On Merge to main:</strong> CI creates a release tag and updates apps/production/myapp/values.yaml to the new image tag (or pushes a release commit). ArgoCD picks it up and triggers rollout; Argo Rollouts performs Blue/Green/Canary.</li><li><strong>Monitoring &amp; automated promotion:</strong> Integrate checks (Prometheus, metrics) to automate promotion or rollback (Argo Rollouts supports metric-based analysis). (<a href="https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/?utm_source=chatgpt.com">Argo Rollouts</a>)</li></ol><h3>11) Sample GitHub Actions snippet to update production manifests on merge</h3><p>Add to ci.yml (on push to main):</p><pre>- name: Update manifests repo for production<br>  if: github.ref == &#39;refs/heads/main&#39;<br>  uses: actions/checkout@v4<br>  with:<br>    repository: your-org/manifests<br>    token: ${{ secrets.MANIFESTS_REPO_TOKEN }}<br>    path: manifests<br>- name: Replace production image tag<br>  run: |<br>    yq e &#39;.image.tag = env.GITHUB_SHA&#39; -i manifests/apps/production/myapp/values.yaml<br>    git config user.email &quot;ci@github.com&quot;<br>    git config user.name &quot;CI Bot&quot;<br>    cd manifests<br>    git add .<br>    git commit -m &quot;prod: release $GITHUB_SHA&quot;<br>    git push origin main</pre><p>yq lets you programmatically update YAML.</p><h3>12) Observability, Rollbacks &amp; Safety</h3><ul><li>Integrate Prometheus alerts and use Argo Rollouts analysis to automatically pause/rollback on bad metrics.</li><li>Keep selfHeal enabled in ArgoCD to revert config drift.</li><li>Use image immutability (tag by SHA) to ensure reproducible deployments. (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</li></ul><h3>Ephemeral Guide — checklist (copyable)</h3><p><strong>When PR opens</strong></p><ul><li>Build image and push ghcr.io/...:sha</li><li>Create preview values.yaml (image.tag = sha) in manifests/apps/previews/pr-&lt;num&gt;/myapp/</li><li>Ensure ArgoCD ApplicationSet picks up new preview app</li><li>Provide preview URL to author (via comment)</li></ul><p><strong>During PR</strong></p><ul><li>Run integration tests against preview</li><li>Share feedback &amp; fix</li></ul><p><strong>On PR merge</strong></p><ul><li>Update production values.yaml to new image tag (via CI)</li><li>Argo Rollouts performs Canary/BlueGreen as configured</li><li>Monitor metrics &amp; promote/rollback as needed</li></ul><p><strong>On PR close without merge</strong></p><ul><li>Delete preview folder or ArgoCD Application</li><li>Confirm namespace cleanup</li></ul><h3>References &amp; further reading</h3><ul><li>Argo CD docs — GitOps CD for Kubernetes. (<a href="https://argo-cd.readthedocs.io/?utm_source=chatgpt.com">Argo CD</a>)</li><li>Argo Rollouts — Blue/Green &amp; Canary strategies. (<a href="https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/?utm_source=chatgpt.com">Argo Rollouts</a>)</li><li>Example preview patterns &amp; ApplicationSet generators (community repos). (<a href="https://github.com/automationiberia/argocd-preview-environments?utm_source=chatgpt.com">GitHub</a>)</li><li>Example GitOps playgrounds and CI/CD posts combining GitHub Actions &amp; ArgoCD. (<a href="https://github.com/adavarski/ArgoCD-GitOps-playground?utm_source=chatgpt.com">GitHub</a>)</li><li>GitHub Actions marketplace: preview environment actions. (<a href="https://github.com/marketplace/actions/preview-environments-for-github?utm_source=chatgpt.com">GitHub</a>)</li></ul><h3>Final notes (practical tips from a Sr. Cloud Solutions Architect)</h3><ul><li>Pin images by SHA. Never promote latest to production.</li><li>Keep manifests repo readable — humans will debug it.</li><li>Start small: implement previews for a single service, then generalize.</li><li>Use ApplicationSet to avoid proliferating manual ArgoCD apps.</li><li>Use Argo Rollouts for safe progressive delivery and automated analysis.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83ec64e57ec0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical Guide: Deploying to Kubernetes Using GitHub Actions + ArgoCD]]></title>
            <link>https://sheraziqbal.medium.com/practical-guide-deploying-to-kubernetes-using-github-actions-argocd-cd5c47c92e63?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd5c47c92e63</guid>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[kuberenetes]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Sat, 22 Nov 2025 17:00:34 GMT</pubDate>
            <atom:updated>2025-11-22T17:00:34.801Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Real working pipeline</strong> that many senior DevOps/Cloud teams use for Ephemeral Environment Setup<br>No fluff — just the exact pieces you need.</p><h3>1. Folder Structure (Recommended)</h3><pre>repo/<br> ├── app/<br> │    └── Dockerfile<br> │    └── src/...<br> ├── k8s/<br> │    ├── deployment.yaml<br> │    ├── service.yaml<br> │    └── kustomization.yaml<br> └── .github/<br>      └── workflows/<br>           └── deploy.yml</pre><p>Your app code stays in app/<br> Your Kubernetes manifests live in k8s/<br> GitHub Actions pipeline goes to .github/workflows/</p><h3>2. Build + Push Docker Image (GitHub Actions)</h3><p>Create .github/workflows/deploy.yml:</p><pre>name: CI-CD</pre><pre>on:<br>  push:<br>    branches: [ &quot;main&quot; ]</pre><pre>jobs:<br>  build:<br>    runs-on: ubuntu-latest</pre><pre>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v3</pre><pre>      - name: Login to GHCR<br>        uses: docker/login-action@v3<br>        with:<br>          registry: ghcr.io<br>          username: ${{ github.actor }}<br>          password: ${{ secrets.GITHUB_TOKEN }}</pre><pre>      - name: Build and Push Image<br>        run: |<br>          IMAGE_TAG=ghcr.io/${{ github.repository }}/app:${{ github.sha }}<br>          docker build -t $IMAGE_TAG ./app<br>          docker push $IMAGE_TAG<br>          echo &quot;IMAGE_TAG=$IMAGE_TAG&quot; &gt;&gt; $GITHUB_ENV</pre><p>✔ Builds Docker image<br> ✔ Pushes it to GitHub Container Registry<br> ✔ Exposes IMAGE_TAG for the next job</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Afv98Litgjc3byEQ" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>3. Update Kubernetes Manifests Automatically</h3><p>Add another step to modify the image inside kustomization.yaml:</p><pre>update-manifests:<br>    runs-on: ubuntu-latest<br>    needs: build<br>    steps:<br>      - uses: actions/checkout@v3<br>- name: Update kustomization image<br>        run: |<br>          sed -i &quot;s|newTag:.*|newTag: &#39;${{ github.sha }}&#39;|g&quot; k8s/kustomization.yaml<br>      - name: Commit changes<br>        run: |<br>          git config user.name &quot;github-actions&quot;<br>          git config user.email &quot;actions@github.com&quot;<br>          git add k8s/kustomization.yaml<br>          git commit -m &quot;Update image to ${{ github.sha }}&quot;<br>          git push</pre><p>✔ Automatically updates the image tag<br>✔ Commits back to repo — this is how ArgoCD sees new changes</p><h3>4. ArgoCD Application (one-time setup)</h3><p>Apply this to your cluster:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: my-app<br>  namespace: argocd<br>spec:<br>  project: default<br><br>source:<br>    repoURL: https://github.com/YOUR_USER/YOUR_REPO<br>    targetRevision: main<br>    path: k8s<br>  destination:<br>    server: https://kubernetes.default.svc<br>    namespace: production<br>  syncPolicy:<br>    automated:<br>      prune: true<br>      selfHeal: true<br>    syncOptions:<br>      - CreateNamespace=true</pre><p>✔ Points ArgoCD to your GitHub repo<br>✔ Watches the k8s/ folder<br>✔ Auto-syncs when GitHub Actions commits manifest updates</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G5uLCT_baHcjqoPR" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>5. The Complete Flow</h3><h3>Step-by-step what happens:</h3><p><strong>Developer pushes code to main</strong></p><ol><li>GitHub Actions:</li></ol><p>builds Docker image</p><p>pushes to registry</p><p>updates kustomization.yaml</p><p>commits change back</p><p><strong>2. ArgoCD detects commit</strong></p><p>ArgoCD deploys new version into Kubernetes</p><p>If anything breaks → rollback in ArgoCD UI in seconds</p><p>This is the <strong>cleanest, GitOps-friendly pipeline</strong> you can run today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd5c47c92e63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Project: PHP8 Deployment on AWS EKS with RDS, GitHub Actions, ArgoCD, Prometheus, Grafana &…]]></title>
            <link>https://sheraziqbal.medium.com/devops-project-php8-deployment-on-aws-eks-with-rds-github-actions-argocd-prometheus-grafana-8501481690d0?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8501481690d0</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 18:33:18 GMT</pubDate>
            <atom:updated>2025-04-23T18:58:48.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>DevOps Project: PHP8 Deployment on AWS EKS with RDS, GitHub Actions, ArgoCD, Prometheus, Grafana &amp; CloudWatch</h3><h3>What’s Inside This Project?</h3><p>We’ll be using some of the best DevSecOps tools out there to make this happen:</p><blockquote>GitHub Actions — Automates the CI process</blockquote><blockquote>SonarQube &amp; Quality-Gate-Check — Keep the code clean, secure, and compliant</blockquote><blockquote>Inspector — Scans container images for security vulnerabilities to meet CIS benchmarks</blockquote><blockquote>Terraform — Automates infrastructure setup on AWS</blockquote><blockquote>ArgoCD — Ensures Kubernetes deployments stay in sync with Git (GitOps)</blockquote><blockquote>Prometheus &amp; Grafana — Provide real-time monitoring and insights</blockquote><h3>Step 1: Set Up Terraform for AWS Infrastructure</h3><h3>1. Set Up an AWS EC2 Instance for Infrastructure Management</h3><p>First, we’ll create an EC2 instance to manage our infrastructure with Terraform:</p><p><strong>Launch an EC2 Instance:</strong></p><ul><li>Login to AWS Console</li><li>Navigate to EC2</li><li>Click “Launch Instance”</li></ul><p><strong>Configure Instance:</strong></p><ul><li>Name: terraform-management</li><li>AMI: Ubuntu Server 22.04 LTS</li><li>Instance Type: t2.medium (2 vCPUs, 4GB RAM)</li><li>Create a key pair (or use existing)</li></ul><p><strong>Security Group Configuration:</strong></p><ul><li>Allow SSH (port 22) from your IP</li><li>Allow HTTPS (port 443)</li><li>Allow HTTP (port 80)</li></ul><p><strong>User Data Script for Automatic Installation:</strong></p><pre>#!/bin/bash<br># Update packages<br>sudo apt update -y</pre><pre># Install required tools<br>sudo apt install -y unzip wget curl git</pre><pre># Install AWS CLI<br>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>unzip awscliv2.zip<br>sudo ./aws/install</pre><pre># Install Terraform<br>wget -O- <a href="https://apt.releases.hashicorp.com/gpg">https://apt.releases.hashicorp.com/gpg</a> | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg<br>echo &quot;deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] <a href="https://apt.releases.hashicorp.com/">https://apt.releases.hashicorp.com</a> $(lsb_release -cs) main&quot; | sudo tee /etc/apt/sources.list.d/hashicorp.list<br>sudo apt update<br>sudo apt install terraform -y</pre><pre># Install kubectl<br>sudo curl -LO &quot;https://dl.k8s.io/release/v1.28.4/bin/linux/amd64/kubectl&quot;<br>sudo chmod +x kubectl<br>sudo mv kubectl /usr/local/bin/<br>kubectl version --client</pre><pre># Install eksctl<br>curl --silent --location &quot;https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz&quot; | tar xz -C /tmp<br>sudo mv /tmp/eksctl /usr/local/bin<br>eksctl version</pre><pre># Install Helm<br>sudo snap install helm --classic</pre><h3>2. Connect to the EC2 Instance and Configure AWS Credentials</h3><p>Once your EC2 instance is running:</p><pre># Configure AWS credentials<br>aws configure</pre><pre># Enter AWS Access Key ID<br># Enter AWS Secret Access Key<br># Default region: e.g., us-east-1<br># Default output format: json</pre><h3>3. Clone the Project Repository</h3><pre>git clone https://github.com/yourusername/your-project-repo.git<br>cd your-project-repo</pre><h3>4. Create Terraform Files for EKS Cluster and Networking</h3><p>Create the following Terraform files:</p><p><strong>provider.tf</strong></p><pre>provider &quot;aws&quot; {<br>  region = var.region<br>}</pre><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}</pre><p><strong>variables.tf</strong></p><pre>variable &quot;region&quot; {<br>  description = &quot;AWS region&quot;<br>  type        = string<br>  default     = &quot;us-east-1&quot;<br>}</pre><pre>variable &quot;eks_cluster_name&quot; {<br>  description = &quot;Name of the EKS cluster&quot;<br>  type        = string<br>  default     = &quot;php-rds-eks-cluster&quot;<br>}</pre><pre>variable &quot;eks_cluster_version&quot; {<br>  description = &quot;Kubernetes version for EKS cluster&quot;<br>  type        = string<br>  default     = &quot;1.28&quot;<br>}</pre><pre>variable &quot;vpc_cidr&quot; {<br>  description = &quot;CIDR block for VPC&quot;<br>  type        = string<br>  default     = &quot;10.0.0.0/16&quot;<br>}</pre><pre>variable &quot;environment&quot; {<br>  description = &quot;Environment name&quot;<br>  type        = string<br>  default     = &quot;dev&quot;<br>}</pre><p><strong>vpc.tf</strong></p><pre>module &quot;vpc&quot; {<br>  source = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;5.0.0&quot;</pre><pre>  name = &quot;${var.environment}-vpc&quot;<br>  cidr = var.vpc_cidr</pre><pre>  azs             = [&quot;${var.region}a&quot;, &quot;${var.region}b&quot;, &quot;${var.region}c&quot;]<br>  private_subnets = [&quot;10.0.1.0/24&quot;, &quot;10.0.2.0/24&quot;, &quot;10.0.3.0/24&quot;]<br>  public_subnets  = [&quot;10.0.101.0/24&quot;, &quot;10.0.102.0/24&quot;, &quot;10.0.103.0/24&quot;]</pre><pre>  enable_nat_gateway     = true<br>  single_nat_gateway     = true<br>  one_nat_gateway_per_az = false<br>  enable_vpn_gateway     = false</pre><pre>  public_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.eks_cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/elb&quot;                        = &quot;1&quot;<br>  }</pre><pre>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.eks_cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/internal-elb&quot;               = &quot;1&quot;<br>  }<br>}</pre><p><strong>eks-cluster.tf</strong></p><pre>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;~&gt; 19.0&quot;</pre><pre>  cluster_name    = var.eks_cluster_name<br>  cluster_version = var.eks_cluster_version</pre><pre>  vpc_id     = module.vpc.vpc_id<br>  subnet_ids = module.vpc.private_subnets</pre><pre>  cluster_endpoint_public_access = true<br>  cluster_endpoint_private_access = true</pre><pre>  # EKS Managed Node Group(s)<br>  eks_managed_node_group_defaults = {<br>    disk_size      = 50<br>    instance_types = [&quot;t3.medium&quot;]<br>  }</pre><pre>  eks_managed_node_groups = {<br>    main = {<br>      min_size     = 2<br>      max_size     = 4<br>      desired_size = 2</pre><pre>      instance_types = [&quot;t3.medium&quot;]<br>      capacity_type  = &quot;ON_DEMAND&quot;<br>    }<br>  }</pre><pre>  # OIDC Identity provider<br>  cluster_identity_providers = {<br>    sts = {<br>      client_id = &quot;sts.amazonaws.com&quot;<br>    }<br>  }</pre><pre>  # aws-auth configmap<br>  manage_aws_auth_configmap = true</pre><pre>  tags = {<br>    Environment = var.environment<br>    Terraform   = &quot;true&quot;<br>  }<br>}</pre><pre># IAM policy for AWS Load Balancer Controller<br>resource &quot;aws_iam_policy&quot; &quot;aws_load_balancer_controller&quot; {<br>  name        = &quot;AWSLoadBalancerControllerIAMPolicy&quot;<br>  description = &quot;AWS Load Balancer Controller IAM Policy&quot;<br>  <br>  policy = file(&quot;${path.module}/policies/load-balancer-controller-policy.json&quot;)<br>}</pre><pre># Output for connection commands<br>output &quot;configure_kubectl&quot; {<br>  description = &quot;Configure kubectl: Command to update kubeconfig&quot;<br>  value       = &quot;aws eks update-kubeconfig --name ${var.eks_cluster_name} --region ${var.region}&quot;<br>}</pre><p><strong>rds.tf</strong></p><pre>resource &quot;aws_db_subnet_group&quot; &quot;php_db_subnet_group&quot; {<br>  name       = &quot;${var.environment}-php-db-subnet-group&quot;<br>  subnet_ids = module.vpc.private_subnets</pre><pre>  tags = {<br>    Name = &quot;${var.environment}-php-db-subnet-group&quot;<br>  }<br>}</pre><pre>resource &quot;aws_security_group&quot; &quot;rds_sg&quot; {<br>  name        = &quot;${var.environment}-rds-sg&quot;<br>  description = &quot;Allow MySQL inbound traffic&quot;<br>  vpc_id      = module.vpc.vpc_id</pre><pre>  ingress {<br>    description     = &quot;MySQL from EKS&quot;<br>    from_port       = 3306<br>    to_port         = 3306<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [module.eks.cluster_security_group_id]<br>  }</pre><pre>  egress {<br>    from_port        = 0<br>    to_port          = 0<br>    protocol         = &quot;-1&quot;<br>    cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }</pre><pre>  tags = {<br>    Name = &quot;${var.environment}-rds-sg&quot;<br>  }<br>}</pre><pre>resource &quot;aws_db_instance&quot; &quot;php_db&quot; {<br>  allocated_storage      = 20<br>  storage_type           = &quot;gp2&quot;<br>  engine                 = &quot;mysql&quot;<br>  engine_version         = &quot;8.0&quot;<br>  instance_class         = &quot;db.t3.micro&quot;<br>  identifier             = &quot;${var.environment}-php-db&quot;<br>  username               = &quot;admin&quot;<br>  password               = &quot;Password123!&quot; # In production, use AWS Secrets Manager<br>  parameter_group_name   = &quot;default.mysql8.0&quot;<br>  db_subnet_group_name   = aws_db_subnet_group.php_db_subnet_group.name<br>  vpc_security_group_ids = [aws_security_group.rds_sg.id]<br>  skip_final_snapshot    = true<br>  publicly_accessible    = false<br>  multi_az               = false</pre><pre>  tags = {<br>    Name        = &quot;${var.environment}-php-db&quot;<br>    Environment = var.environment<br>  }<br>}</pre><pre>output &quot;rds_endpoint&quot; {<br>  description = &quot;The connection endpoint for the RDS instance&quot;<br>  value       = aws_db_instance.php_db.endpoint<br>}</pre><h3>5. Initialize and Apply Terraform Configuration</h3><pre># Initialize Terraform<br>terraform init</pre><pre># Preview the changes<br>terraform plan -var-file=dev.tfvars</pre><pre># Apply the configuration<br>terraform apply -var-file=dev.tfvars -auto-approve</pre><h3>Step 2: Set Up GitHub Actions CI Pipeline</h3><h3>1. Create GitHub Repository Secrets</h3><p>In your GitHub repository, add the following secrets:</p><ol><li>Go to your repository → Settings → Secrets and Variables → Actions</li><li>Click “New repository secret” and add:</li></ol><ul><li>AWS_ACCESS_KEY_ID: Your AWS access key ID</li><li>AWS_SECRET_ACCESS_KEY: Your AWS secret access key</li><li>AWS_REGION: Your AWS region</li><li>SONAR_TOKEN: SonarQube access token</li><li>SONAR_HOST_URL: SonarQube URL</li><li>ECR_REPOSITORY_FRONTEND: Name of your ECR repository for frontend</li><li>ECR_REPOSITORY_BACKEND: Name of your ECR repository for backend</li><li>ECR_REPOSITORY_PHP : Name of your ECR repository for PHP app that has combined code for be/fe</li></ul><h3>2. Create ECR Repositories</h3><pre># Create frontend repository<br>aws ecr create-repository --repository-name frontend --region us-east-1<br># Create backend repository<br>aws ecr create-repository --repository-name backend --region us-east-1<br>OR<br># Create combinedrepository<br>aws ecr create-repository --repository-name php-app --region us-east-1</pre><h3>3. Create GitHub Actions Workflow File for Infrastructure</h3><p>Create a file at .github/workflows/infra-deployment.yml:</p><pre>name: Infrastructure Deployment</pre><pre>on:<br>  push:<br>    branches: [main]<br>    paths:<br>      - &#39;terraform/**&#39;<br>  workflow_dispatch:</pre><pre>jobs:<br>  terraform:<br>    runs-on: ubuntu-latest<br>    defaults:<br>      run:<br>        working-directory: ./terraform</pre><pre>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Setup Terraform<br>        uses: hashicorp/setup-terraform@v3<br>        with:<br>          terraform_version: 1.5.7</pre><pre>      - name: Configure AWS credentials<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          aws-region: ${{ secrets.AWS_REGION }}</pre><pre>      - name: Terraform Init<br>        run: terraform init</pre><pre>      - name: Terraform Format<br>        run: terraform fmt -check</pre><pre>      - name: Terraform Validate<br>        run: terraform validate</pre><pre>      - name: Terraform Plan<br>        run: terraform plan -var-file=dev.tfvars</pre><pre>      - name: Terraform Apply<br>        if: github.ref == &#39;refs/heads/main&#39;<br>        run: terraform apply -var-file=dev.tfvars -auto-approve</pre><h3>4. Create GitHub Actions Workflow File for Frontend</h3><p>Create a file at .github/workflows/frontend-pipeline.yml:</p><pre>name: Frontend CI/CD Pipeline</pre><pre>on:<br>  push:<br>    branches: [main]<br>    paths:<br>      - &#39;frontend/**&#39;<br>  pull_request:<br>    branches: [main]<br>    paths:<br>      - &#39;frontend/**&#39;<br>  workflow_dispatch:</pre><pre>jobs:<br>  build-and-test:<br>    runs-on: ubuntu-latest<br>    <br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Setup Node.js<br>        uses: actions/setup-node@v4<br>        with:<br>          node-version: &#39;18&#39;<br>          cache: &#39;npm&#39;<br>          cache-dependency-path: frontend/package-lock.json</pre><pre>      - name: Install dependencies<br>        run: |<br>          cd frontend<br>          npm ci</pre><pre>      - name: Run tests<br>        run: |<br>          cd frontend<br>          npm test</pre><pre>      - name: SonarQube Scan<br>        uses: SonarSource/sonarqube-scan-action@master<br>        env:<br>          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}<br>          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}<br>        with:<br>          projectBaseDir: frontend<br>          args: &gt;<br>            -Dsonar.projectKey=frontend<br>            -Dsonar.projectName=frontend</pre><pre>      - name: SonarQube Quality Gate check<br>        uses: SonarSource/sonarqube-quality-gate-action@master<br>        timeout-minutes: 5<br>        env:<br>          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}<br>          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}</pre><pre>  build-and-push:<br>    needs: build-and-test<br>    if: github.event_name != &#39;pull_request&#39;<br>    runs-on: ubuntu-latest<br>    <br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Configure AWS credentials<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          aws-region: ${{ secrets.AWS_REGION }}</pre><pre>      - name: Login to Amazon ECR<br>        id: login-ecr<br>        uses: aws-actions/amazon-ecr-login@v2</pre><pre>      - name: Build, tag, and push image to Amazon ECR<br>        env:<br>          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>          ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_FRONTEND }}<br>          IMAGE_TAG: ${{ github.sha }}<br>        run: |<br>          cd frontend<br>          docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .<br>          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG</pre><pre>      - name: Run Amazon Inspector scan<br>        env:<br>          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>          ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_FRONTEND }}<br>          IMAGE_TAG: ${{ github.sha }}<br>        run: |<br>          aws inspector2 scan-ecr --repository-name $ECR_REPOSITORY --image-tags $IMAGE_TAG<br>          aws inspector2 list-findings --filter-criteria &#39;{&quot;findingStatus&quot;:[{&quot;comparison&quot;:&quot;EQUALS&quot;, &quot;value&quot;:&quot;ACTIVE&quot;}], &quot;resourceType&quot;:[{&quot;comparison&quot;:&quot;EQUALS&quot;, &quot;value&quot;:&quot;AWS_ECR_CONTAINER_IMAGE&quot;}]}&#39; --max-results 10</pre><pre>      - name: Update deployment file<br>        run: |<br>          git config --global user.name &#39;GitHub Actions&#39;<br>          git config --global user.email &#39;actions@github.com&#39;<br>          <br>          # Replace image tag in deployment YAML<br>          sed -i &quot;s|image: .*frontend:.*|image: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY_FRONTEND }}:${{ github.sha }}|g&quot; k8s-manifests/frontend/deployment.yaml<br>          <br>          git add k8s-manifests/frontend/deployment.yaml<br>          git commit -m &quot;Update frontend deployment image to version ${{ github.sha }}&quot;<br>          git push</pre><h3>5. Create GitHub Actions Workflow File for Backend</h3><p>Create a file at .github/workflows/backend-pipeline.yml:</p><pre>name: Backend CI/CD Pipeline</pre><pre>on:<br>  push:<br>    branches: [main]<br>    paths:<br>      - &#39;backend/**&#39;<br>  pull_request:<br>    branches: [main]<br>    paths:<br>      - &#39;backend/**&#39;<br>  workflow_dispatch:</pre><pre>jobs:<br>  build-and-test:<br>    runs-on: ubuntu-latest<br>    <br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Setup PHP<br>        uses: shivammathur/setup-php@v2<br>        with:<br>          php-version: &#39;8.2&#39;<br>          extensions: mbstring, intl, pdo_mysql<br>          coverage: xdebug</pre><pre>      - name: Install dependencies<br>        run: |<br>          cd backend<br>          composer install --no-progress --prefer-dist</pre><pre>      - name: Run tests<br>        run: |<br>          cd backend<br>          vendor/bin/phpunit</pre><pre>      - name: SonarQube Scan<br>        uses: SonarSource/sonarqube-scan-action@master<br>        env:<br>          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}<br>          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}<br>        with:<br>          projectBaseDir: backend<br>          args: &gt;<br>            -Dsonar.projectKey=backend<br>            -Dsonar.projectName=backend</pre><pre>      - name: SonarQube Quality Gate check<br>        uses: SonarSource/sonarqube-quality-gate-action@master<br>        timeout-minutes: 5<br>        env:<br>          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}<br>          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}</pre><pre>  build-and-push:<br>    needs: build-and-test<br>    if: github.event_name != &#39;pull_request&#39;<br>    runs-on: ubuntu-latest<br>    <br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Configure AWS credentials<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          aws-region: ${{ secrets.AWS_REGION }}</pre><pre>      - name: Login to Amazon ECR<br>        id: login-ecr<br>        uses: aws-actions/amazon-ecr-login@v2</pre><pre>      - name: Build, tag, and push image to Amazon ECR<br>        env:<br>          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>          ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_BACKEND }}<br>          IMAGE_TAG: ${{ github.sha }}<br>        run: |<br>          cd backend<br>          docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .<br>          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG</pre><pre>      - name: Run Amazon Inspector scan<br>        env:<br>          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>          ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_BACKEND }}<br>          IMAGE_TAG: ${{ github.sha }}<br>        run: |<br>          aws inspector2 scan-ecr --repository-name $ECR_REPOSITORY --image-tags $IMAGE_TAG<br>          aws inspector2 list-findings --filter-criteria &#39;{&quot;findingStatus&quot;:[{&quot;comparison&quot;:&quot;EQUALS&quot;, &quot;value&quot;:&quot;ACTIVE&quot;}], &quot;resourceType&quot;:[{&quot;comparison&quot;:&quot;EQUALS&quot;, &quot;value&quot;:&quot;AWS_ECR_CONTAINER_IMAGE&quot;}]}&#39; --max-results 10</pre><pre>      - name: Update deployment file<br>        run: |<br>          git config --global user.name &#39;GitHub Actions&#39;<br>          git config --global user.email &#39;actions@github.com&#39;<br>          <br>          # Replace image tag in deployment YAML<br>          sed -i &quot;s|image: .*backend:.*|image: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPOSITORY_BACKEND }}:${{ github.sha }}|g&quot; k8s-manifests/backend/deployment.yaml<br>          <br>          git add k8s-manifests/backend/deployment.yaml<br>          git commit -m &quot;Update backend deployment image to version ${{ github.sha }}&quot;<br>          git push</pre><h3>Step 3: Set Up a Jump Server for Cluster Management</h3><h3>1. Create a Jump Server in AWS</h3><p><strong>Launch EC2 Instance:</strong></p><ul><li>Go to AWS EC2 Console → Launch Instance</li><li>Name it “jump-server”</li><li>Choose Ubuntu AMI</li><li>Select t2.medium instance type</li><li>Create or select a key pair</li><li>Network Settings:</li><li>VPC: Select the VPC created by Terraform</li><li>Subnet: Choose a public subnet</li><li>Auto-assign public IP: Enable</li><li>Configure Security Group:</li><li>Allow SSH (port 22) from your IP</li><li>Add User Data script:</li></ul><pre>#!/bin/bash<br>sudo apt update -y</pre><pre># Installing AWS CLI<br>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>sudo apt install unzip -y<br>unzip awscliv2.zip<br>sudo ./aws/install</pre><pre># Installing Kubectl<br>sudo apt update<br>sudo apt install curl -y<br>sudo curl -LO &quot;https://dl.k8s.io/release/v1.28.4/bin/linux/amd64/kubectl&quot;<br>sudo chmod +x kubectl<br>sudo mv kubectl /usr/local/bin/<br>kubectl version --client</pre><pre># Installing Helm<br>sudo snap install helm --classic</pre><pre># Installing eksctl<br>curl --silent --location &quot;https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz&quot; | tar xz -C /tmp<br>sudo mv /tmp/eksctl /usr/local/bin<br>eksctl version</pre><h3>2. Connect to the Jump Server</h3><ul><li>Use SSH to connect to the jump server</li><li>Configure AWS credentials:</li></ul><pre>aws configure<br># Enter AWS Access Key ID, Secret Access Key, region, and output format</pre><h3>3. Update kubeconfig to Access the EKS Cluster</h3><pre>aws eks update-kubeconfig --name php-rds-eks-cluster --region us-east-1</pre><h3>4. Verify the Cluster Connection</h3><pre>kubectl get nodes<br>kubectl get pods --all-namespaces</pre><h3>Step 4: Configure AWS Load Balancer Controller on EKS</h3><h3>1. Create IAM Policy and Service Account</h3><pre># Create policy file<br>curl -o load-balancer-controller-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json</pre><pre># Create IAM policy<br>aws iam create-policy \<br>    --policy-name AWSLoadBalancerControllerIAMPolicy \<br>    --policy-document file://load-balancer-controller-policy.json</pre><pre># Note the Policy ARN from the output</pre><pre># Create service account<br>eksctl create iamserviceaccount \<br>  --cluster=php-rds-eks-cluster \<br>  --namespace=kube-system \<br>  --name=aws-load-balancer-controller \<br>  --role-name AmazonEKSLoadBalancerControllerRole \<br>  --attach-policy-arn=arn:aws:iam::&lt;AWS_ACCOUNT_ID&gt;:policy/AWSLoadBalancerControllerIAMPolicy \<br>  --approve \<br>  --region=us-east-1</pre><h3>2. Install AWS Load Balancer Controller with Helm</h3><pre># Add Helm repo<br>helm repo add eks https://aws.github.io/eks-charts<br>helm repo update</pre><pre># Install AWS Load Balancer Controller<br>helm install aws-load-balancer-controller eks/aws-load-balancer-controller \<br>  --namespace kube-system \<br>  --set clusterName=php-rds-eks-cluster \<br>  --set serviceAccount.create=false \<br>  --set serviceAccount.name=aws-load-balancer-controller</pre><h3>3. Verify the Installation</h3><pre>kubectl get pods -n kube-system | grep aws-load-balancer-controller</pre><h3>Step 5: Set Up and Configure ArgoCD on EKS</h3><h3>1. Create a Namespace for ArgoCD</h3><pre>kubectl create namespace argocd</pre><h3>2. Install ArgoCD</h3><pre>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml</pre><h3>3. Verify ArgoCD Installation</h3><pre>kubectl get pods -n argocd</pre><h3>4. Expose ArgoCD Server</h3><pre>kubectl patch svc argocd-server -n argocd -p &#39;{&quot;spec&quot;: {&quot;type&quot;: &quot;LoadBalancer&quot;}}&#39;</pre><h3>5. Get the ArgoCD Load Balancer URL</h3><pre>kubectl get svc argocd-server -n argocd</pre><h3>6. Retrieve the ArgoCD Admin Password</h3><pre>kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath=&quot;{.data.password}&quot; | base64 --decode</pre><h3>7. Access ArgoCD UI</h3><ul><li>Use the External IP from step 5</li><li>Login with:</li><li>Username: admin</li><li>Password: from step 6</li></ul><h3>Step 6: Configure SonarQube for Code Analysis</h3><h3>1. Deploy SonarQube on EKS</h3><pre># Create namespace<br>kubectl create namespace sonarqube</pre><pre># Create persistent volume<br>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: sonarqube-data<br>  namespace: sonarqube<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 10Gi<br>EOF</pre><pre># Deploy SonarQube<br>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: sonarqube<br>  namespace: sonarqube<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: sonarqube<br>  template:<br>    metadata:<br>      labels:<br>        app: sonarqube<br>    spec:<br>      containers:<br>      - name: sonarqube<br>        image: sonarqube:lts<br>        ports:<br>        - containerPort: 9000<br>        volumeMounts:<br>        - name: sonarqube-data<br>          mountPath: /opt/sonarqube/data<br>        env:<br>        - name: SONARQUBE_JDBC_URL<br>          value: &quot;jdbc:h2:tcp://localhost:9092/sonar&quot;<br>        resources:<br>          limits:<br>            memory: &quot;3Gi&quot;<br>            cpu: &quot;1000m&quot;<br>          requests:<br>            memory: &quot;2Gi&quot;<br>            cpu: &quot;500m&quot;<br>      volumes:<br>      - name: sonarqube-data<br>        persistentVolumeClaim:<br>          claimName: sonarqube-data<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: sonarqube<br>  namespace: sonarqube<br>spec:<br>  type: LoadBalancer<br>  ports:<br>  - port: 9000<br>    targetPort: 9000<br>  selector:<br>    app: sonarqube<br>EOF</pre><h3>2. Get SonarQube URL</h3><pre>kubectl get svc -n sonarqube</pre><h3>3. Setup SonarQube</h3><p>Access SonarQube at the LoadBalancer URL and:</p><ul><li>Login with default credentials (admin/admin)</li><li>Change the default password</li><li>Create two projects:</li><li>Frontend</li><li>Backend</li><li>Generate an authentication token for GitHub Actions</li><li>Configure Quality Gates</li></ul><h3>Step 7: Application Deployment with ArgoCD</h3><h3>1. Create Kubernetes Namespace for the Application</h3><pre>kubectl create namespace php-app</pre><h3>2. Configure ArgoCD to Track Git Repository</h3><p>In the ArgoCD UI:</p><ol><li>Click on “Settings” → “Repositories” → “Connect Repo”</li><li>Enter your Git repository URL</li><li>Add authentication details if needed</li><li>Click “Connect”</li></ol><h3>3. Create ArgoCD Applications</h3><p>For each component, create an application in ArgoCD:</p><p><strong>Database:</strong></p><ul><li>Application Name: php-db</li><li>Project: default</li><li>Sync Policy: Automatic</li><li>Repository URL: Your Git repo URL</li><li>Path: k8s-manifests/database</li><li>Cluster: <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a></li><li>Namespace: php-app</li></ul><p><strong>Backend:</strong></p><ul><li>Application Name: php-backend</li><li>Project: default</li><li>Sync Policy: Automatic</li><li>Repository URL: Your Git repo URL</li><li>Path: k8s-manifests/backend</li><li>Cluster: <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a></li><li>Namespace: php-app</li></ul><p><strong>Frontend:</strong></p><ul><li>Application Name: php-frontend</li><li>Project: default</li><li>Sync Policy: Automatic</li><li>Repository URL: Your Git repo URL</li><li>Path: k8s-manifests/frontend</li><li>Cluster: <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a></li><li>Namespace: php-app</li></ul><p><strong>Ingress:</strong></p><ul><li>Application Name: php-ingress</li><li>Project: default</li><li>Sync Policy: Automatic</li><li>Repository URL: Your Git repo URL</li><li>Path: k8s-manifests/ingress</li><li>Cluster: <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a></li><li>Namespace: php-app</li></ul><h3>4. Check Deployment Status</h3><p>In the ArgoCD UI, verify that all applications are synced and healthy.</p><h3>Step 8: Set Up Monitoring with Prometheus and Grafana</h3><h3>1. Create Monitoring Namespace</h3><pre>kubectl create namespace monitoring</pre><h3>2. Install Prometheus and Grafana using Helm</h3><pre># Add Helm repositories<br>helm repo add stable https://charts.helm.sh/stable<br>helm repo add prometheus-community https://prometheus-community.github.io/helm-charts<br>helm repo add grafana https://grafana.github.io/helm-charts<br>helm repo update</pre><pre># Install Prometheus Stack (includes Grafana)<br>helm install prometheus prometheus-community/kube-prometheus-stack \<br>  --namespace monitoring \<br>  --set prometheus.service.type=LoadBalancer \<br>  --set grafana.service.type=LoadBalancer \<br>  --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \<br>  --set prometheus.prometheusSpec.podMonitorSelectorNilUsesH</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ohc39eHq0eziBebi" /></figure><h3>3. Access Prometheus UI</h3><ul><li>Get the Prometheus service details:</li></ul><p>kubectl get svc #look for prometheus-kube-prometheus-prometheus svc</p><p>Change the serveice type from ClusterIP to Loadbalancer</p><ul><li>kubectl edit svc prometheus-kube-prometheus-prometheus</li><li>Find the line type: ClusterIP and change it to type: LoadBalancer.</li><li>You can now access the prometheus server using external-IP of prometheus-kube-prometheus-prometheus svc</li></ul><p>kubectl get svc prometheus-kube-prometheus-prometheus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dE5NMY7QS5z_EkIC" /></figure><ul><li>Open &lt;External-IP&gt;:9999 in your browser.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zllP0xKs-UecZsNn" /></figure><ul><li>Click on Status and select Target. You’ll see a list of Targets displayed. In Grafana, we’ll use this as a data source.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TdFv2tOdpWwQ9zso" /></figure><h3>4. Access Grafana UI</h3><ul><li>Get the Grafana service details</li><li>kubectl get svc #look for the prometheus-grafana svc</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L2uhaoY9nDCKS14e" /></figure><ul><li>By default, it uses ClusterIP. Change it to LoadBalancer:</li><li>kubectl edit svc prometheus-grafana</li><li>Find the line type: ClusterIP and change it to type: LoadBalancer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*bx2kTU8X9prIFU4U" /></figure><ul><li>kubectl get svc prometheus-grafana</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3W3yWNu8Cp1tjlFx" /></figure><ul><li>Open &lt;EXTERNAL-IP&gt; in your browser.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EW0IPzq4scWo_A2S" /></figure><h3>5. Get Grafana Admin Password</h3><p>kubectl get secret grafana -n default -o jsonpath=&quot;{.data.admin-password}&quot; | base64 --decode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*azbVjJBvBNs_1Bf4" /></figure><ul><li>Username: adminPassword: (output from the above command)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qbvwUBjtS5bVTdbq" /></figure><h3>6. Configure Prometheus as a Data Source in Grafana</h3><ol><li>Login to Grafana UI.</li><li>Go to Connections → Data Sources.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5n6u_mSewT3SijIM" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YgiiAwlewiqje4Gg" /></figure><ol><li>Click Data source → Select Prometheus</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mjQisOdWVkms1gH0" /></figure><ol><li>Provide the Prometheus URL (&lt;prometheus-loadbalancer-dns&gt;:9090) if not get provided.</li><li>Click Save &amp; Test.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PFqGFYw7NYXdbKsU" /></figure><blockquote>🎉 Congratulations! Your Kubernetes cluster is now being monitored using Prometheus &amp; Grafana!</blockquote><h3>7. Setting Up Dashboards in Grafana for Kubernetes Monitoring</h3><p>Grafana allows us to visualize Kubernetes cluster and resource metrics effectively. We’ll set up two essential dashboards to monitor our cluster using Prometheus as the data source.</p><h4>Dashboard 1: Kubernetes Cluster Monitoring</h4><p>This dashboard provides an overview of the Kubernetes cluster, including node health, resource usage, and workload performance.</p><p>Steps to Import the Dashboard:</p><ul><li>Open the Grafana UI and navigate to Dashboards.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NIh5USvTAsdUqdZQ" /></figure><ul><li>Click on New → Import.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lnREf2Wlw_lUUdP_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HAzYEKpilK9M9p0h" /></figure><ul><li>In the Import via <a href="http://grafana.com/">Grafana.com</a> field, enter 6417 (Prometheus Kubernetes Cluster Monitoring Dashboard).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p9Jo6dYONfUCc6_D" /></figure><ul><li>Click Load.</li><li>Select Prometheus as the data source.</li><li>Click Import.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uvoXumvFKCDo_wW2" /></figure><blockquote>You should now see a comprehensive dashboard displaying Kubernetes cluster metrics.</blockquote><h4>Dashboard 2: Kubernetes Resource Monitoring</h4><p>This dashboard provides insights into individual Kubernetes resources such as pods, deployments, and namespaces.</p><p>Steps to Import the Dashboard:</p><ol><li>Open the Grafana UI and navigate to Dashboards.</li><li>Click on New → Import.</li><li>Enter 17375 (Kubernetes Resources Monitoring Dashboard).</li><li>Click Load.</li><li>Select Prometheus as the data source.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JScnCsHcWWoU3I5X" /></figure><ol><li>select the data source i.e. prometheus and click on import</li><li>Click Import.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KUEcvd44aMm7C2va" /></figure><blockquote>Now, you have two powerful dashboards to monitor both the overall cluster health and specific Kubernetes resources in real-time.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8501481690d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why AWS Remains the No. 1 Choice for Cloud Services]]></title>
            <link>https://sheraziqbal.medium.com/why-aws-remains-the-no-1-choice-for-cloud-services-0a831385c59f?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a831385c59f</guid>
            <category><![CDATA[best]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[no1]]></category>
            <category><![CDATA[awsvsazure]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Sat, 01 Mar 2025 11:26:05 GMT</pubDate>
            <atom:updated>2025-03-01T11:26:05.330Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Market Leadership &amp; Maturity</h3><p><strong>First &amp; Largest Cloud Provider: </strong>AWS launched in 2006, ahead of Azure (2010), making it more mature with a <strong>wider adoption</strong>.<br><strong>Largest Market Share: </strong>AWS consistently leads the cloud market, meaning <strong>more community support, documentation, and expertise</strong>.</p><h3>2. Global Infrastructure &amp; Reliability</h3><p><strong>More Regions &amp; Availability Zones (AZs): </strong>AWS has <strong>32 regions &amp; 102 AZs</strong>, whereas Azure has <strong>60+ data centers but fewer distinct regions</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0KDl9n5GcEdQO5J1x6A6Gg.png" /><figcaption><a href="https://scholarkai.com/visa-sponsored-warehouse-jobs-in-luxembourg-for-foreigners-2024/">https://scholarkai.com/visa-sponsored-warehouse-jobs-in-luxembourg-for-foreigners-2024/</a></figcaption></figure><p><strong>Better Uptime &amp; SLAs: </strong>AWS generally <strong>outperforms Azure</strong> in <strong>reliability and resilience</strong> based on industry reports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/0*CLcZk44S8AsLXBzG.jpg" /><figcaption><a href="https://aws.amazon.com/blogs/publicsector/achieving-five-nines-cloud-justice-public-safety/">https://aws.amazon.com/blogs/publicsector/achieving-five-nines-cloud-justice-public-safety/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*BBzUOxXYeMXivQBQ.jpg" /><figcaption>This is a reference architecture of a system built in the AWS Cloud that can achieve five nines using services such as <a href="https://aws.amazon.com/ec2/">Amazon Elastic Compute Cloud (Amazon EC2)</a>, <a href="https://aws.amazon.com/elasticloadbalancing/">Elastic Load Balancing (ELB)</a>, and <a href="https://aws.amazon.com/rds/aurora/">Amazon Aurora</a> deployed in a Virtual Private Cloud (VPC). It also uses multiple availability zones in both AWS Regions with <a href="https://aws.amazon.com/route53/">Amazon Route 53</a> for health-based routing of client traffic.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/0*ZSPw47yhkcl7T0y2.jpg" /><figcaption>This shows how these solutions could be designed to be serverless by using services such as <a href="https://aws.amazon.com/lambda/">AWS Lambda</a>, <a href="https://aws.amazon.com/dynamodb/">Amazon DynamoDB</a>, and <a href="https://aws.amazon.com/api-gateway/">Amazon API Gateway</a> to power an application.</figcaption></figure><h3>3. Scalability &amp; Performance</h3><p><strong>Best-in-Class Compute Power</strong>: AWS Graviton processors <strong>reduce costs and improve performance</strong> vs. Azure’s standard VMs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xRAjlQ1EN80xaf7h.png" /><figcaption><a href="https://aws.amazon.com/ec2/graviton/graviton-savings-dashboard/">https://aws.amazon.com/ec2/graviton/graviton-savings-dashboard/</a></figcaption></figure><p><strong>Superior Auto-Scaling: </strong>AWS has 6 type of scaling options for you in <strong>Auto Scaling with EC2 Spot Instances</strong> and On Demand Instances, Serverless Scaling, Database Scaling with optimize costs and scale workloads better than Azure’s autoscale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*npSuUA2AFAqKULB8.png" /></figure><h3>4. Cost Optimization</h3><p><strong>Flexible Pricing Models: </strong>AWS offers <strong>Savings Plans, Reserved Instances, and Spot Instances</strong>, often reducing costs <strong>more than Azure’s reservations</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KOK5WrRAu9HyOuAV.png" /><figcaption><a href="https://zesty.co/blog/what-are-the-aws-pricing-models/">https://zesty.co/blog/what-are-the-aws-pricing-models/</a></figcaption></figure><p><strong>AWS Graviton Processors: </strong>Custom <strong>ARM-based instances</strong> offer <strong>40% better price-performance</strong> over traditional Intel/AMD instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5MQHt5KEWRSUo5Y7" /><figcaption><a href="https://www.zdnet.com/article/aws-graviton2-what-it-means-for-arm-in-the-data-center-cloud-enterprise-aws/">https://www.zdnet.com/article/aws-graviton2-what-it-means-for-arm-in-the-data-center-cloud-enterprise-aws/</a></figcaption></figure><h3>5. Service Breadth &amp; Innovation</h3><p><strong>More Services &amp; Features: </strong>AWS has <strong>200+ services</strong>, leading in <strong>serverless, containers, IoT, Robotics and AI/ML</strong> (e.g., Bedrock, Lambda, SageMaker, ECR, ECS, EKS, Fargate, IoT Greengrass).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*elYsXm-PQYtAy1io" /><figcaption><a href="https://cloudkatha.com/top-11-aws-services-list-2022-which-one-is-your-favourite/">https://cloudkatha.com/top-11-aws-services-list-2022-which-one-is-your-favourite/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Uw40JJQnLkfKvR-C.jpeg" /><figcaption><a href="https://faun.pub/aws-services-how-many-are-there-really-bc39b9d2cc53">https://faun.pub/aws-services-how-many-are-there-really-bc39b9d2cc53</a></figcaption></figure><p><strong>Multi-Cloud &amp; Hybrid Leadership: </strong>AWS <strong>integrates better</strong> with third-party tools and multi-cloud strategies than others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDG0Yl0co9r1SCIZ0jEg1g.png" /><figcaption><a href="https://aws.amazon.com/hybrid-multicloud/">https://aws.amazon.com/hybrid-multicloud/</a></figcaption></figure><p><strong>Better Networking: </strong>AWS <strong>VPC</strong> is more flexible than Azure VNet, and <strong>AWS Direct Connect</strong> has lower latency vs. Azure ExpressRoute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kaLELRz2_Tj96-Z0.jpg" /><figcaption><a href="https://devblogs.microsoft.com/premier-developer/differentiating-between-azure-virtual-network-vnet-and-aws-virtual-private-cloud-vpc/">https://devblogs.microsoft.com/premier-developer/differentiating-between-azure-virtual-network-vnet-and-aws-virtual-private-cloud-vpc/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8-wJvcfovr77bSGS.png" /><figcaption><a href="https://docs.aws.amazon.com/whitepapers/latest/aws-vpc-connectivity-options/aws-direct-connect.html">https://docs.aws.amazon.com/whitepapers/latest/aws-vpc-connectivity-options/aws-direct-connect.html</a></figcaption></figure><h3>6. AI &amp; Machine Learning</h3><p><strong>Strong AI/ML Capabilities: </strong>AWS SageMaker is a <strong>leader</strong> in AI/ML, with broader adoption than Azure ML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Za0iPmgjwWuegJzI.png" /><figcaption><a href="https://aws.amazon.com/compare/the-difference-between-artificial-intelligence-and-machine-learning/">https://aws.amazon.com/compare/the-difference-between-artificial-intelligence-and-machine-learning/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*IAVv9eBWiJrBo3iv" /></figure><p><strong>Generative AI &amp; Innovation: </strong>AWS <strong>Bedrock</strong> supports multiple AI models, while Azure focuses mainly on OpenAI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XbhnCAndeRZzbcIz.png" /></figure><h3>Security &amp; Compliance</h3><p><strong>AWS Security is Battle-Tested: </strong>AWS has <strong>more security certifications</strong> and a stronger track record in <strong>zero-downtime</strong> compliance updates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CNHNy8uPZjQBo-KZ.png" /><figcaption><a href="https://docs.aws.amazon.com/whitepapers/latest/aws-overview/security-services.html">https://docs.aws.amazon.com/whitepapers/latest/aws-overview/security-services.html</a></figcaption></figure><p><strong>Superior Identity &amp; Access Management (IAM): </strong>AWS IAM is often considered <strong>more granular</strong> than Azure’s RBAC system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*TQD21YBS8Vbb2IK7.png" /><figcaption><a href="https://jayendrapatil.com/aws-iam-access-management/">https://jayendrapatil.com/aws-iam-access-management/</a></figcaption></figure><p>Would you like a cost comparison or a migration plan to AWS? Tell me in Comment and I’ll write it for you.</p><p><a href="https://www.fiverr.com/s/XL3QYK0">You are Welcome to contact me for your help in AWS.</a></p><p><a href="https://scholarkai.com/">Happy Clouding with AWS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a831385c59f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure Amazon ECR Credential Helper for seamless integration, Auth, Login and Pull Docker Images]]></title>
            <link>https://sheraziqbal.medium.com/configure-amazon-ecr-credential-helper-for-seamless-integration-auth-login-and-pull-docker-images-c3d317df5d7c?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3d317df5d7c</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[ecrcredentialhelper]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ecr]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 11:09:14 GMT</pubDate>
            <atom:updated>2025-01-07T12:01:36.314Z</atom:updated>
            <content:encoded><![CDATA[<h4>across various operating systems and environments</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M7ANBzQhEXTKgU6c.png" /><figcaption>ECR Credential Helper</figcaption></figure><h3><strong>Why We Need This?</strong></h3><p>To pull images from a private AWS ECR repository, Docker requires a login token since it doesn’t directly use IAM. The aws ecr get-login-password command generates a temporary token for authentication,<strong> valid for 12 hours. Once expired, reauthentication is required.</strong></p><p>Manually renewing tokens or scripting this process often leads to deployment failures in CI/CD pipelines due to expired credentials. Using the Amazon ECR Docker Credential Helper automates authentication, ensuring seamless and reliable ECR access.</p><h3>Prerequisites</h3><ul><li><strong>Docker Installed</strong>: Ensure Docker 1.11 or newer is installed.</li><li><strong>AWS CLI Installed</strong>: For managing credentials and interacting with ECR.</li><li><strong>AWS Credentials</strong>: Ensure you have credentials available either through the shared credentials file (~/.aws/credentials), environment variables, or an IAM role.</li><li>Go to 2nd Section Directly if you have installed <strong><em>amazon-ecr-credential-helper </em></strong>in your relevent Operating System and Want to Configure it.</li></ul><h3>Step-by-Step Guide</h3><h4>1. Install Amazon ECR Credential Helper</h4><p>Choose the appropriate <a href="https://github.com/awslabs/amazon-ecr-credential-helper?tab=readme-ov-file#configuration">installation method for your operating system.</a></p><p><strong>Ubuntu (20.04 and newer)</strong>:</p><ol><li>Install using the system’s package manager:</li></ol><pre>sudo apt update<br>sudo apt install amazon-ecr-credential-helper</pre><p>2. Verify installation:</p><pre>docker-credential-ecr-login -v</pre><p><strong>Amazon Linux 2 (AL2)</strong>:</p><ol><li>Enable Docker extras and install:</li></ol><pre>sudo amazon-linux-extras enable docker<br>sudo yum install amazon-ecr-credential-helper</pre><p>2. Verify installation:</p><pre>docker-credential-ecr-login -v</pre><p><strong>MacOS</strong>:</p><p>Use Homebrew:</p><ol><li>Install via Homebrew:</li></ol><pre>brew install docker-credential-helper-ecr</pre><p>2. Verify installation:</p><pre>docker-credential-ecr-login -v</pre><p>Alternatively, use MacPorts:</p><pre>sudo port install docker-credential-helper-ecr</pre><p><strong>From Source (Linux or macOS) If ecr-cred-helper is not available for your OS</strong>:</p><ol><li>Install Go if not already installed.</li><li>Clone the repository:</li></ol><pre>git clone https://github.com/awslabs/amazon-ecr-credential-helper.git<br>cd amazon-ecr-credential-helper</pre><p>3. Build the binary:</p><pre>make docker<br>sudo mv bin/local/docker-credential-ecr-login /usr/local/bin/</pre><p>4. Verify installation:</p><pre>docker-credential-ecr-login -v</pre><p><strong>Windows</strong>:</p><ol><li>Download the binary from <a href="https://github.com/awslabs/amazon-ecr-credential-helper/releases">GitHub Releases</a>.</li><li>Add the binary path to your system’s PATH environment variable.</li></ol><h4><strong>2. Configure Docker to Use ECR Credential Helper</strong></h4><p>Edit or create the Docker <a href="https://github.com/awslabs/amazon-ecr-credential-helper?tab=readme-ov-file#configuration">configuration</a> file at ~/.docker/config.json:</p><ul><li>To use the credential helper for all Amazon ECR registries:</li></ul><pre>{<br>      &quot;credsStore&quot;: &quot;ecr-login&quot;<br>  }</pre><ul><li>To use the credential helper for specific ECR registries:</li></ul><pre>{<br>      &quot;credHelpers&quot;: {<br>          &quot;&lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com&quot;: &quot;ecr-login&quot;,<br>          &quot;public.ecr.aws&quot;: &quot;ecr-login&quot;<br>      }<br>  }</pre><ul><li>For multiple registries, combine credHelpers and auths:</li></ul><pre>{<br>      &quot;credHelpers&quot;: {<br>          &quot;&lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com&quot;: &quot;ecr-login&quot;<br>      },<br>      &quot;auths&quot;: {<br>          &quot;ghcr.io&quot;: {<br>              &quot;auth&quot;: &quot;BASE64_AUTH_TOKEN&quot;<br>          }<br>      }<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*BOJDSwVlihMWarXr" /></figure><h4>3. Authenticate with ECR</h4><p>The credential helper automatically handles authentication. To test:</p><ol><li>Pull an image from your ECR repository:</li></ol><pre>docker pull &lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com/&lt;repository&gt;:&lt;tag&gt;</pre><p>2. Push an image:</p><pre>docker push &lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com/&lt;repository&gt;:&lt;tag&gt;</pre><h4>4. Manage AWS Credentials</h4><p>The helper supports various AWS credentials mechanisms:</p><ul><li><strong>Shared credentials file (</strong><strong>~/.aws/credentials)</strong>: Add your credentials:</li></ul><pre>[default]<br>  aws_access_key_id = YOUR_ACCESS_KEY<br>  aws_secret_access_key = YOUR_SECRET_KEY</pre><ul><li><strong>Environment variables</strong>:</li></ul><pre>export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY<br>export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY</pre><ul><li><strong>IAM roles</strong>:</li><li>Attach an IAM role to an EC2 instance or ECS task.</li><li>Ensure the role has policies granting access to ECR.</li></ul><p>For named profiles:</p><pre>export AWS_PROFILE=your_profile_name</pre><h3>5. Example of a config.json File with Credential Store and Helpers</h3><p>Below is an example of a ~/.docker/config.json file configured to use credential helpers for both AWS ECR and Docker Hub. This setup assumes that tokens from ECR expire after 12 hours, and Docker Hub uses a credential helper like docker-credential-desktop.</p><h4>~/.docker/config.json</h4><pre>{<br>    &quot;credsStore&quot;: &quot;desktop&quot;,<br>    &quot;credHelpers&quot;: {<br>        &quot;123456789012.dkr.ecr.us-east-1.amazonaws.com&quot;: &quot;ecr-login&quot;,<br>        &quot;docker.io&quot;: &quot;desktop&quot;<br>    },<br>    &quot;auths&quot;: {<br>        &quot;123456789012.dkr.ecr.us-east-1.amazonaws.com&quot;: {},<br>        &quot;docker.io&quot;: {}<br>    }<br>}</pre><ul><li><strong>credsStore</strong>: Specifies the default credential store (e.g., Docker Desktop credential store).</li><li><strong>credHelpers</strong>: Overrides for specific registries. For AWS ECR, ecr-login is specified, which uses the docker-credential-ecr-login helper to fetch ECR credentials. For Docker Hub, the default desktop credential store is used.</li><li><strong>auths</strong>: Specifies which registries require authentication. The empty objects {} are placeholders.</li></ul><h3>6. Troubleshooting</h3><ul><li><strong>Permission Issues</strong>: Ensure your IAM policies allow actions like ecr:GetAuthorizationToken, ecr:BatchGetImage, and ecr:GetDownloadUrlForLayer.</li><li><strong>Binary Not Found</strong>: Ensure the docker-credential-ecr-login binary is in your PATH.</li><li><strong>Configuration Errors</strong>: Validate ~/.docker/config.json using:</li></ul><pre>cat ~/.docker/config.json</pre><h3>7. (Alternative) Automating Reauthentication for AWS ECR with a Cron Job</h3><p>Since ECR tokens expire every 12 hours, you’ll need a mechanism to reauthenticate periodically. If you are not comfortable with using ecr-cred-store. You can use CronJob.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sBysasHZOlUmojox.png" /></figure><p>So Achieve this with a Bash script and a Cron job.</p><h4>Bash Script: ecr_reauth.sh</h4><pre>#!/bin/bash<br>AWS_REGION=&quot;us-east-1&quot;<br>ECR_REGISTRY_ID=&quot;Enter your Registry/AWS AccountID&quot;<br># Authenticate Docker to the ECR registry<br>$(aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin &quot;$ECR_REGISTRY_ID.dkr.ecr.$AWS_REGION.amazonaws.com&quot;)<br># Optional: Pull an image to ensure the token is valid<br>docker pull &quot;$ECR_REGISTRY_ID.dkr.ecr.$AWS_REGION.amazonaws.com/your-repository:latest&quot;<br># Log output for debugging<br>echo &quot;Reauthenticated to ECR at $(date)&quot; &gt;&gt; /var/log/ecr_reauth.log</pre><h4>Make the Script Executable</h4><p>Run the following command to make the script executable:</p><pre>chmod +x ecr_reauth.sh</pre><h4>Set Up a Cron Job</h4><p>Edit the crontab file:</p><pre>crontab -e</pre><p>Add the following line to run the script every 11 hours (to avoid token expiration):</p><pre>0 */11 * * * /path/to/ecr_reauth.sh</pre><ul><li><strong>0 */11 * * *</strong>: This means the script will run every 11 hours.</li><li>Replace /path/to/ecr_reauth.sh with the full path to your script.</li></ul><h3>Logging and Debugging</h3><p>The script appends a log entry to /var/log/ecr_reauth.log every time it successfully authenticates. You can monitor this log file for troubleshooting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UV_Lout8lZ_jhsY3" /><figcaption>Photo by <a href="https://unsplash.com/@nublson?utm_source=medium&amp;utm_medium=referral">Nubelson Fernandes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Summary</h3><p>Using the Amazon ECR Credential Helper eliminates the need for manual token refreshes by securely managing Docker authentication to ECR. Once installed and configured, the helper seamlessly integrates with Docker workflows. For enhanced security and automation, leverage IAM roles and the AWS credentials file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3d317df5d7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up CICD with Bitbucket Pipelines with Docker Build to Deploy]]></title>
            <link>https://sheraziqbal.medium.com/setting-up-cicd-with-bitbucket-pipelines-from-build-to-deploy-230874cb9a50?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/230874cb9a50</guid>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 16:44:17 GMT</pubDate>
            <atom:updated>2025-01-07T10:21:57.442Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build Store Deploy Docker Images to ECR and Deploy to EC2 via SSH</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/0*Uwuj6sqYZwIB5qg0" /><figcaption>bitbucket cicd with build push deploy</figcaption></figure><p>In this tutorial, we&#39;ll walk you through setting up a Bitbucket Pipeline to automatically build and deploy Docker images to an EC2 instance. This pipeline will:</p><ol><li>Build a Docker image.</li><li>Push it to Amazon ECR (Elastic Container Registry).</li><li>Deploy it to an EC2 instance by pulling the image from ECR and running it on the EC2 instance.</li></ol><h3>Prerequisites:</h3><ul><li>A Bitbucket repository with access to your codebase.</li><li>A running EC2 instance with Docker installed.</li><li>AWS ECR (Elastic Container Registry) to store Docker images.</li><li>AWS IAM credentials with permissions to access ECR and manage EC2 instances.</li><li>SSH key to connect Bitbucket to your EC2 instance.</li></ul><h3>Step 1: Set up your Bitbucket Repository</h3><p>First, ensure your repository has a Dockerfile in its root directory that defines how to build your Docker image. Here is a simple example:</p><p><strong>Dockerfile:</strong></p><pre>FROM node:18.20<br>WORKDIR /app<br>COPY package*.json ./<br>RUN npm install --force<br>COPY . .<br>EXPOSE 3005<br><br># Default to production mode if not specified<br>CMD [&quot;sh&quot;, &quot;-c&quot;, &quot;npm run start || npm run start-dev || npm run start-stage || npm run prod || npm run dev&quot;]<br>#CMD [&quot;npm&quot;, &quot;start&quot;]</pre><h3>Step 2: Set Up Bitbucket Pipelines</h3><p>Next, configure Bitbucket Pipelines to automate the build and deployment process. You&#39;ll need to create a bitbucket-pipelines.yml file at the root of your repository.</p><p>This file defines the stages of your pipeline: <strong>Build</strong> and <strong>Deploy</strong>.</p><p><strong>bitbucket-pipelines.yml:</strong></p><pre>image: atlassian/default-image:2  # Use the default Bitbucket Docker image<br><br>pipelines:<br>  branches:<br>    dev:<br>      - step:<br>          name: Build Docker Image<br>          services:<br>            - docker  # Add Docker as a service<br>          caches:<br>            - docker  # Cache Docker layers to speed up builds<br>          script:<br>            # Log into AWS using Bitbucket environment variables<br>            - echo &quot;Logging into AWS ECR&quot;<br><br>            # Install AWS CLI if it&#39;s not installed<br>            - apt-get update &amp;&amp; apt-get install -y awscli<br><br>            # Configure AWS CLI with Bitbucket environment variables<br>            - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID<br>            - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY<br>            - aws configure set region $AWS_REGION<br><br>            # Authenticate Docker to ECR<br>            - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com<br><br>            # Build the Docker image<br>            - docker build -t $ECR_REPOSITORY:$BITBUCKET_COMMIT .<br><br>            # Tag the image with the latest tag<br>            - docker tag $ECR_REPOSITORY:$BITBUCKET_COMMIT $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$BITBUCKET_COMMIT<br>            - docker tag $ECR_REPOSITORY:$BITBUCKET_COMMIT $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest<br><br>            # Push the image to Amazon ECR<br>            - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$BITBUCKET_COMMIT<br>            - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest<br><br>      - step:<br>          name: Deploy to EC2<br>          script:<br>            # SSH into the EC2 instance and pull the latest Docker image<br>            - pipe: atlassian/ssh-run:0.4.1<br>              variables:<br>                SSH_USER: $EC2_USER<br>                SERVER: $EC2_PUBLIC_IP<br>                COMMAND: |<br>                  # Log in to AWS ECR on EC2<br>                  aws ecr get-login-password --region $AWS_REGION | sudo docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com<br><br>                  # Pull the latest Docker image from ECR<br>                  sudo docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest<br><br>                  # Stop and remove the old container if it exists<br>                  sudo docker stop app-backend || true<br>                  sudo docker rm app-backend || true<br><br>                  # Run the new container<br>                  sudo docker run -d -p 3005:3005 --env-file /home/ubuntu/.env --name app-backend $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest</pre><h3>Step 3: Set Up AWS Credentials in Bitbucket</h3><p>You need to set up AWS credentials as environment variables in Bitbucket. These credentials will allow Bitbucket Pipelines to authenticate with AWS and interact with services like ECR and EC2.</p><ol><li>In your Bitbucket repository, go to <strong>Repository Settings</strong>.</li><li>Under <strong>Pipelines</strong>, click on <strong>Environment variables</strong>.</li><li>Add the following environment variables:</li></ol><ul><li>AWS_ACCESS_KEY_ID: Your AWS Access Key ID.</li><li>AWS_SECRET_ACCESS_KEY: Your AWS Secret Access Key.</li><li>AWS_REGION: The AWS region (e.g., us-east-1).</li><li>AWS_ACCOUNT_ID: Your AWS account ID.</li><li>ECR_REPOSITORY: The name of your ECR repository (e.g., aisound-backend-dev).</li><li>EC2_USER: The SSH user for your EC2 instance (e.g., ubuntu).</li><li>EC2_PUBLIC_IP: The public IP address of your EC2 instance.</li></ul><h3>Step 4: Set Up SSH Access to EC2</h3><p>In order to deploy to your EC2 instance, you’ll need an SSH key for Bitbucket to authenticate to your EC2 instance.</p><ol><li>Generate an SSH key pair (if you don’t already have one):</li></ol><pre>ssh-keygen -t rsa -b 2048 -f ~/.ssh/bitbucket-ec2-key</pre><p>OR</p><p>You can go to repo/admin/pipeline/ssh-keys into the settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1S7u9Bp5Kp0aYv42v0jnhw.png" /></figure><p>2. Copy the public key to your EC2 instance:</p><pre>cat ~/.ssh/bitbucket-ec2-key.pub | ssh -i ~/.ssh/your-ec2-key.pem ubuntu@your-ec2-public-ip &quot;mkdir -p ~/.ssh &amp;&amp; cat &gt;&gt; ~/.ssh/authorized_keys&quot;</pre><p>3. If key is not generated by bitbucket ssh and you generated it from your local machine then Add the private key (bitbucket-ec2-key) as an environment variable in Bitbucket:</p><ul><li>In <strong>Repository Settings</strong> &gt; <strong>Environment variables</strong>, add:</li><li>BITBUCKET_SSH_PRIVATE_KEY: Paste the contents of your private key file (bitbucket-ec2-key)</li></ul><h3>Step 5: Configure Your EC2 Instance</h3><p>Ensure that Docker is installed on your EC2 instance. If it’s not, you can install it with the following commands:</p><pre>sudo apt update<br>sudo apt install docker.io -y<br>sudo apt install docker-compose<br>sudo systemctl start docker<br>sudo systemctl enable docker<br>sudo usermod -a -G docker $(whoami)<br>newgrp docker</pre><p>Also, make sure that the EC2 instance’s security group allows inbound SSH (port 22) and HTTP (port 3005) traffic.</p><h3>Step 6: Triggering the Pipeline</h3><p>Once you’ve set everything up, each time you push code to the dev branch, Bitbucket Pipelines will:</p><ol><li>Build your Docker image.</li><li>Push it to AWS ECR.</li><li>Deploy it to your EC2 instance.</li></ol><p>You can monitor the progress from the <strong>Pipelines</strong> tab in Bitbucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZryLSbv5Xb-ji3L0.png" /><figcaption>bitbucket cicd pipeline</figcaption></figure><h3>Step 7: Verify the Deployment</h3><p>To verify that the deployment was successful:</p><ol><li>SSH into your EC2 instance:</li></ol><pre>ssh -i /path/to/your/private/key.pem ubuntu@your-ec2-public-ip</pre><p>2. Run docker ps to check if the container is running:</p><pre>sudo docker ps</pre><p>You should see your app-backend container running on port 3005.</p><p>Visit http://your-ec2-public-ip:3005 in your browser to ensure that the application is accessible.</p><h3>Conclusion</h3><p>With this setup, you have automated the process of building, pushing, and deploying Docker images from Bitbucket to EC2 using AWS ECR. This helps you streamline your deployment pipeline, making it faster and more reliable.</p><p>Now, every time you push changes to your dev branch, your application will automatically be built, deployed, and live on your EC2 instance with minimal effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5RX9cE_Pb28YP5pU" /><figcaption>Photo by <a href="https://unsplash.com/@maxsfotos?utm_source=medium&amp;utm_medium=referral">Max Vyölzse</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=230874cb9a50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing with Mitmproxy: A Step-by-Step Guide]]></title>
            <link>https://blog.stackademic.com/testing-with-mitmproxy-a-step-by-step-guide-65737415b31a?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/65737415b31a</guid>
            <category><![CDATA[man-in-the-middle]]></category>
            <category><![CDATA[mitmproxy]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 15:15:14 GMT</pubDate>
            <atom:updated>2024-11-22T12:53:12.340Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Middle in the Man — mitmproxy</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*kQsHYhlMXRQFUn9-.jpg" /><figcaption>mitm proxy working</figcaption></figure><p>In the realm of software development, especially when dealing with web services, it is crucial to test and inspect the traffic between your client and server. One powerful tool for this purpose is <strong>mitmproxy</strong>. Mitmproxy is an interactive, SSL/TLS-capable intercepting proxy with a console interface that allows you to inspect and modify traffic flowing through it. In this article, we will explore how to use mitmproxy to test and inspect HTTP and HTTPS traffic.</p><p><strong>What is Mitmproxy?</strong></p><p>Mitmproxy (short for “man-in-the-middle proxy”) is an open-source tool that provides a suite of capabilities to intercept, inspect, modify, and replay HTTP and HTTPS traffic. It is especially useful for debugging and testing web applications, APIs, and other web services.</p><p><strong>Why Use Mitmproxy?</strong></p><ul><li><strong>Intercept and Inspect Traffic: </strong>View the raw data exchanged between the client and server.<br><strong>Modify Requests and Responses: </strong>Manipulate the traffic to test various scenarios.<br><strong>Replay Requests: </strong>Resend captured requests to the server to test different server responses.<br><strong>Debugging and Testing:</strong> Identify issues in web applications, APIs, and microservices.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*o9I8atRbpNAK1iBC.png" /><figcaption>how mitm works</figcaption></figure><p><strong>Setting Up Mitmproxy</strong></p><p><strong>Installation</strong></p><p>Mitmproxy can be installed on various platforms. Here’s how to install it on a few common ones:</p><p><strong>For macOS:</strong></p><pre>brew install mitmproxy</pre><p><strong>For Linux:</strong></p><pre>sudo apt-get update<br>sudo apt-get install mitmproxy</pre><p><strong>For Windows:</strong><br>Download the installer from the <a href="https://mitmproxy.org/">mitmproxy.org</a> and follow the installation instructions.</p><p><strong>Running Mitmproxy</strong></p><p>To start mitmproxy, simply run the following command:</p><pre>mitmproxy</pre><p>This command starts the mitmproxy console interface.</p><p><strong>Using Mitmproxy</strong></p><p><strong>Setting Up Your Client</strong></p><p>To intercept traffic, you need to configure your client (browser, application, or device) to use mitmproxy as its proxy server. Typically, this involves setting the HTTP and HTTPS proxy to <strong><em>`localhost` and port `8080`</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dWFM_KlA3SZzeuuo.png" /></figure><p><strong>Example for setting up a browser:</strong><br>1. Open browser settings.<br>2. Navigate to Network or Proxy settings.<br>3. Set the HTTP and HTTPS proxy to `<a href="http://localhost:8080/">localhost</a>` and port `8080`.</p><p><strong>Installing the Mitmproxy Certificate</strong></p><p>Since mitmproxy intercepts HTTPS traffic, it needs to decrypt <strong><em>SSL/TLS</em></strong>.</p><p>For this purpose, you need to install mitmproxy’s CA certificate in your browser or system.</p><p>1. Open mitmproxy in your browser by visiting ‘<a href="http://mitm.it`/"><strong><em>http://mitm.it</em></strong></a><strong><em>’</em></strong>.<br>2. Download the certificate for your platform.<br>3. Follow the instructions to install and trust the certificate.</p><p><strong>Intercepting and Inspecting Traffic</strong></p><p>With mitmproxy running and your client configured to use it, you can now intercept and inspect traffic.</p><ol><li>Start mitmproxy:</li></ol><pre>mitmproxy</pre><p><strong>2. Open a website or make a request from your client:</strong><br> Your traffic will now flow through mitmproxy.</p><p><strong>3. Inspect traffic:</strong><br> Use the console interface to navigate through requests and responses. You can view headers, body content, and other details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3XKEffB0u6iWoMa_" /><figcaption>Photo by <a href="https://unsplash.com/@happy_pixel?utm_source=medium&amp;utm_medium=referral">Vinu T</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Modifying Requests and Responses</strong></p><p>Mitmproxy allows you to modify traffic on the fly. Here’s how to do it:</p><p><strong>1. Intercept a request:</strong><br> Select a request in the mitmproxy interface and press `Enter`.</p><p><strong>2. Modify the request:</strong><br> Press <strong>e</strong> to edit the request. You can change headers, URL, method, or body.</p><p><strong>3. Forward the request:</strong><br> Press <strong>a</strong> to accept and forward the modified request to the server.</p><p>Similarly, you can modify responses using the same approach.</p><p><strong>Replaying Requests</strong></p><p>Mitmproxy can replay requests to the server, which is useful for testing server behavior with the same request multiple times.</p><p><strong>1. Select a request to replay:</strong><br> Navigate to the request in the mitmproxy interface.</p><p><strong>2. Replay the request:</strong><br> Press <strong>r</strong> to replay the request. Mitmproxy will send the request to the server again and capture the response.</p><p><strong>Automating with Mitmproxy Scripts</strong></p><p>Mitmproxy supports scripting in Python, allowing you to automate tasks and customize behavior.</p><p><strong>Example script to modify all responses:</strong></p><p>Create a script <strong><em>modify_response.py</em></strong>:<br><br><strong><em>from mitmproxy import http</em></strong></p><p><strong><em>def response(flow: http.HTTPFlow) -&gt; None:<br> if “example.com” in flow.request.host:<br> flow.response.headers[“new-header”] = “value”</em></strong><br>```</p><p>Run mitmproxy with the script:<br><strong><em>mitmproxy -s modify_response.py</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/0*3-uCBmbveb9WYz4i.png" /></figure><p><strong>Conclusion</strong></p><p>Mitmproxy is a powerful tool for intercepting, inspecting, and modifying HTTP and HTTPS traffic. It is invaluable for debugging and testing web applications and services. By following this guide, you can set up mitmproxy, configure your client, intercept traffic, modify requests and responses, replay requests, and automate tasks using scripts. Whether you are a developer, tester, or security professional, mitmproxy provides the capabilities you need to ensure your web services are functioning correctly and securely.</p><p><strong>Happy debugging with mitmproxy!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6-3dIddy9bOjxKMP" /><figcaption>Photo by <a href="https://unsplash.com/@th_dangvu?utm_source=medium&amp;utm_medium=referral">Thien Dang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://differ.blog/"><strong>Create a free AI-powered blog on Differ.</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65737415b31a" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/testing-with-mitmproxy-a-step-by-step-guide-65737415b31a">Testing with Mitmproxy: A Step-by-Step Guide</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set up Custom Error Pages for various HTTP Status Codes in an Istio K8s Environment.]]></title>
            <link>https://sheraziqbal.medium.com/how-to-set-up-custom-error-pages-for-various-http-status-codes-in-an-istio-k8s-environment-28b1252e7a0a?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/28b1252e7a0a</guid>
            <category><![CDATA[custom-error-page]]></category>
            <category><![CDATA[envoy-filter]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Fri, 24 May 2024 12:40:14 GMT</pubDate>
            <atom:updated>2024-05-31T08:11:44.826Z</atom:updated>
            <content:encoded><![CDATA[<h4>Configuring Custom Error Pages in Kubernetes Istio/Envoy for Multiple Error Codes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y5RFuhBmaGD98It7" /><figcaption>Photo by <a href="https://unsplash.com/@carrier_lost?utm_source=medium&amp;utm_medium=referral">Ian Taylor</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the realm of application management and microservice architecture, error handling plays a crucial role in delivering a seamless <a href="https://scholarkai.com/student-zone-contest-2024/">user experience (UX)</a>. Not only does it enhance UX, but it also contributes to better security practices. Istio, with its powerful and flexible proxy component, <a href="https://www.envoyproxy.io/"><strong>Envoy</strong></a><strong>,</strong> offers robust service mesh capabilities. In this article, we will explore how to configure custom error pages for multiple HTTP status codes in Istio/Envoy.</p><p><strong>Introduction</strong></p><p>If you are using Istio and want to replace the <strong><em>default Envoy error pages (e.g., “RBAC: Access Denied”) with custom error pages</em></strong>, this guide is for you. We will cover the steps to create custom error pages for various error codes <strong><em>(400, 401, 402, 403, 404, 405, 500, 501, 502, 503, 504) </em></strong>and apply them to your production microservices.</p><p><strong>Prerequisites</strong></p><p>1. Basic understanding of Kubernetes and Istio.<br>2. A Kubernetes cluster with Istio installed.<br>3. Access to your cluster through kubectl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nw-ZOvoDRgwdyHLH.png" /></figure><p><strong>Step 1: Prepare the EnvoyFilter Configuration</strong></p><p>First, let’s create an <strong>EnvoyFilter</strong> configuration that covers all the major error codes. This configuration will display a custom HTML page.</p><p>This <strong>envoyfilter-for-503–404-error-codes.yaml will display a beatiful page over the 503, 404 and other error codes in specific namespace and environment.</strong></p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br>  name: custom-error-pages<br>  namespace: myapp-prod //(name-space/env name)<br>spec:<br>  workloadSelector:<br>    labels:<br>      istio: istio-ingressgateway-prod<br>  configPatches:<br>    - applyTo: HTTP_FILTER<br>      match:<br>        context: GATEWAY<br>        listener:<br>          filterChain:<br>            filter:<br>              name: envoy.filters.network.http_connection_manager<br>              subFilter:<br>                name: envoy.filters.http.router<br>      patch:<br>        operation: INSERT_BEFORE<br>        value:<br>          name: envoy.filters.http.lua<br>          typed_config:<br>            &quot;@type&quot;: type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua<br>            inlineCode: |<br>              function envoy_on_response(response_handle)<br>                local status_code = response_handle:headers():get(&quot;:status&quot;)<br>                if status_code == nil then<br>                  response_handle:logInfo(&quot;No status code in response&quot;)<br>                  return<br>                end<br>                if status_code == &quot;404&quot; then<br>                  local custom_404_body = [[<br>                  &lt;!DOCTYPE html&gt;<br>                  &lt;html&gt;<br>                  &lt;head&gt;<br>                    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>                    &lt;title&gt;Page Not Found&lt;/title&gt;<br>                    &lt;style&gt;<br>                      body { background-color: #f4f4f4; color: #333; text-align: center; font-family: Arial, sans-serif; margin-top: 10%; }<br>                      h1 { font-size: 2.5em; margin: 20px 0; }<br>                      p { font-size: 1.2em; margin: 10px 0; }<br>                      .icon { width: 100px; height: 100px; margin: 0 auto; }<br>                    &lt;/style&gt;<br>                  &lt;/head&gt;<br>                  &lt;body&gt;<br>                    &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; fill=&quot;#5CB5EE&quot; class=&quot;icon&quot; viewBox=&quot;0 0 16 16&quot;&gt;<br>                    &lt;circle cx=&quot;8&quot; cy=&quot;8&quot; r=&quot;8&quot; fill=&quot;#5DADE2&quot;/&gt;<br>                    &lt;path d=&quot;M7.255 6.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286m1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94&quot; fill=&quot;#FFFFFF&quot; transform=&quot;translate(-2 -1)&quot;/&gt;<br>                    &lt;/svg&gt;<br>                    <br>                    &lt;h1&gt;Page Not Found&lt;/h1&gt;<br>                    &lt;p&gt;Oops! We couldn&#39;t find the page that you&#39;re looking for.&lt;/p&gt;<br>                    &lt;p&gt;Please check the address and try again.&lt;/p&gt;<br>                    &lt;p&gt;Error Code: 404&lt;/p&gt;<br>                  &lt;/body&gt;<br>                  &lt;/html&gt;<br>                  ]]<br>                  response_handle:headers():replace(&quot;content-type&quot;, &quot;text/html&quot;)<br>                  response_handle:body():setBytes(custom_404_body)<br>                elseif status_code == &quot;503&quot; then<br>                  local custom_503_body = [[<br>                  &lt;!DOCTYPE html&gt;<br>                  &lt;html&gt;<br>                  &lt;head&gt;<br>                    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>                    &lt;title&gt;Service Unavailable&lt;/title&gt;<br>                    &lt;style&gt;<br>                      body { background-color: #f4f4f4; color: #333; text-align: center; font-family: Arial, sans-serif; margin-top: 10%; }<br>                      h1 { font-size: 2.5em; margin: 20px 0; color: #5CB5EE; }<br>                      p { font-size: 1.2em; margin: 10px 0; }<br>                      .icon { width: 150px; height: 150px; margin: 0 auto; }<br>                      .error-code { font-size: 2em; color: #5CB5EE; margin-top: 1.2rem; font-weight: bolder; }<br>                    &lt;/style&gt;<br>                  &lt;/head&gt;<br>                  &lt;body&gt;<br>                    &lt;h1&gt;Service Unavailable&lt;/h1&gt;<br>                    &lt;svg version=&quot;1.0&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>                      width=&quot;211.000000pt&quot; height=&quot;116.000000pt&quot; viewBox=&quot;0 0 211.000000 116.000000&quot;<br>                      preserveAspectRatio=&quot;xMidYMid meet&quot;&gt;<br>                      &lt;metadata&gt;<br>                      Created by potrace 1.16, written by Peter Selinger 2001-2019<br>                      &lt;/metadata&gt;<br>                      &lt;g transform=&quot;translate(0.000000,116.000000) scale(0.100000,-0.100000)&quot;<br>                      fill=&quot;#737174&quot; stroke=&quot;none&quot;&gt;<br>                      &lt;path d=&quot;M335 929 c-88 -116 -168 -221 -178 -235 l-19 -24 916 0 c504 0 916 2<br>                      916 5 0 3 -20 31 -45 63 -76 97 -259 335 -283 370 l-23 32 -562 0 -562 0 -160<br>                      -211z&quot;/&gt;<br>                      &lt;path d=&quot;M10 265 l0 -254 32 -6 c18 -3 487 -4 1043 -3 l1010 3 3 258 2 257<br>                      -1045 0 -1045 0 0 -255z m340 105 c0 -5 -6 -24 -14 -42 -8 -18 -27 -66 -43<br>                      -105 l-28 -73 -57 0 -57 0 13 38 c8 20 24 62 36 92 12 30 26 65 31 78 7 19 16<br>                      22 64 22 30 0 55 -4 55 -10z m179 -2 c0 -7 -19 -58 -42 -113 l-42 -100 -59 -3<br>                      c-45 -2 -57 0 -53 10 3 7 22 56 42 108 20 52 39 98 42 103 8 13 113 8 112 -5z<br>                      m180 0 c0 -7 -19 -58 -42 -113 l-42 -100 -58 -3 c-31 -2 -57 -1 -57 1 0 2 16<br>                      43 36 93 20 49 40 99 45 112 7 19 16 22 64 22 38 0 55 -4 54 -12z m181 5 c0<br>                      -5 -19 -55 -43 -113 l-43 -105 -58 -3 c-53 -3 -58 -1 -51 15 4 10 22 58 41<br>                      107 19 48 37 92 40 97 6 11 114 12 114 2z m175 -12 c-3 -11 -23 -62 -44 -113<br>                      l-37 -93 -57 -3 c-31 -2 -57 -1 -57 2 0 7 80 207 86 218 3 5 30 8 60 8 50 0<br>                      55 -2 49 -19z m844 -47 c62 -79 -43 -170 -114 -99 -49 49 -16 125 55 125 30 0<br>                      43 -6 59 -26z&quot;/&gt;<br>                      &lt;/g&gt;<br>                      &lt;/svg&gt;<br>                    &lt;div class=&quot;error-code&quot;&gt;503 HTTP Error&lt;/div&gt;<br>                  &lt;/body&gt;<br>                  &lt;/html&gt;<br>                  ]]<br>                  response_handle:headers():replace(&quot;content-type&quot;, &quot;text/html&quot;)<br>                  response_handle:body():setBytes(custom_503_body)<br>                end<br>              end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ox4M6ls3ArreKxEGOfgl2Q.png" /></figure><p><strong>In case of 503 error code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*2yY6ZP0FPnFwzGNEDDkKrw.png" /></figure><p>Create a file named <strong><em>`envoyfilter-custom-errors.yaml`</em></strong> and add the following content:</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br> name: custom-error-pages<br> namespace: istio-system<br>spec:<br> configPatches:<br> - applyTo: HTTP_FILTER<br> match:<br> context: GATEWAY<br> listener:<br> filterChain:<br> filter:<br> name: envoy.filters.network.http_connection_manager<br> subFilter:<br> name: envoy.filters.http.router<br> patch:<br> operation: INSERT_BEFORE<br> value:<br> name: envoy.lua<br> typed_config:<br> &#39;@type&#39;: type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua<br> inlineCode: |<br> function envoy_on_response(response_handle)<br> local response_code = tonumber(response_handle:headers():get(&quot;:status&quot;))<br> local error_codes = {400, 401, 402, 403, 404, 405, 500, 501, 502, 503, 504}<br> if contains(error_codes, response_code) then<br> response_handle:body():setBytes([[<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br> &lt;title&gt;Maintenance Mode&lt;/title&gt;<br> &lt;link href=&quot;https://fonts.googleapis.com/css?family=Open+Sans:300,400,700&quot; rel=&quot;stylesheet&quot;/&gt;<br> &lt;style&gt;<br> html, body { padding: 0; margin: 0; width: 100%; height: 100%; }<br> * { box-sizing: border-box; }<br> body { text-align: center; padding: 0; background: #d6433b; color: #fff; font-family: Open Sans; }<br> h1 { font-size: 50px; font-weight: 100; text-align: center; }<br> body { font-family: Open Sans; font-weight: 100; font-size: 20px; color: #fff; text-align: center; display: flex; justify-content: center; align-items: center; }<br> article { display: block; width: 700px; padding: 50px; margin: 0 auto; }<br> a { color: #fff; font-weight: bold; }<br> a:hover { text-decoration: none; }<br> img { width: 75px; margin-top: 1em; }<br> &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;article&gt;<br> &lt;img src=&quot;https://istockphoto.6q33.net/c/246195/270498/4205?u=https%3A%2F%2Fwww.istockphoto.com%2Fphoto%2Fsoftware-programmers-analyzing-html-code-and-database-brainstorming-script-ideas-to-gm1487286827-512812825&amp;adplacement=srp_freephoto_top-thumbs&amp;sharedid=html&amp;adid=1281084&quot; alt=&quot;Maintenance Image&quot;/&gt;<br> &lt;h1&gt;Maintenance Mode&lt;/h1&gt;<br> &lt;div&gt;<br> &lt;p&gt;Sorry for the inconvenience. We&#39;ll be back soon.&lt;/p&gt;<br> &lt;p&gt;&amp;mdash; Development Team&lt;/p&gt;<br> &lt;/div&gt;<br>&lt;/article&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>]])<br> response_handle:headers():replace(&quot;content-type&quot;, &quot;text/html&quot;)<br> end<br> end<br>function contains(table, element)<br> for _, value in pairs(table) do<br> if value == element then<br> return true<br> end<br> end<br> return false<br> end</pre><p><strong>Note:</strong></p><p>502 (bad gateway) and 503 (service unavailable) error responses are generally returns from Envoy, in other side 4xx responses are generally comes from application.</p><p>In our case, the EnvoyFilter can handle 401, 403, 502 and 503 error responses with local_reply_config. But handling 404 response is little bit different, we cannot manipulate error page with local_reply_config, we used Lua script to manipulate error page body.</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br>  name: 401-error-filter<br>  namespace: istio-system<br>spec:<br>  configPatches:<br>  - applyTo: NETWORK_FILTER<br>    match:<br>      context: SIDECAR_INBOUND<br>      listener:<br>        filterChain:<br>          filter:<br>            name: envoy.filters.network.http_connection_manager<br>    patch:<br>      operation: MERGE<br>      value:<br>        typed_config:<br>          &#39;@type&#39;: type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager<br>          server_name: 401-unauthorized<br>          local_reply_config:<br>            mappers:<br>            - filter:<br>                status_code_filter:<br>                  comparison:<br>                    op: EQ<br>                    value:<br>                      default_value: 401<br>                      runtime_key: key_b<br>              status_code: 401<br>            body_format:<br>              content_type: &quot;text/html; charset=UTF-8&quot;<br>              text_format_source:<br>                inline_string: |<br>                  &lt;html&gt;&lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;title&gt;Error401&lt;/title&gt;&lt;style&gt;body{width:35em;margin:0 auto;font-family:Tahoma,Verdana,Arial,sans-serif}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div style=&quot;text-align:center&quot;&gt;&lt;h3&gt;%RESPONSE_CODE% Unauthorized: You can customize this page&lt;/h3&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre><p>In the example above, we are creating a custom 401 (unauthorized) error page and it merges additional rule for network chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uEK82mIB_cWnopHP" /><figcaption>Photo by <a href="https://unsplash.com/@davfts?utm_source=medium&amp;utm_medium=referral">David Pupăză</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>For 404 pages, the process works a little differently. Since the application side usually answers the 404 page, we need to manipulate its body. For this purpose, we used HTTP_FILTER in the configPatches section and preferred INSERT_BEFORE as operation. The scripting part is actually quite simple once you decide where to put the rules.</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br>  name: custom-404error<br>  namespace: istio-system<br>spec:<br>  configPatches:<br>  - applyTo: HTTP_FILTER<br>    match:<br>      context: GATEWAY<br>      listener:<br>        filterChain:<br>          filter:<br>            name: envoy.filters.network.http_connection_manager<br>            subFilter:<br>              name: envoy.filters.http.router<br>    patch:<br>      operation: INSERT_BEFORE<br>      value:<br>        name: envoy.lua<br>        typed_config:<br>          &#39;@type&#39;: type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua<br>          inlineCode: |<br>            function envoy_on_response(response_handle)<br>                local response_code = response_handle:headers():get(&quot;:status&quot;)<br><br>                if response_code == &quot;404&quot; then<br>                  response_handle:body():setBytes(&quot;&lt;html&gt;&lt;b&gt;Custom 404 Error Page&lt;b&gt;&lt;/html&gt;&quot;)<br>                  response_handle:headers():replace(&quot;content-type&quot;, &quot;text/html&quot;)<br>                end<br>            end</pre><p>Our Lua script is quite simple, when the 404 status code is received in the header, we add the HTML page we want in the response_handle:body() section. In fact, other error pages can also be checked and manipulated in the same script.</p><p><strong>Step 2: Apply the EnvoyFilter</strong></p><p>Apply the EnvoyFilter using kubectl:<br><strong><em>kubectl apply -f envoyfilter-custom-errors.yaml</em></strong></p><p><strong>Step 3: Test the Custom Error Pages</strong></p><p>To verify that the custom error pages are correctly displayed, you can use curl to simulate the errors for each of your services. Here are the steps:</p><p><strong>Using Curl</strong></p><p>Test each error by sending a request that triggers the respective error code. For example:</p><p><strong>Test 404 error</strong><br><strong><em>curl -I </em></strong><a href="https://portal.ayra.health/non-existent-endpoint"><strong><em>https://domain.com/non-existent-endpoint</em></strong></a></p><p><strong>Test 401 error (adjust endpoint to one requiring authentication)</strong><br>curl -I <a href="https://portal.ayra.health/admin/protected-endpoint">https://domain.com/admin/protected-endpoint</a></p><p>Adjust the endpoint paths and methods to trigger the appropriate error responses.</p><p><strong>Using Browser</strong></p><p>Open a browser and navigate to various endpoints that would trigger the error pages. For example:</p><p>-<strong><em> </em></strong><a href="https://portal.ayra.health/non-existent-endpoint%60"><strong><em>https://domain.com/non-existent-endpoint</em></strong></a><strong><em> </em></strong>for 404 errors<br>- <a href="https://portal.ayra.health/admin/protected-endpoint%60"><strong><em>https://domain.com/admin/protected-endpoint</em></strong></a> for 401 errors</p><p><strong>Step 4: Clean Up</strong></p><p>If necessary, you can remove the EnvoyFilter using:<br><strong><em>kubectl delete -f envoyfilter-custom-errors.yaml</em></strong></p><p><strong>Summary</strong></p><p>By following these steps, you can effectively set up custom error pages for various HTTP status codes in your Istio environment.</p><p>This ensures that your users receive user-friendly error pages, enhancing the overall user experience.</p><p>Beyond configuring custom error pages, it’s important to stay updated with the <a href="https://scholarkai.com/category/opportunities/">latest opportunities</a> to enhance your academic and professional growth. <a href="https://www.google.com/search?q=scholarkai&amp;sca_esv=6798127eb6819917&amp;sca_upv=1&amp;rlz=1C5CHFA_enPK1065PK1065&amp;sxsrf=ADLYWIJwT5L06JbPeDH63kesurlcSValmA%3A1716551317019&amp;ei=lX5QZrBhhpPFzw-a0oPIBg&amp;ved=0ahUKEwjw__T7m6aGAxWGSfEDHRrpAGkQ4dUDCBA&amp;uact=5&amp;oq=scholarkai&amp;gs_lp=Egxnd3Mtd2l6LXNlcnAiCnNjaG9sYXJrYWkyBBAjGCcyChAjGIAEGCcYigUyCBAAGKIEGIkFMggQABiABBiiBDIIEAAYgAQYogQyCBAAGIAEGKIESKoOUPECWLUHcAF4AJABAJgB8QKgAcwHqgEFMi0xLjK4AQPIAQD4AQGYAgOgAuYEwgILEAAYgAQYsAMYogTCAgsQABiwAxiiBBiJBZgDAIgGAZAGBJIHBzEuMC4xLjGgB-oN&amp;sclient=gws-wiz-serp"><strong><em>ScholarKai </em></strong></a>is a platform dedicated to providing valuable insights into <a href="https://scholarkai.com/category/scholarships/">scholarships</a>, <a href="https://scholarkai.com/category/internships/">internships</a>, <a href="https://scholarkai.com/category/fellowships/">fellowships</a>, <a href="https://scholarkai.com/category/opportunities/conferences/">conferences</a>, and job vacancies available worldwide.</p><figure><img alt="https://scholarkai.com/" src="https://cdn-images-1.medium.com/max/708/1*b2x64q9zifGGACfqG3t1qw.png" /><figcaption><a href="https://scholarkai.com/">scholarkai.com</a></figcaption></figure><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28b1252e7a0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying AKS Management with Kubernetes Dashboard]]></title>
            <link>https://sheraziqbal.medium.com/simplifying-aks-management-with-kubernetes-dashboard-44fa60988ebf?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/44fa60988ebf</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[kubernetes-management]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Fri, 05 Apr 2024 07:37:36 GMT</pubDate>
            <atom:updated>2024-04-05T07:42:28.710Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes has emerged as a leading container orchestration system, streamlining the deployment, scaling, and management of containerized applications. However, navigating the complexities of Kubernetes management, especially in terms of monitoring and visualization, can be daunting. This is where the Kubernetes dashboard comes into play. In this article, we’ll delve into the process of setting up the Kubernetes dashboard for Azure Kubernetes Service (AKS) using straightforward kubectl and helm commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L01axdXO7wQgpRCX" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Understanding the Kubernetes Dashboard</strong></p><p>The Kubernetes dashboard serves as a user-friendly web interface for monitoring and managing Kubernetes clusters. It provides a visual representation of the cluster’s state, facilitates application management and troubleshooting, and offers access to logs and metrics. Leveraging the Kubernetes API, the dashboard is compatible with various Kubernetes clusters, including AKS.</p><p><strong>Installation Process for Kubernetes Dashboard on AKS</strong></p><p>Before proceeding, ensure you have an AKS cluster set up with administrative access. Alternatively, utilize Azure Cloud Shell for dashboard installation. Here’s a step-by-step guide using PowerShell:</p><p><strong>Step 1: Connect to your AKS cluster:</strong></p><pre>az aks get-credentials - resource-group myRg - name MyAKS</pre><p><strong>Step 2: Obtain Helm charts for the Kubernetes dashboard:</strong><br>Download the Kubernetes dashboard helm charts from <a href="https://artifacthub.io/packages/helm/k8s-dashboard/kubernetes-dashboard">artifacthub.io</a> or <a href="https://kubernetes.github.io/dashboard/kubernetes-dashboard-6.0.6.tgz">here</a> and extract them into your project folder.</p><p><strong>Step 3: Create a new Namespace for the Kubernetes dashboard:</strong></p><pre>kubectl create ns aks-dashboard</pre><p><strong>Step 4: Navigate to the project directory containing the charts:</strong></p><pre>cd C:\MyProject\kubernetes-dashboard-6.0.6</pre><p><strong>Step 5: Install the Kubernetes dashboard using helm chart:</strong></p><pre>helm install my-aks-dashboard .\kubernetes-dashboard -n aks-dashboard</pre><p><strong>Output can be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/0*hotFwrkEgH8OFsL3" /></figure><p><strong>Step 6: Set up port forwarding to access the dashboard:</strong></p><pre>$POD_NAME=$(kubectl get pods -n aks-dashboard -l &quot;app.kubernetes.io/name=kubernetes-dashboard,app.kubernetes.io/instance=my-aks-dashboard&quot; -o jsonpath=&quot;{.items[0].metadata.name}&quot;)<br>kubectl -n aks-dashboard port-forward $POD_NAME 8443:8443</pre><p><strong>Step 7: Access and authenticate the dashboard at </strong><a href="https://127.0.0.1:8443/"><strong>https://127.0.0.1:8443/</strong></a><br>You can Select <strong><em>“Kubeconfig” </em></strong>and upload your kube config file from <strong>Step 1</strong>. or Select “<strong><em>Token”</em></strong> as per your choice Upon authentication, you’ll gain access to the fully functional dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s_mR1-ZKk3mifoD3" /><figcaption>AKS Dash with Token</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cxyoYECeVIA5SBCK" /><figcaption>AKS Dash with KubeConfig</figcaption></figure><p><strong>Step 8: Explore AKS insights through the Kubernetes Dashboard</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/0*Xn6Yj4c1zqIY9XCG" /></figure><p><strong>Conclusion</strong></p><p>In essence, the Kubernetes Dashboard serves as a robust tool for simplifying AKS cluster management. Offering real-time monitoring, resource management, and troubleshooting capabilities through an intuitive web interface, it empowers users to monitor cluster health and optimize performance efficiently. Whether you’re a Kubernetes novice or seasoned user, the Kubernetes Dashboard is a valuable asset for enhancing AKS management. Give it a try and elevate your AKS management experience!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RnyNM2BpWphC_7lG" /><figcaption>Photo by <a href="https://unsplash.com/@julianhochgesang?utm_source=medium&amp;utm_medium=referral">Julian Hochgesang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44fa60988ebf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Lifecycle Policies in AWS ECR: A Practical Guide]]></title>
            <link>https://blog.stackademic.com/title-implementing-lifecycle-policies-in-aws-ecr-a-practical-guide-3860b612b477?source=rss-e7a5fab7c9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3860b612b477</guid>
            <category><![CDATA[cloud-infrastructure]]></category>
            <category><![CDATA[lifecycle]]></category>
            <category><![CDATA[aws-ecr]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[docker-container]]></category>
            <dc:creator><![CDATA[Sheraz Iqbal]]></dc:creator>
            <pubDate>Fri, 29 Mar 2024 18:09:45 GMT</pubDate>
            <atom:updated>2024-04-01T01:37:23.418Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction:</strong><br>In the ever-evolving landscape of cloud infrastructure management, optimizing storage resources is paramount. Amazon Elastic Container Registry (ECR) provides a convenient solution for storing and managing Docker container images securely. However, as image repositories grow over time, it becomes essential to implement lifecycle policies to manage image retention efficiently.</p><p>This article aims to guide users through the process of implementing lifecycle policies in AWS ECR, ensuring optimal resource utilization and cost efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oUlmtvox_JzzSHiV" /><figcaption>Photo by <a href="https://unsplash.com/@oulashin?utm_source=medium&amp;utm_medium=referral">Sean Oulashin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Practical Implementation:</strong></p><p><strong>Step 1: Define Lifecycle Policy:</strong><br>The first step in implementing a lifecycle policy is defining the policy itself. A lifecycle policy specifies the rules for managing images within a repository. These rules typically include criteria such as the age of images and their tag status (e.g., tagged or untagged).</p><p>For example, a common policy might be to expire untagged images older than a certain number of days.</p><p><strong>Step 2: Create Lifecycle Policy Document:</strong><br>Once the policy rules are defined, they need to be encapsulated in a JSON document. This document outlines the rule priorities, descriptions, selection criteria, and actions to be taken. It is crucial to ensure that the JSON document adheres to the AWS ECR lifecycle policy schema to avoid validation errors during implementation.</p><p><strong>Step 3: Apply Lifecycle Policy to ECR Repository:</strong><br>With the lifecycle policy document ready, the next step is to apply it to the desired ECR repository. This can be achieved using the AWS CLI or SDK by executing the<strong><em> `put-lifecycle-policy`</em></strong> command with the repository name and the path to the policy document as parameters. Upon successful execution, the policy will be associated with the repository, and the defined rules will take effect.</p><p><strong>Technical Implementation:</strong></p><p><strong>CLI Command:</strong></p><pre>aws ecr put-lifecycle-policy \<br> - repository-name &lt;repository-name&gt; \<br> - lifecycle-policy-text &quot;file://&lt;path-to-policy-document&gt;</pre><p><strong>Sample Policy Document (policy.json):</strong></p><pre>{<br> &quot;rules&quot;: [<br> {<br> &quot;rulePriority&quot;: 1,<br> &quot;description&quot;: &quot;Expire untagged images older than 60 days&quot;,<br> &quot;selection&quot;: {<br> &quot;tagStatus&quot;: &quot;untagged&quot;,<br> &quot;countType&quot;: &quot;sinceImagePushed&quot;,<br> &quot;countUnit&quot;: &quot;days&quot;,<br> &quot;countNumber&quot;: 60<br> },<br> &quot;action&quot;: {<br> &quot;type&quot;: &quot;expire&quot;<br> }<br> }<br> ]<br>}</pre><p><strong>Bash Script to Implement on Bulk:</strong></p><pre>#!/bin/bash<br><br># Define the list of repository names<br>repositories=(<br>    &quot;repo-1&quot;<br>    &quot;repo-2&quot;<br>    &quot;repo-3...&quot;<br>)<br><br># Loop through each repository and apply the lifecycle policy<br>for repository in &quot;${repositories[@]}&quot;; do<br>    aws ecr put-lifecycle-policy \<br>        --repository-name &quot;$repository&quot; \<br>        --lifecycle-policy-text &quot;file://policy.json&quot;<br>done</pre><p>This script will iterate over each repository name in the<strong> `repositories`</strong> array and execute the<strong> `aws ecr put-lifecycle-policy`</strong> command for each one, applying the lifecycle policy defined in the <strong>`policy.json`</strong> file. Make sure to replace <strong>”file://policy.json” </strong>with the correct path to your policy file.</p><p><strong>Conclusion:</strong><br>Implementing lifecycle policies in AWS ECR is a straightforward yet powerful approach to managing container image retention. By defining and applying lifecycle policies tailored to specific repository requirements, users can automate image cleanup processes, optimize storage utilization, and reduce operational overhead. With the practical and technical insights provided in this guide, users can seamlessly integrate lifecycle policies into their AWS ECR workflows, ensuring efficient resource management in containerized environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GOIv9Asez84zeNvp" /><figcaption>Photo by <a href="https://unsplash.com/@sauravmahto?utm_source=medium&amp;utm_medium=referral">Saurav Mahto</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3860b612b477" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/title-implementing-lifecycle-policies-in-aws-ecr-a-practical-guide-3860b612b477">Implementing Lifecycle Policies in AWS ECR: A Practical Guide</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>