<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pankaj892</title>
    <description>The latest articles on DEV Community by pankaj892 (@pankaj892).</description>
    <link>https://dev.to/pankaj892</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F544347%2F0818b1e7-586d-4271-b896-3939c4cef770.jpg</url>
      <title>DEV Community: pankaj892</title>
      <link>https://dev.to/pankaj892</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pankaj892"/>
    <language>en</language>
    <item>
      <title>Devops pipeline on a Golang Web App with Gitops and Kubernetes</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Wed, 23 Oct 2024 08:00:37 +0000</pubDate>
      <link>https://dev.to/pankaj892/devops-pipeline-on-a-golang-web-app-with-gitops-and-kubernetes-4k7m</link>
      <guid>https://dev.to/pankaj892/devops-pipeline-on-a-golang-web-app-with-gitops-and-kubernetes-4k7m</guid>
      <description>&lt;h2&gt;
  
  
  In this blog post I'll walk you through the journey of automating the deployment of a web app in golang with CI/CD pipelines and using Gitops approach.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  We'll go through containerizing our app to deploying it on kubernetes to using ArgoCD for deployment.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A kubernetes cluster
You can use any of the managed services from cloud providers for kubernetes or if your system has enough resources to provision a kubernetes cluster you can setup a local kubernetes cluster using Minikube/kind&lt;/li&gt;
&lt;li&gt;A github account
A free account is sufficient enough as we will be using Github Actions for Continuous Integration (CI)&lt;/li&gt;
&lt;li&gt;A dockerhub account
We'll be using dockerhub to pull container images&lt;/li&gt;
&lt;li&gt;Eagerness to learn&lt;/li&gt;
&lt;li&gt;Not giving up
This is the important one you'll face problems and you should be able to troubleshoot them and resolve them. I had to troubleshoot a lot of times before I can complete this project.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets start&lt;/p&gt;

&lt;h3&gt;
  
  
  Containerizing the app with Multi-stage docker builds
&lt;/h3&gt;

&lt;p&gt;For the web app to be available on all machines we have to containerize it and when containerization is the word what's best than docker.&lt;br&gt;
I created a Dockerfile to run the app but I have used multi-stage format&lt;/p&gt;
&lt;h4&gt;
  
  
  Why multi-stage builds ?
&lt;/h4&gt;

&lt;p&gt;The reason is simple if I create an image in a single stage it would consume more space on the machine whereas by using multi-stage builds we optimize the final size of the image by seperating build and runtime environments and also reduce the attack surface of our image for better security&lt;/p&gt;

&lt;p&gt;Here's how you can do it&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a dockerfile&lt;/li&gt;
&lt;li&gt;Compile the application in the build stage&lt;/li&gt;
&lt;li&gt;Copy the compiled binary to a minimal base image&lt;/li&gt;
&lt;li&gt;Build the image and push it to dockerhub so the image can be used by Github Actions in CI
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Start with a base image
FROM golang:1.22 as base
WORKDIR /app
COPY go.mod ./
RUN go mod download
COPY . .
RUN go build -o main .

#######################################################
# Reduce the image size using multi-stage builds
# We will use a distroless image to run the application
FROM gcr.io/distroless/base

# Copy the binary from the previous stage
COPY --from=base /app/main .

# Copy the static files from the previous stage
COPY --from=base /app/static ./static

# Expose the port on which the application will run
EXPOSE 8080

# Command to run the application
CMD ["./main"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now that we have the dockerfile let's build it and deploy it to dockerhub&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t  pankaj892/webapp:v1 .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We try to check whether app works as expected on local machine&lt;br&gt;
&lt;code&gt;docker run -p 8080:8080 pankaj892-webapp:v1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lets push it to dockerhub&lt;br&gt;
&lt;code&gt;docker push pankaj892/webapp:v1 .&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Kubernetes cluster creation
&lt;/h3&gt;

&lt;p&gt;You can create a cluster locally using mininkube/kind or use any one of the managed solutions on cloud. I'll be using Elastic Kubernetes Service(EKS) from AWS.&lt;/p&gt;

&lt;p&gt;You can launch a cluster in EKS using console or from commandline. I'll be using the commandline&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl create cluster--instance-selector-vcpus=2 --instance-selector-memory=4 --name &amp;lt;name-of-cluster&amp;gt; --region &amp;lt;region-code&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will choose only those machine types for node groups which have 2 vCPUs and memory of 4gb&lt;/p&gt;

&lt;h3&gt;
  
  
  Helm chart creation and configuration
&lt;/h3&gt;

&lt;p&gt;We can deploy all the resources one by one but it would be difficult to manage them as they scale this is where Helm comes in it acts as a package manager to manage all of our resources with the use of charts&lt;/p&gt;

&lt;p&gt;Create a helm chart&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm create web-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Helm will create files for our use but we don't need most of them for our project.&lt;/p&gt;

&lt;p&gt;Create the following files and add them in the helm directory &lt;/p&gt;

&lt;p&gt;Deployment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This is a sample deployment manifest file for a simple web application.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  labels:
    app: web-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web-app
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        ports:
        - containerPort: 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Service for the application
apiVersion: v1
kind: Service
metadata:
  name: web-app
  labels:
    app: web-app
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: web-app
  type: ClusterIP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ingress&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Ingress resource for the application
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-app
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - host: web-app.local
    http:
      paths: 
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-app
            port:
              number: 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the values file to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Default values for web-app.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: pankaj892/webapp
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "11440208844"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: ""
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Helm part is done now let's move on to deploying our CI&lt;/p&gt;

&lt;h3&gt;
  
  
  Continuous Integration (CI) with Github Actions
&lt;/h3&gt;

&lt;p&gt;Github Actions allow us to automate the build process of our app based on some events in our repo like push,pull.&lt;/p&gt;

&lt;p&gt;Let's create our pipeline file&lt;br&gt;
Workflow file is stored in (.github/workflows/cicd.yml)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CICD using GitHub actions

name: CI and Deploy to ArgoCD

# Exclude the workflow to run on changes to the following files
on:
  push:
    branches:
      - main
    paths-ignore:
      - 'helm/**'
      - 'README.md'

jobs:

  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Set up Go 1.22
      uses: actions/setup-go@v2
      with:
        go-version: 1.22

    - name: Build binary
      run: go build -o web-app

    - name: Test code
      run: go test ./...

  push:
    runs-on: ubuntu-latest

    needs: build

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1

    - name: Login to DockerHub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - name: Build and Push action
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ./Dockerfile
        push: true
        tags: ${{ secrets.DOCKERHUB_USERNAME }}/webapp:${{github.run_id}}

  update-newtag-in-helm-chart:
    runs-on: ubuntu-latest

    needs: push

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        token: ${{ secrets.TOKEN }}

    - name: Update tag in Helm chart
      run: |
        sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/web-app/values.yaml

    - name: Commit and push changes
      run: |
        git config --global user.email "pankaj28988@gmail.com"
        git config --global user.name "pankaj892"
        git add helm/web-app/values.yaml
        git commit -m "fix: Update tag in Helm chart"
        git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This workflow file first builds our image from dockerfile then pushes it to dockerhub and then updates the tag of the image in our charts.yaml file in helm.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up ArgoCD for Continuous Delivery
&lt;/h3&gt;

&lt;p&gt;We will use argocd for our Cd pipeline since argocd will be able to pick up changes from our git repo and update them in the app.&lt;/p&gt;

&lt;p&gt;Lets install argocd on our cluster&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl create namespace argocd&lt;br&gt;
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To access the argocd server we need to change the service to loadbalancer type&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For windows this would be &lt;br&gt;
&lt;code&gt;kubectl patch svc argocd-server -n argocd -p '{\"spec\": {\"type\": \"LoadBalancer\"}}'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If it doesn't work just edit service through kubectl and change the type to LoadBalancer it should work&lt;/p&gt;

&lt;p&gt;Now get the ip of the service&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl get svc argocd-server -n argocd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We got the ip but we need the password to login to argocd&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 --decode&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command would get the password and decode the password since the password is encoded in base64 format&lt;/p&gt;

&lt;p&gt;After logging in click on New Project &amp;gt; Add the name for your project &amp;gt; Add the repo so that argocd can sync the repo argocd will automatically look for values file and pick that up after that click on submit &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2oxqv0bgbxrwq36rwx0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2oxqv0bgbxrwq36rwx0g.png" alt="ArgoCD Sync Image" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Ingress and DNS Mapping
&lt;/h3&gt;

&lt;p&gt;We built our pipeline but how do we access our app you can't put in the cluster url from EKS everytime to access it we need to use an ingress for this&lt;/p&gt;

&lt;p&gt;I am using Nginx Ingress from AWS so that I can access the app&lt;/p&gt;

&lt;p&gt;Deploy the ingress on our cluster&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/aws/deploy.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now ingress is deployed and we need to add the ip of our cluster from EKS in our local hosts file for linux its /etc/hosts for windows it is in C:\Windows\System32\etc\hosts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ip-of-cluster&amp;gt; web-app.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can access our app on web-app.local&lt;/p&gt;

&lt;p&gt;We have done all the steps lets test our app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrjtcdlkh8s34qt1iii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrjtcdlkh8s34qt1iii.png" alt="ArgoCD Sync Image" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see the url at the top is what we defined in our hosts file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9x9fowddymyu7qq0hlmi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9x9fowddymyu7qq0hlmi.png" alt="Project Live Image" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have the app running lets add something and commit to our repo so argocd can pick up that change and deploy to app&lt;/p&gt;

&lt;p&gt;I made a change to me repo and this should trigger the pipeline&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1hdurv2al8mlyfuh905l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1hdurv2al8mlyfuh905l.png" alt="CI Pipeline Image" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pipeline has started and after its completion lets see whether argocd picks up that change&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvxpyojlb72ygez8zgai.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvxpyojlb72ygez8zgai.png" alt="Final project image" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes we see changes in our app argocd did pick up changes and synced our app with the latest changes&lt;/p&gt;

&lt;p&gt;If you made it this far then congrats!!!&lt;/p&gt;

&lt;p&gt;This project has been a great learning experience for me right from deploying kubernetes on AWS to creating my pipelines and deployments and troubleshooting them. This project helped me create an end-to-end devops pipeline for a go app and it can be scalable based on needs. I plan to explore more like maybe deploying the eks clutser using terraform or cloudformation stacks and refine more.&lt;/p&gt;

&lt;p&gt;If you get stuck somewhere you can reference this &lt;a href="https://github.com/pankaj892/web-app-devops.git" rel="noopener noreferrer"&gt;repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me know in the comments how was your experience building this pipeline.&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>kubernetes</category>
      <category>go</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>Monitoring a Kubernetes Cluster using Prometheus and Grafana with Helm</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Tue, 23 Jul 2024 11:52:08 +0000</pubDate>
      <link>https://dev.to/pankaj892/monitoring-a-kubernetes-cluster-using-prometheus-and-grafana-with-helm-3970</link>
      <guid>https://dev.to/pankaj892/monitoring-a-kubernetes-cluster-using-prometheus-and-grafana-with-helm-3970</guid>
      <description>&lt;p&gt;Monitoring a Kubernetes cluster is essential for maintaining its health, optimizing performance, and ensuring reliability. Prometheus and Grafana are industry-standard tools that, when combined, offer robust monitoring, alerting, and visualization capabilities.&lt;br&gt;
In this guide, we'll walk through deploying Prometheus and Grafana on Kubernetes using Helm charts, streamlining the setup process for efficient monitoring.&lt;/p&gt;
&lt;h4&gt;
  
  
  Why Use Prometheus and Grafana?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Prometheus:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scalability: Easily handles high cardinality metrics and dynamic service discovery within Kubernetes.&lt;/li&gt;
&lt;li&gt;Flexibility: Supports custom metrics and powerful querying capabilities.&lt;/li&gt;
&lt;li&gt;Reliability: Time-series database optimized for fast querying of metrics data.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grafana:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visualization: Provides intuitive, customizable dashboards for visualizing Prometheus metrics.&lt;/li&gt;
&lt;li&gt;Alerting: Configurable alerts based on metric thresholds or specific conditions.&lt;/li&gt;
&lt;li&gt;Integration: Easily integrates with various data sources, including Prometheus, to consolidate monitoring data.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Kubernetes Cluster: Ensure you have access to a Kubernetes cluster where you can deploy applications. You can set it up locally using &lt;a href="https://kind.sigs.k8s.io/" rel="noopener noreferrer"&gt;KinD&lt;/a&gt;/&lt;a href="https://minikube.sigs.k8s.io/docs/" rel="noopener noreferrer"&gt;Minikube&lt;/a&gt; or use one hosted on the cloud.&lt;/li&gt;
&lt;li&gt;Helm: Install Helm on your local machine and initialize it to connect to your Kubernetes cluster. If you haven't installed Helm yet, follow the instructions &lt;a href="https://helm.sh/docs/intro/install/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Deploying Prometheus with Helm
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: Add Prometheus Helm Repository
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Step 2: Install Prometheus
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm install prometheus prometheus-community/prometheus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This command installs Prometheus with default configurations suitable for monitoring Kubernetes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 3: Access Prometheus UI
To access the Prometheus UI, port-forward the Prometheus server pod to your local machine:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl port-forward service/prometheus-server 9090:80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Open &lt;a href="http://localhost:9090" rel="noopener noreferrer"&gt;http://localhost:9090&lt;/a&gt; in your web browser to access the Prometheus expression browser and other features.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogspa081ck10xb4dfdzc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fogspa081ck10xb4dfdzc.png" alt="Prometheus UI" width="800" height="258"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Deploying Grafana with Helm
&lt;/h4&gt;

&lt;p&gt;Grafana can also be easily deployed using the official Helm chart from the Grafana community repository.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: Add Grafana Helm Repository
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Step 2: Install Grafana
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm install grafana grafana/grafana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This installs Grafana with a default admin password. Retrieve the password using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 3: Access Grafana UI
To access the Grafana UI, port-forward the Grafana pod to your local machine:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl port-forward service/grafana 3000:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; in your web browser. Log in with username admin and the password retrieved earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febawlg596kd58w9am8fz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febawlg596kd58w9am8fz.png" alt="Grafana Home" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After logging in you are greeted with the following UI&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F568bjs5alj0qs19h8b0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F568bjs5alj0qs19h8b0k.png" alt="Grafana UI" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Configuring Prometheus Data Source in Grafana
&lt;/h4&gt;

&lt;p&gt;Once both Prometheus and Grafana are running, we need to configure Grafana to use Prometheus as a data source.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to Configuration &amp;gt; Data Sources &amp;gt; Add data source.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose Prometheus as the type.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq645sv5pk4hkmdh27zgo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq645sv5pk4hkmdh27zgo.png" alt="Choose Data Source Page" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Configure the URL to &lt;a href="http://url_of_prometheus_server" rel="noopener noreferrer"&gt;http://url_of_prometheus_server&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lj10g2e934deslxs90u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lj10g2e934deslxs90u.png" alt="Prometheus URL" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save and test the data source at bottom to ensure it connects successfully.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6y3gwte5dcsn89j2of5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6y3gwte5dcsn89j2of5j.png" alt="Test Prometheus Connection" width="800" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Importing Grafana Dashboards
&lt;/h4&gt;

&lt;p&gt;Grafana provides pre-built dashboards for monitoring Kubernetes clusters. You can import these dashboards to visualize metrics collected by Prometheus.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to Create &amp;gt; Import in Grafana.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the dashboard IDs from Grafana's official repository or community dashboards.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I am using the official one from Grafana you can find it &lt;a href="https://grafana.com/grafana/dashboards/3662-prometheus-2-0-overview/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryc9hdtjjm11wbocdnhc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryc9hdtjjm11wbocdnhc.png" alt="Prometheus ID" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the Prometheus data source you configured earlier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And now we can see our dashboard which is collecting metrics from Prometheus and displaying it on dashboard in realtime&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadhu93gfbhu9awm6rd74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadhu93gfbhu9awm6rd74.png" alt="Grafana Dashboard" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can customize the imported dashboard as needed to monitor your Kubernetes cluster effectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Deploying Prometheus and Grafana using Helm charts simplifies the setup and configuration of monitoring for your Kubernetes cluster. This setup provides scalable metric collection, robust visualization capabilities, and flexible alerting mechanisms. By leveraging these tools, you can gain deep insights into your Kubernetes infrastructure's performance and ensure proactive management of your applications.&lt;/p&gt;

&lt;p&gt;If you have any questions comment it down I'll try to help&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>prometheus</category>
      <category>grafana</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>CI/CD pipeline using Jenkins and Docker</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Tue, 02 Jul 2024 11:11:53 +0000</pubDate>
      <link>https://dev.to/pankaj892/cicd-pipeline-using-jenkins-and-docker-2cbk</link>
      <guid>https://dev.to/pankaj892/cicd-pipeline-using-jenkins-and-docker-2cbk</guid>
      <description>&lt;p&gt;Today we will be creating a CI/CD pipeline in Jenkins which fetches code from github and creates an image from Dockerfile and runs our app in a docker container and terminates automatically after scheduled time&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Creating EC2 instances
&lt;/h4&gt;

&lt;p&gt;I have used AWS EC2 to launch an ubuntu instance which comes under free tier you can try it on your local machine or use a VM from any public cloud provider&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6rs703urr1pqnng7xnj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6rs703urr1pqnng7xnj.png" alt="EC2 Instance Image" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now connect to the instance&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Setting up Jenkins &amp;amp; Docker
&lt;/h4&gt;

&lt;p&gt;We need to update our installation package manager&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Jenkins needs java to run so we'll proceed with installing Java first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install openjdk-11-jre
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if java is installed correctly&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdipsd0mvfmvxvszq5bxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdipsd0mvfmvxvszq5bxf.png" alt="Check java" width="800" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we download Jenkins using curl command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \   /usr/share/keyrings/jenkins-keyring.asc &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We add it to our package manager&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \   https://pkg.jenkins.io/debian binary/ | sudo tee \   /etc/apt/sources.list.d/jenkins.list &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets update our package manager once&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now install jenkins&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we can use jenkins we need to enable it first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo systemctl enable jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start jenkins server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo systemctl start jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check status of jenkins&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo systemctl status jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You would get a response like this&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwru7u5t7zhup64oyctu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwru7u5t7zhup64oyctu7.png" alt="jenkins status" width="800" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Jenkins runs on port 8080 by default go to localhost:8080 to access it.&lt;br&gt;
Since I have a VM provisioned in the cloud I need to open port 8080 to allow connections&lt;br&gt;
I went to Network security groups and added the port number I want to access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5ar33t1frvzuk2u0g57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5ar33t1frvzuk2u0g57.png" alt="NSG in AWS" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I don't want everyone to able to access jenkins I have limited the port to only a single host&lt;/p&gt;

&lt;p&gt;Now when I login to port 8080 I am greeted with a login screen of jenkins&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhckflzo6gcv836ebn9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkhckflzo6gcv836ebn9c.png" alt="Jenkins login" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to login we need credentials&lt;br&gt;
Username is admin&lt;br&gt;
password can be found through the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After logging into jenkins change your password and jenkins would ask to install plugins let it install them&lt;/p&gt;

&lt;p&gt;Now we are greeted with a screen like this click on new item&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w5ms7axjii0rmxmscuf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w5ms7axjii0rmxmscuf.png" alt="Jenkins Dashboard" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I plan to keep it simple click on freestyle project &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fziatwihgnqiyhjjkqtff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fziatwihgnqiyhjjkqtff.png" alt="Setting up" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After adding the name for you app add your github repo you want to connect&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtr7itvjlm0f9x5psrx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtr7itvjlm0f9x5psrx9.png" alt="Git repo adding" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After adding a repo we need to tell jenkins how to access the repo and give it required permission so it can fetch the code from repo&lt;br&gt;
To achieve this I have used SSH keys simple generate a ssh key and add the public key in github&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuf4wtrbqotf10xobkeu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuf4wtrbqotf10xobkeu.png" alt="Credentials for Github" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to add private key in jenkins so that it can authenticate with github and pull code from our repo.&lt;br&gt;
Click on add below credentials and choose Jenkins &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1cpdvtsgvjnmcvdyz36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1cpdvtsgvjnmcvdyz36.png" alt="SSH Private key adding image" width="800" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give a name to you credential and add the private key&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkay8lc5o6keddujth0j7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkay8lc5o6keddujth0j7.png" alt="Naming credential" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we move to next step install a plugin called Github Integration available in Jenkins you can do this by going to manage jenkins and selecting plugins and search for the extension&lt;/p&gt;

&lt;p&gt;Now add the steps to build the app and run it. Since our app runs on node.js I will be using a docker container. I have created a Dockerfile &lt;br&gt;
to do this.&lt;br&gt;
I am using shell scripting to run the container in a shell and exit it &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcw2vt3m2wjiq569vo1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcw2vt3m2wjiq569vo1p.png" alt="Shell Script" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The commands in above image do the following things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build the docker image&lt;/li&gt;
&lt;li&gt;Run the app in a container on port 8000&lt;/li&gt;
&lt;li&gt;The app will be live for 5 minutes&lt;/li&gt;
&lt;li&gt;After that the container is stopped and removed from the machine &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Build ID with a $ is an environment variable which changes according to build of jenkins so we get a new container on every run and there won't be any problems as we won't be running same container everytime&lt;/p&gt;

&lt;p&gt;Click Save when done&lt;/p&gt;

&lt;p&gt;We need docker to run the app if you don't have install it on your machine&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install docker.io 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need a Dockerfile &lt;br&gt;
You can find it on my repository &lt;a href="https://github.com/pankaj892/node-jenkins-cicd/blob/main/Dockerfile"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dockerfile does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It pulls the latest node image from DockerHub&lt;/li&gt;
&lt;li&gt;The work directory is set as app &lt;/li&gt;
&lt;li&gt;It runs npm install and all libraries and packages are downloaded&lt;/li&gt;
&lt;li&gt;It exposes port 8000 for our app&lt;/li&gt;
&lt;li&gt;It runs the command &lt;code&gt;node app.js&lt;/code&gt; in a shell&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets move on to next stage&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Configuring Github
&lt;/h4&gt;

&lt;p&gt;We need to make sure that when a change is detected in our repo jenkins runs the pipeline automatically we use webhooks to achieve this &lt;/p&gt;

&lt;p&gt;Go to Settings &amp;gt; Webhooks for your repo not your account &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5e7c0661e1isf2s4ptzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5e7c0661e1isf2s4ptzm.png" alt="Webhook Tab" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now add url of your jenkins where it is hosted followed by /github-webhook/ and click on save &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fue1k1of30sqdqla4kbj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fue1k1of30sqdqla4kbj6.png" alt="Webhook details" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Testing our app
&lt;/h4&gt;

&lt;p&gt;Now lets do a dry run and see if our pipeline works as expected&lt;/p&gt;

&lt;p&gt;Click on build now to run the pipeline &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjcmr8d4g8c5p3mtdnqq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjcmr8d4g8c5p3mtdnqq5.png" alt="Dry Run" width="800" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Build has started &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxld0mza4k4e0i5xpxvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxld0mza4k4e0i5xpxvg.png" alt="Pipeline status" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I expect the container name to end with build number let's check&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42x7v9cf5gq25deq5qsm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42x7v9cf5gq25deq5qsm.png" alt="Container name checking" width="800" height="66"&gt;&lt;/a&gt;&lt;br&gt;
It is working as expected&lt;/p&gt;

&lt;p&gt;And pipeline is successful since we can see our app&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd44bdjcvio5g9ufhphm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd44bdjcvio5g9ufhphm5.png" alt="Pipeline success" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets change something in repo and see if jenkins picks it up and runs the pipeline &lt;br&gt;
I changed the background and some text &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1h29eisowo97khh1gc1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1h29eisowo97khh1gc1i.png" alt="Pipeline with changes" width="800" height="311"&gt;&lt;/a&gt;&lt;br&gt;
It is working as expected&lt;/p&gt;

&lt;p&gt;We have completed this project successfully&lt;/p&gt;

&lt;p&gt;If you have any questions comment down below I'll be happy to help&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>docker</category>
    </item>
    <item>
      <title>Deploying applications to Kubernetes with Gitlab CI/CD,Helm Charts and ArgoCD</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Mon, 01 Jul 2024 10:59:26 +0000</pubDate>
      <link>https://dev.to/pankaj892/deploying-applications-to-kubernetes-with-gitlab-cicdhelm-charts-and-argocd-3oik</link>
      <guid>https://dev.to/pankaj892/deploying-applications-to-kubernetes-with-gitlab-cicdhelm-charts-and-argocd-3oik</guid>
      <description>&lt;p&gt;In my last post I talked about Gitops and how it helps in automation you can read about it 👉&lt;a href="https://dev.to/pankaj892/gitops-streamlining-kubernetes-application-deployment-with-gitlab-cicd-helm-charts-and-argocd-685"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post we'll be doing a project using GitOps methodology and tools like ArgoCD&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftn7jomy7uw2j2y9qxr5f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftn7jomy7uw2j2y9qxr5f.jpg" alt="Project Workflow Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Workflow
&lt;/h4&gt;

&lt;p&gt;Let me take you through the project flow-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Developers commit code to git repository&lt;/li&gt;
&lt;li&gt;After code is commited a CI pipeline is triggered in gitlab which has the job of building an image and tagging it and updating the image in the repository which hosts the manifest files.&lt;/li&gt;
&lt;li&gt;After the job is completed the pipeline pushes the images to a container registry like dockerhub,gitlab etc. &lt;/li&gt;
&lt;li&gt;ArgoCD syncs the manifest repo which contains helm charts and values&lt;/li&gt;
&lt;li&gt;ArgoCD deploys the changes to Kubernetes cluster and changes reflect in the application &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before we begin we need a kubernetes cluster up and running you can deploy a cluster in one of the many cloud environments or you can run it locally using tools like &lt;a href="https://minikube.sigs.k8s.io/docs/" rel="noopener noreferrer"&gt;Minikube&lt;/a&gt;,&lt;a href="https://rancherdesktop.io/" rel="noopener noreferrer"&gt;Rancher Desktop&lt;/a&gt; to name a few&lt;/p&gt;

&lt;p&gt;I prefer running my cluster on cloud since it takes away a lot of stress for setting it up locally.&lt;/p&gt;

&lt;h4&gt;
  
  
  1.Setting up the cluster
&lt;/h4&gt;

&lt;p&gt;I have used Azure Kubernetes Service (AKS) for deploying kubernetes in Azure. It is a managed Kubernetes solution provided by Azure where we have access to nodes and Azure takes care of control plane.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpcwwz9t8uss507iwa2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpcwwz9t8uss507iwa2r.png" alt="Azure Kubernetes Service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dc9jrexec2p66kf2q1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dc9jrexec2p66kf2q1g.png" alt="AKS Deployment Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in above images we have our cluster set up and ready we can we now move to our next step which is setting up the gitlab pipeline&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Setting up CI pipeline in Gitlab
&lt;/h4&gt;

&lt;p&gt;I have used gitlab for CI/CD since I believe it has a lot of options and support for CI/CD. You can choose any other CI tool like CircleCI, Jenkins to name a few&lt;br&gt;
I have created 2 repos-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;code-repo&lt;br&gt;
This repo hosts the Dockerfile and the source code of our app&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fksgu7wfgh1gnk4j7s884.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fksgu7wfgh1gnk4j7s884.png" alt="Code-repo image from gitlab"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Manifest repo&lt;br&gt;
This repo hosts helm charts and yaml files for deployment of our app to kubernetes&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdygh5lkk9mab3tmqygau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdygh5lkk9mab3tmqygau.png" alt="Manifest repo image from gitlab"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In gitlab to setup a pipeline we need to define it in a yaml file called .gitlab-ci.yml&lt;/p&gt;

&lt;p&gt;Make sure your pipeline looks like below&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51zkh4ji7amscweagb8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg51zkh4ji7amscweagb8.png" alt="Gitlab CI file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pipeline consisits of 2 stages - build and helm-chart-updation&lt;/p&gt;

&lt;h5&gt;
  
  
  Build Stage
&lt;/h5&gt;

&lt;p&gt;In this stage the pipeline logs into the container registry based on the credentials defined in the environment variables and builds the docker image and pushes it to container registry which in our project is the gitlab container registry. Also we login to the repo through SSH Keys which I have provided as an variable for CI/CD&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ay58x0y9nnyimuchfdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ay58x0y9nnyimuchfdl.png" alt="CI/CD Variable SSH"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftg5t12qa8z0cqz6jufku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftg5t12qa8z0cqz6jufku.png" alt="Container registry image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h5&gt;
  
  
  Helm chart updation
&lt;/h5&gt;

&lt;p&gt;In this stage the pipeline after logging in by the SSH Key updates the values.yaml file in manifest repo to the current image from container registry with the latest tag so I don't have to manually change the tag after every run.&lt;/p&gt;

&lt;p&gt;Now let's run the pipeline&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facrpaly0ij8euod759rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facrpaly0ij8euod759rb.png" alt="Pipeline"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My pipeline ran successfully. Now lets move on to setting up argoCD&lt;/p&gt;

&lt;h4&gt;
  
  
  3. ArgoCD
&lt;/h4&gt;

&lt;p&gt;ArgoCD automates the deployment of applications to multiple Kubernetes clusters while maintaining desired state configuration stored in Git repositories. ArgoCD continuously monitors these repositories for changes, ensuring applications are always synchronized with the declared configuration. Its robust capabilities include automated rollbacks, extensive deployment auditing, and a user-friendly UI for visualizing and managing application deployments across environments. It is a core component in GitOps practices.&lt;/p&gt;

&lt;p&gt;Enough said lets start&lt;/p&gt;

&lt;p&gt;ArgoCD can be installed on your cluster by&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ kubectl create namespace argocd
$ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Access the argoCD server&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;ArgoCD provides documentation which seems easy to follow you can access it &lt;a href="https://argo-cd.readthedocs.io/en/stable/getting_started/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets log in to argoCD server&lt;br&gt;
Before we can add our app we need to connect our repo.&lt;br&gt;
Go to settings and go to repositories&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1eqh6hifx2527upr69hd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1eqh6hifx2527upr69hd.png" alt="Settings Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now add our repo details and connect &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F797cegu609y65on1obwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F797cegu609y65on1obwq.png" alt="Repo details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If connection is successful it will show a successful status&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9i5uc35ken2jpahq2u5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9i5uc35ken2jpahq2u5.png" alt="Connection Status"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click on add app to connect our app&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe49mndt7ege5ilbz7527.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe49mndt7ege5ilbz7527.png" alt="argoCD Login Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the name of your app you can give any name but it should be lowercase&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwnhbd1caa9kw5vq9t46.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwnhbd1caa9kw5vq9t46.png" alt="App name details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add source and destination for your app&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fdxqppe2z34stnrkice.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fdxqppe2z34stnrkice.png" alt="Source app details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since my repo has a values.yaml file and it is a helm chart so details are automatically picked up by argoCD&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc04uqoms8810wwj2729.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc04uqoms8810wwj2729.png" alt="Helm Details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After adding details and creating your app you will see a screen like this which shows the appname and if you click on it you will get more details&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuv3td5sivlezrq491he.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuv3td5sivlezrq491he.png" alt="Argo Progress"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Testing the app
&lt;/h4&gt;

&lt;p&gt;We have completed our app setup and it is synchronizing with our repo but how do we find the address where it will be hosted&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fofy4v6orn1foco90fr0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fofy4v6orn1foco90fr0t.png" alt="Service command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After going to the link we have our app now ready&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9aorqr1uwm5tro5rllc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9aorqr1uwm5tro5rllc.png" alt="First instance of app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets test it I will try to change the backgroud image of our app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqm0c6n0ogp1ng68uc3ny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqm0c6n0ogp1ng68uc3ny.png" alt="Background change"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After committing my change the pipeline starts&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z46lbosw4p3s301ynyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5z46lbosw4p3s301ynyw.png" alt="Pipeline run"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And background image of our app has been changed successfully&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw42ixj3xjstmskihbin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw42ixj3xjstmskihbin.png" alt="Final App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations on completing this project and making it till here.&lt;/p&gt;

&lt;p&gt;If you have any questions comment them down I would be happy to help you&lt;/p&gt;

</description>
      <category>gitops</category>
      <category>argocd</category>
      <category>gitlab</category>
      <category>cicd</category>
    </item>
    <item>
      <title>GitOps: Streamlining Kubernetes Application Deployment with GitLab CI/CD, Helm Charts, and ArgoCD</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Mon, 01 Jul 2024 06:38:29 +0000</pubDate>
      <link>https://dev.to/pankaj892/gitops-streamlining-kubernetes-application-deployment-with-gitlab-cicd-helm-charts-and-argocd-685</link>
      <guid>https://dev.to/pankaj892/gitops-streamlining-kubernetes-application-deployment-with-gitlab-cicd-helm-charts-and-argocd-685</guid>
      <description>&lt;p&gt;In the realm of modern software development and deployment practices, GitOps has emerged as a robust methodology for managing Kubernetes applications efficiently. This approach leverages Git as the single source of truth for declarative infrastructure and application code, ensuring consistency, traceability, and collaboration across development teams. In this blog post, we'll delve into the core concepts of GitOps and explore how GitLab CI/CD, Helm Charts, and ArgoCD synergistically enable streamlined application deployment on Kubernetes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Understanding GitOps
&lt;/h4&gt;

&lt;p&gt;GitOps represents a paradigm shift towards managing infrastructure and applications through version-controlled repositories, typically using Git. The key principles of GitOps include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Declarative Configuration&lt;/strong&gt;: Infrastructure and application state are described declaratively and stored as code in Git repositories.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version Control&lt;/strong&gt;: Git provides a versioned history of changes, enabling rollbacks, audits, and collaboration among team members.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation&lt;/strong&gt;: Continuous Integration/Continuous Deployment (CI/CD) pipelines automate the deployment process, triggered by Git repository events.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observability and Monitoring&lt;/strong&gt;: GitOps encourages observability by integrating monitoring and alerting tools with CI/CD pipelines to ensure reliability and performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  GitLab CI/CD: Automating Builds and Deployments
&lt;/h4&gt;

&lt;p&gt;GitLab CI/CD plays a pivotal role in the GitOps workflow by automating build, test, and deployment processes directly from GitLab repositories. Here's how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pipeline Configuration&lt;/strong&gt;: Developers define CI/CD pipelines using &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; files, specifying stages such as build, test, and deploy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Triggering Deployments&lt;/strong&gt;: Changes pushed to specific branches or tags trigger pipeline executions, ensuring that deployments are automatically synchronized with code changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration with Kubernetes&lt;/strong&gt;: GitLab integrates seamlessly with Kubernetes clusters, enabling deployment of Helm Charts and other Kubernetes resources directly from CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Helm Charts: Packaging Kubernetes Applications
&lt;/h4&gt;

&lt;p&gt;Helm is a package manager for Kubernetes that simplifies the deployment and management of applications. Helm Charts encapsulate Kubernetes manifests, making it easier to define, version, and share complex application configurations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Chart Repositories&lt;/strong&gt;: Helm Charts are stored in repositories and referenced in CI/CD pipelines for consistent deployment across environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parameterization&lt;/strong&gt;: Helm Charts support templating and parameterization, allowing customization of configurations for different environments or deployment scenarios.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  ArgoCD: Continuous Deployment and GitOps
&lt;/h4&gt;

&lt;p&gt;ArgoCD is a GitOps continuous delivery tool for Kubernetes that ensures applications are deployed and maintained consistently across clusters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Declarative GitOps Workflows&lt;/strong&gt;: ArgoCD continuously monitors Git repositories for changes and reconciles them with the desired state defined in Helm Charts or Kubernetes manifests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automatic Synchronization&lt;/strong&gt;: Any changes to the Git repository trigger automatic synchronization and deployment updates to Kubernetes clusters, ensuring consistency and reliability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback and Versioning&lt;/strong&gt;: ArgoCD provides rollbacks to previous versions and maintains an audit trail of deployments, enhancing traceability and resilience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;GitOps, powered by GitLab CI/CD, Helm Charts, and ArgoCD, represents a transformative approach to Kubernetes application deployment. By centralizing configuration management, automating deployment workflows, and enhancing observability, organizations can achieve greater efficiency, reliability, and collaboration in their DevOps practices. Embracing GitOps not only streamlines deployment processes but also fosters a culture of continuous improvement and innovation in modern software development teams.&lt;/p&gt;

&lt;p&gt;In summary, GitOps isn't just a methodology but a fundamental shift towards more efficient and reliable Kubernetes operations, leveraging the power of Git and modern CI/CD tools to drive application deployment and management forward.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>LAMP Stack in Microsoft Azure</title>
      <dc:creator>pankaj892</dc:creator>
      <pubDate>Fri, 13 Jan 2023 16:28:53 +0000</pubDate>
      <link>https://dev.to/pankaj892/lamp-stack-in-microsoft-azure-5065</link>
      <guid>https://dev.to/pankaj892/lamp-stack-in-microsoft-azure-5065</guid>
      <description>&lt;p&gt;Hello 👋&lt;br&gt;
I am Pankaj a beginner at cloud computing ☁️ I started my journey with Linux 🐧. I learnt shell scripting and even made a few of them but I didn't know how to enforce my learnings.&lt;/p&gt;

&lt;p&gt;So i searched for some projects to get acquainted with cloud and I came up on LAMP stack.&lt;strong&gt;LAMP&lt;/strong&gt; is an acronym for &lt;strong&gt;Linux&lt;/strong&gt;,&lt;strong&gt;Apache Server&lt;/strong&gt;,&lt;strong&gt;MySql&lt;/strong&gt;,&lt;strong&gt;PHP&lt;/strong&gt; all of these make as a base for an application it is used widely to develop applications in the cloud.&lt;/p&gt;

&lt;p&gt;So let's start&lt;/p&gt;

&lt;p&gt;For this tutorial I assume you know how to create a VM in Azure if not check this from &lt;a href="https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-portal" rel="noopener noreferrer"&gt;Microsoft Learn&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Connecting to VM
&lt;/h2&gt;

&lt;p&gt;Use ssh to connect to the VM(Virtual Machine) hosted in Azure&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kfuaipciln98o3mxvsn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kfuaipciln98o3mxvsn.png" alt="Azure Portal" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After connecting you might get a below screen based on the Linux VM you created I went with Ubuntu but you can use any Linux based VM&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpflh2asnpazwvfc55mg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpflh2asnpazwvfc55mg8.png" alt="Linux VM" width="800" height="416"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  2.Installing Apache server
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Few5pq2ml7h3mkfrkmx5m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Few5pq2ml7h3mkfrkmx5m.png" alt="Command update" width="515" height="43"&gt;&lt;/a&gt;&lt;br&gt;
Run the above command to update the apt repository&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p5egs17s5s8mm2aya0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p5egs17s5s8mm2aya0m.png" alt="Install command" width="536" height="49"&gt;&lt;/a&gt;&lt;br&gt;
Now we install apache server with the above command press Y if asked &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz0fpn4zsjh36epg98nr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz0fpn4zsjh36epg98nr.png" alt="Result" width="800" height="369"&gt;&lt;/a&gt;&lt;br&gt;
You can check if server is installed correctly by going to the ip address of the VM. If you get the above image be proud that you have completed an important task in LAMP stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Installing MySQL database
&lt;/h2&gt;

&lt;p&gt;Now lets move onto installing MySql database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe25g2wzbi68a3ltmriqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe25g2wzbi68a3ltmriqz.png" alt="SQL Install" width="800" height="205"&gt;&lt;/a&gt; &lt;br&gt;
We will install mysql server using the above command and enter Y when asked during installation.&lt;/p&gt;

&lt;p&gt;Now comes the part to harden the sql installation so it can be saved from attacks&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxkm6wz599lo0ut681tg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxkm6wz599lo0ut681tg.png" alt="Hardening SQL Installation" width="551" height="20"&gt;&lt;/a&gt;&lt;br&gt;
After executing this command you need to set a password it should be different from the one you used for your VM (in case you used a password for connecting VM in Azure)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fui80ihgjutubinde2aci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fui80ihgjutubinde2aci.png" alt="Connect to SQL" width="800" height="191"&gt;&lt;/a&gt;&lt;br&gt;
Connect to sql database using the password you set earlier in the previous command.&lt;br&gt;
You can see you get a sql prompt if password is correct &lt;br&gt;
Type exit to come out of sql &lt;/p&gt;

&lt;p&gt;Finally you are done with SQL installation now lets move on to php installation&lt;/p&gt;

&lt;h2&gt;
  
  
  4.Installing PHP
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ak1pixxci7xs618nwpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ak1pixxci7xs618nwpq.png" alt="PHP installation" width="800" height="210"&gt;&lt;/a&gt;&lt;br&gt;
Install php using the command above and press Y i asked during installation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwaatmhm8jv546v8qfzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwaatmhm8jv546v8qfzr.png" alt="Install phpmyadmin" width="634" height="61"&gt;&lt;/a&gt;&lt;br&gt;
Now we will install phpmyadmin to access the php dashboard and also for accessing the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.Next steps
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vexo2hggqy51omoatzv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vexo2hggqy51omoatzv.png" alt="Restart apache" width="596" height="101"&gt;&lt;/a&gt;&lt;br&gt;
We need to restart apache server in order to take efect the changes we made to system&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqw5yk1kw20rx5pc9d413.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqw5yk1kw20rx5pc9d413.png" alt="Apache server" width="800" height="409"&gt;&lt;/a&gt;&lt;br&gt;
Select the apache server using spacebar and navigate to the OK button using TAB&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2u6bbo8b7wyu5uy3c4u2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2u6bbo8b7wyu5uy3c4u2.png" alt="Password set" width="800" height="306"&gt;&lt;/a&gt;&lt;br&gt;
You can set the password or let phpmyadmin automatically generate one for you.&lt;/p&gt;

&lt;p&gt;And you are done with the LAMP stack installation.&lt;br&gt;
Be proud of yourself that you completed the most used task in cloud computing and Welcome to the Cloud ☁️&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
  </channel>
</rss>
