<?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 Anju on Medium]]></title>
        <description><![CDATA[Stories by Anju on Medium]]></description>
        <link>https://medium.com/@anju-chaurasiya2012?source=rss-9a06aa352229------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b-izwslJOILccBcCb584bg.jpeg</url>
            <title>Stories by Anju on Medium</title>
            <link>https://medium.com/@anju-chaurasiya2012?source=rss-9a06aa352229------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:16:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anju-chaurasiya2012/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[Linux Disks]]></title>
            <link>https://anju-chaurasiya2012.medium.com/linux-disks-1664bc7a012d?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/1664bc7a012d</guid>
            <category><![CDATA[disk]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Wed, 25 Nov 2026 09:58:52 GMT</pubDate>
            <atom:updated>2026-11-25T09:58:52.109Z</atom:updated>
            <content:encoded><![CDATA[<p>The first time you run lsblk on a Linux server, the output can feel like a different language:</p><pre>NAME      MAJ:MIN  SIZE TYPE MOUNTPOINTS<br>vda       253:0    200G disk<br>├─vda1    253:1    513M part /boot/efi<br>└─vda2    253:2  199.5G part /<br>vdb       253:16     5T disk</pre><p>What is vda? Why does it contain vda1 and vda2? What does 253:16 mean?</p><p>These fields describe different aspects of storage: its Linux name, its structure, its current device numbers, and where its filesystem is accessible.</p><p>The commands below inspect storage. They do not format or repartition disks. Example names and numbers may differ on your machine.</p><h3>Start with the storage vocabulary.</h3><p>A few terms make the rest of the output easier to understand:</p><ul><li><strong>Disk</strong> — A storage device presented to Linux. It can be physical or virtual. <em>Example:</em> An SSD, AWS EBS volume, or virtual-machine disk</li><li><strong>Block device</strong> — A device that Linux reads and writes in blocks. Disks, partitions, and logical volumes can all be block devices. <em>Example:</em> /dev/vda</li><li><strong>Partition</strong> — A defined region within a disk. <em>Example:</em> /dev/vda2</li><li><strong>Partition table</strong> — Metadata describing the disk’s partitions. GPT is a common format. <em>Example:</em> A GPT partition table</li><li><strong>Filesystem</strong> — The structure used to organize files and directories on storage. <em>Example:</em> ext4, xfs</li><li><strong>Mount point</strong> — The directory through which a mounted filesystem becomes accessible. <em>Example:</em> /, /boot/efi, /var/appd/data</li><li><strong>Driver</strong> — Kernel software that communicates with a device or virtual storage interface. <em>Example:</em> A VirtIO or NVMe driver</li></ul><p>A common arrangement looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlRWNMVapipLq9qfllFffw.png" /></figure><p>Here, / is the root of the Linux directory tree.</p><blockquote><em>Partitions are common, but they are not mandatory. A filesystem can occupy an entire disk. Therefore, a disk without visible partitions may already contain data.</em></blockquote><p>You may also encounter LVM, or Logical Volume Manager. It adds a storage-management layer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZ_Rp5IqRlq6S1xTaN_ncg.png" /></figure><p>A logical volume may appear under a name such as /dev/mapper/appd0-data.</p><h3>Device paths are how Linux exposes storage to programs.</h3><p>The /dev directory contains special device files, also called device nodes.</p><p>For example:</p><pre>/dev/sda<br>/dev/vda<br>/dev/nvme0n1</pre><p>These paths refer to devices. They are different from ordinary files such as /home/alice/report.txt.</p><p>Several naming patterns are common:</p><ul><li><strong>/dev/sda</strong> — A disk exposed through the SCSI disk subsystem, including many SATA, SAS, USB, and virtual disks</li><li><strong>/dev/vda</strong> — A VirtIO block disk, commonly used by virtual machines</li><li><strong>/dev/nvme0n1</strong> — An NVMe namespace exposed as a block device</li><li><strong>/dev/xvda</strong> — A Xen virtual block device</li><li><strong>/dev/mmcblk0</strong> — An SD card or eMMC storage device</li><li><strong>/dev/loop0</strong> — A file exposed as a block device</li><li><strong>/dev/dm-0</strong> — A device-mapper device, potentially backing LVM, encryption, or multipath storage</li></ul><p>The name describes how Linux presents the device. It does not, by itself, identify the cloud provider or establish that the storage is persistent.</p><h3>Use lsblk to see the relationships.</h3><p>Its name means “list block devices.”</p><pre>lsblk -o NAME,MAJ:MIN,SIZE,TYPE,FSTYPE,MOUNTPOINTS</pre><p>The columns answer different questions:</p><ul><li><strong>NAME</strong> — The device’s Linux name</li><li><strong>MAJ:MIN</strong> — Its current major and minor device numbers</li><li><strong>SIZE</strong> — Device capacity</li><li><strong>TYPE</strong> — Whether it is a disk, partition, logical volume, or another device type</li><li><strong>FSTYPE</strong> — The detected filesystem or storage-signature type</li><li><strong>MOUNTPOINTS</strong> — Where its filesystem is mounted</li></ul><p>The tree indentation shows relationships. In the opening example, vda1 and vda2 are partitions belonging to vda.</p><blockquote><em>A blank mount-point column only means no mount point is shown. It does not establish that a device is empty or available for formatting.</em></blockquote><p><a href="https://kernel.googlesource.com/pub/scm/utils/util-linux/util-linux/+/refs/tags/v2.41.1/misc-utils/lsblk.8.adoc">The lsblk manual</a> explains its output and options.</p><h3>Major and minor numbers are kernel device identifiers.</h3><p>Consider:</p><pre>vdb    253:16</pre><p>This means:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmFF6N33AL6G4eKz2OnbSA.png" /></figure><p>The major number identifies a registered device-number group, often associated with a driver. The minor number distinguishes devices within that group.</p><p>For the traditional SCSI disk allocation, examples include:</p><ul><li><strong>/dev/sda</strong> — 8:0 — Whole disk</li><li><strong>/dev/sda1</strong> — 8:1 — First partition on sda</li><li><strong>/dev/sdb</strong> — 8:16 — Another whole disk</li><li><strong>/dev/sdb1</strong> — 8:17 — First partition on sdb</li></ul><p>Notice that the minor number is not simply the partition number: /dev/sdb1 has minor 17 in this allocation. Other device families use different allocation schemes. <a href="https://www.kernel.org/doc/Documentation/admin-guide/devices.txt">Linux allocated-device registry</a></p><p>An inode number is a separate concept: it identifies a file’s inode within a filesystem. The major and minor numbers associated with a device node identify the device represented by that file. <a href="https://man7.org/linux/man-pages/man7/inode.7.html">Linux inode documentation</a></p><h3>Some major numbers are familiar, but a lookup table is not a universal discovery rule.</h3><ul><li><strong>Traditional SCSI disk allocations</strong> — 8 and additional registered majors</li><li><strong>Loop devices</strong> — Commonly 7</li><li><strong>Linux software RAID</strong> — Commonly 9</li><li><strong>Optical drives such as sr0</strong> — Commonly 11</li><li><strong>MMC/eMMC</strong> — Commonly 179</li><li><strong>Xen virtual disks</strong> — Commonly 202</li><li><strong>NVMe namespace devices</strong> — Commonly use extended block major 259</li><li><strong>VirtIO disks</strong> — Dynamically allocated; inspect the running system</li><li><strong>Device-mapper devices</strong> — Inspect the running system</li></ul><blockquote><em>Major 259 is the extended block major; it is not exclusive to NVMe. VirtIO explicitly requests a dynamically allocated major from the kernel. Consequently, observing 253 on one server does not make it a universal VirtIO identifier.</em></blockquote><p><a href="https://www.kernel.org/doc/Documentation/admin-guide/devices.txt">Linux device registry</a>, <a href="https://raw.githubusercontent.com/torvalds/linux/master/drivers/block/virtio_blk.c">VirtIO driver source</a></p><h3>“Hard-coded” describes an assumption in your script.</h3><p>For example:</p><pre>lsblk -I 8,259 --nodeps --noheadings --paths --output NAME</pre><p>The -I option includes only the listed major numbers.</p><p>If a VM exposes these disks:</p><pre>/dev/vda    253:0<br>/dev/vdb    253:16</pre><p>the filter excludes both. The disks exist, but the script does not discover them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0S34t1fta_bhtdn_DxWGxg.png" /></figure><p>Changing the filter to 253 may work on that VM while excluding devices on another machine. Looking up the current major number does not make that number portable.</p><p>There are two separate ideas here: the kernel may allocate a number statically or dynamically, and a script may embed that observed number as a fixed assumption.</p><h3>An NVMe name contains several parts.</h3><p>Consider:</p><pre>/dev/nvme2n1p2</pre><p>Read it from the outside inward:</p><ul><li><strong>/dev/</strong> — The device-file directory</li><li><strong>nvme2n1</strong> — A Linux NVMe namespace block device</li><li><strong>p2</strong> — Partition number 2 within that device</li></ul><p>An NVMe controller handles storage commands. A namespace is an addressable region of NVMe storage that Linux can expose as a disk. Partitions can then be created within that namespace.</p><p>The numeric portions of the name are Linux enumeration labels. Controller, subsystem, and namespace-instance numbering can differ with the storage configuration, so the name should not be interpreted as a permanent physical-drive identifier. <a href="https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux/+/3857c2fe5449541e24afc5efdb0f81a8a8f9a3a0/drivers/nvme/host/core.c">Linux NVMe naming implementation</a></p><p>Inspect the whole namespace and its partition separately:</p><pre>lsblk -f /dev/nvme2n1<br>lsblk -f /dev/nvme2n1p2</pre><h3>You can inspect device numbers in several ways.</h3><p>For a device that exists on your machine:</p><pre>ls -l /dev/vdb</pre><p>Example:</p><pre>brw-rw---- 1 root disk 253, 16 Nov 25 11:00 /dev/vdb</pre><p>The initial b identifies a block-device node. The pair 253, 16 gives its major and minor numbers.</p><p>The kernel also exposes the pair through sysfs:</p><pre>cat /sys/class/block/vdb/dev</pre><p>Example:</p><pre>253:16</pre><p>To see registered device-number groups:</p><pre>cat /proc/devices</pre><p>Look under Block devices. This lists registrations, rather than providing a complete inventory of every attached disk.</p><h3>Persistent identifiers help when device names change.</h3><p>On AWS Nitro, for example, NVMe names can change when devices respond in a different order during startup. AWS recommends stable identifiers such as EBS volume IDs. Filesystem UUIDs serve a different purpose: identifying filesystems. <a href="https://docs.aws.amazon.com/ebs/latest/userguide/identify-nvme-ebs-device.html">AWS NVMe identification documentation</a></p><p>Useful inspection commands include:</p><pre>lsblk -o NAME,TYPE,SERIAL,UUID,PARTUUID,MOUNTPOINTS<br>findmnt --target /</pre><p>findmnt — target / shows the filesystem mounted at the root directory. If its source is an LVM device, you still need to trace its backing storage to identify the physical or virtual disk. <a href="https://man7.org/linux/man-pages/man8/findmnt.8.html">The findmnt manual</a></p><h3>Disk discovery and disk selection are separate steps.</h3><p>This command discovers devices reported as whole disks without embedding major numbers:</p><pre>lsblk --nodeps --noheadings --paths --output NAME,TYPE |<br>    awk &#39;$2 == &quot;disk&quot; { print $1 }&#39;</pre><p>awk examines each output row: when the second column equals disk, it prints the first column.</p><p>The results can include the OS disk, application disks, and temporary disks. Further checks must establish which device belongs to the application and whether it is safe to initialize.</p><p>If you store the results using Bash, the command becomes silent:</p><pre>mapfile -t disks &lt; &lt;(<br>    lsblk --nodeps --noheadings --paths --output NAME,TYPE |<br>        awk &#39;$2 == &quot;disk&quot; { print $1 }&#39;<br>)</pre><p>mapfile reads lines into an array. It does not print the array. Display its contents explicitly:</p><pre>declare -p disks<br>printf &#39;Discovered disks: %s\n&#39; &quot;${#disks[@]}&quot;</pre><p>A successful mapfile exit status does not establish that any disks matched, nor does it establish that the command inside process substitution succeeded. Production scripts need explicit failure handling as well as validation of the discovered devices. <a href="https://www.gnu.org/software/bash/manual/bash.html#index-mapfile">GNU Bash manual</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1664bc7a012d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filesystem Types]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Have you ever wondered how many filesystem types your Linux servers support?</p><p class="medium-feed-link"><a href="https://anju-chaurasiya2012.medium.com/filesystem-types-f5316fd68389?source=rss-9a06aa352229------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://anju-chaurasiya2012.medium.com/filesystem-types-f5316fd68389?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5316fd68389</guid>
            <category><![CDATA[linux-commands]]></category>
            <category><![CDATA[filesystem]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 07:25:27 GMT</pubDate>
            <atom:updated>2026-02-12T07:25:27.555Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Probes]]></title>
            <link>https://anju-chaurasiya2012.medium.com/understanding-kubernetes-probes-22e756e7eab4?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/22e756e7eab4</guid>
            <category><![CDATA[application-deployment]]></category>
            <category><![CDATA[kubernetes-probes]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Wed, 19 Mar 2025 12:08:30 GMT</pubDate>
            <atom:updated>2025-03-19T12:08:30.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes provides powerful mechanisms to ensure the reliability and stability of applications running in a cluster. One such feature is <strong>probes</strong>, which help Kubernetes determine the health of an application. In this blog, we’ll explore the three types of probes in Kubernetes — <strong>startup probes, readiness probes, and liveness probes</strong> — using an example deployment.</p><h3>What Are Kubernetes Probes?</h3><p>Probes are diagnostic checks performed on a container to determine its health and availability. Kubernetes uses three types of probes:</p><ol><li><strong><em>Liveness Probe</em></strong>: Checks if the container is still running.</li></ol><ul><li>Determines if the container is still <strong>alive</strong> and functioning properly.</li><li>If the probe fails, Kubernetes <strong>kills the container</strong> and restarts it.</li><li>Useful for detecting deadlocks or application crashes.</li></ul><p><strong>2. <em>Readiness Probe</em></strong>: Checks if the container is ready to serve requests.</p><ul><li>Checks if the container is <strong>ready to accept traffic</strong>.</li><li>If the probe fails, Kubernetes <strong>removes the pod from the Service’s endpoints</strong> (but does <strong>not</strong> restart it).</li><li>Useful when an app has a long startup time.</li></ul><p><strong>3. <em>Startup Probe</em></strong>: Ensures the container has started properly before other probes take over.</p><ul><li>Used for <strong>slow-starting applications</strong> that take a long time to initialize.</li><li>It prevents <strong>unnecessary restarts</strong> caused by the liveness probe during startup.</li><li>Once the startup probe succeeds, the liveness probe takes over.</li></ul><h3>How Probes Work</h3><p>Each probe can be configured using different methods:</p><ul><li><strong>httpGet</strong>: Makes an HTTP request to a specific endpoint.</li><li><strong>tcpSocket</strong>: Checks if a TCP connection to a container port is successful.</li><li><strong>exec</strong>: Runs a command inside the container to determine health.</li></ul><h3>Example: Probes in Action</h3><p>Let’s take an example of a <strong>Spring Cloud Config Server</strong> running in a Kubernetes cluster. The configuration below defines all three probes to ensure that the service starts correctly, remains alive, and is ready to serve traffic.</p><h3>Deployment YAML with Probes</h3><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: config-server<br>  labels:<br>    app: config-server<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: config-server<br>  template:<br>    metadata:<br>      labels:<br>        app: config-server<br>    spec:<br>      serviceAccountName: config-server-sa<br>      imagePullSecrets:<br>        - name: regcred<br>      containers:<br>        - name: config-server<br>          image: &quot;spring-cloud-config-server:latest&quot;<br>          ports:<br>            - name: http<br>              containerPort: 8888<br>          env:<br>            - name: VAULT_HOST<br>              value: &quot;vault.vault.svc.cluster.local&quot;<br>            - name: SECRET_PATH<br>              value: &quot;test-secret&quot;<br>          imagePullPolicy: Always<br>          resources:<br>            limits:<br>              cpu: 300m<br>              memory: 500Mi<br>            requests:<br>              cpu: 50m<br>              memory: 300Mi<br>          <br>          # Startup Probe - Ensures the app has fully started before other probes take over<br>          startupProbe:<br>            httpGet:<br>              path: /actuator/health<br>              port: 8888<br>            failureThreshold: 30<br>            periodSeconds: 10<br>          <br>          # Readiness Probe - Ensures the app is ready to accept traffic<br>          readinessProbe:<br>            httpGet:<br>              path: /actuator/health/readiness<br>              port: 8888<br>            initialDelaySeconds: 20<br>            periodSeconds: 10<br>          <br>          # Liveness Probe - Ensures the app is still running<br>          livenessProbe:<br>            httpGet:<br>              path: /actuator/health/liveness<br>              port: 8888<br>            initialDelaySeconds: 20<br>            periodSeconds: 10</pre><h3>Service YAML</h3><pre>kind: Service<br>apiVersion: v1<br>metadata:<br>  name: config-server-sv<br>  namespace: core<br>spec:<br>  selector:<br>    app: config-server<br>  type: ClusterIP<br>  ports:<br>     - port: 80<br>       targetPort: 8888<br>       protocol: TCP<br>       name: http</pre><h3>Understanding the Probes in This Example</h3><p><strong><em>Startup Probe</em></strong></p><ul><li>It pings the /actuator/health endpoint every 10 seconds.</li><li>Kubernetes will wait for 30 failed attempts before marking the container as unhealthy.</li><li>Used when an application has a slow startup time to prevent false failures.</li></ul><p><strong><em>Readiness Probe</em></strong></p><ul><li>Checks the /actuator/health/readiness endpoint after 20 seconds.</li><li>Ensures the service is fully ready before allowing traffic.</li><li>Prevents the app from receiving requests until it’s operational.</li></ul><p><strong><em>Liveness Probe</em></strong></p><ul><li>Periodically pings the /actuator/health/liveness endpoint.</li><li>If it fails, Kubernetes restarts the container.</li><li>Ensures the application remains alive and responsive.</li></ul><h3>When to Use Each Probe</h3><p>Probe Type Purpose <strong>Startup</strong> Used for applications with long startup times. Prevents liveness and readiness probes from interfering until startup is complete. <strong>Readiness</strong> Ensures a container is ready to handle traffic. If it fails, Kubernetes removes it from the service load balancer. <strong>Liveness</strong> Detects if an application is stuck or unresponsive. If it fails, Kubernetes restarts the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NeSkBK3WOvo0aK5jA2rLow.png" /></figure><h3>Best Practices</h3><ul><li><strong>Use startupProbe for applications with a long initialization time.</strong></li><li>Use <strong>liveness probes</strong> to restart crashed/hung apps and <strong>readiness probes</strong> to prevent routing traffic to unready pods.</li><li><strong>Ensure that readinessProbe and livenessProbe check appropriate endpoints.</strong></li><li><strong>Avoid aggressive failure thresholds to prevent unnecessary restarts.</strong></li><li><strong>Monitor probe failures using Kubernetes logs and metrics.</strong></li></ul><h3>Conclusion</h3><p>Kubernetes probes are essential for maintaining application health and availability. By properly configuring <strong>liveness, readiness, and startup probes</strong>, you can ensure that your applications are always responsive, restart when needed, and only receive traffic when they’re truly ready.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22e756e7eab4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using SecretStore, ExternalSecret, and Secret in Kubernetes with Vault]]></title>
            <link>https://anju-chaurasiya2012.medium.com/using-secretstore-externalsecret-and-secret-in-kubernetes-with-vault-a375cd94ad1c?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/a375cd94ad1c</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[secret-storage-csi]]></category>
            <category><![CDATA[external-secrets-operator]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 07:16:20 GMT</pubDate>
            <atom:updated>2025-03-18T07:16:20.421Z</atom:updated>
            <content:encoded><![CDATA[<p>Secrets management is a crucial part of Kubernetes security. External Secrets Operator (ESO) allows Kubernetes to fetch secrets from external sources like HashiCorp Vault, AWS Secrets Manager, and more. In this blog, we’ll demonstrate how to use SecretStore, ExternalSecret, and Secret in Kubernetes, with Vault as the backend.</p><h3>Prerequisites</h3><p>Ensure you have the following set up:</p><ul><li>A running Kubernetes cluster</li><li>Helm installed</li><li>HashiCorp Vault deployed and configured</li><li>External Secrets Operator installed in Kubernetes</li></ul><h3>Step 1: Install HashiCorp Vault</h3><p>If you haven’t already installed Vault, you can deploy it using Helm:</p><pre>helm repo add hashicorp https://helm.releases.hashicorp.com<br>helm install vault hashicorp/vault --set &quot;server.dev.enabled=true&quot;</pre><p>Verify that Vault is running:</p><pre>kubectl get pods -n default</pre><h3>Step 2: Enable and Configure Vault for Kubernetes</h3><p>Exec into the Vault pod and enable Kubernetes authentication:</p><pre>kubectl exec -it vault-0 -- vault login root<br>kubectl exec -it vault-0 -- vault auth enable kubernetes</pre><p>Configure Vault policies and secrets:</p><pre>kubectl exec -it vault-0 -- sh<br>vault policy write k8s-secret-policy - &lt;&lt;EOF<br>path &quot;secret/data/myapp&quot; {<br>  capabilities = [&quot;read&quot;]<br>}<br>EOF</pre><p>Write a test secret to Vault:</p><pre>vault kv put secret/myapp username=admin password=supersecret</pre><h3>Step 3: Install External Secrets Operator</h3><p>Install ESO using Helm:</p><pre>helm repo add external-secrets https://charts.external-secrets.io<br>helm install external-secrets external-secrets/external-secrets</pre><p>Verify installation:</p><pre>kubectl get pods -n external-secrets</pre><h3>Step 4: Create a SecretStore</h3><p>A SecretStore defines how Kubernetes should communicate with Vault.</p><pre>apiVersion: external-secrets.io/v1beta1<br>kind: SecretStore<br>metadata:<br>  name: vault-secretstore<br>  namespace: default<br>spec:<br>  provider:<br>    vault:<br>      server: &quot;http://vault.default:8200&quot;<br>      path: &quot;secret&quot;<br>      version: &quot;v2&quot;<br>      auth:<br>        kubernetes:<br>          mountPath: &quot;kubernetes&quot;<br>          role: &quot;my-role&quot;</pre><p>Apply it:</p><pre>kubectl apply -f secretstore.yaml</pre><h3>Step 5: Create an ExternalSecret</h3><p>An ExternalSecret maps Vault secrets to Kubernetes secrets.</p><pre>apiVersion: external-secrets.io/v1beta1<br>kind: ExternalSecret<br>metadata:<br>  name: my-secret<br>  namespace: default<br>spec:<br>  refreshInterval: 1m<br>  secretStoreRef:<br>    name: vault-secretstore<br>    kind: SecretStore<br>  target:<br>    name: my-k8s-secret<br>  data:<br>    - secretKey: username<br>      remoteRef:<br>        key: myapp<br>        property: username<br>    - secretKey: password<br>      remoteRef:<br>        key: myapp<br>        property: password</pre><p>Apply it:</p><pre>kubectl apply -f externalsecret.yaml</pre><h3>Step 6: Verify the Kubernetes Secret</h3><p>Once ExternalSecret is applied, check if Kubernetes has created the corresponding secret:</p><pre>kubectl get secrets</pre><p>Decode the secret values:</p><pre>kubectl get secret my-k8s-secret -o yaml</pre><p>You should see Base64 encoded values for username and password. Decode them using:</p><pre>echo &quot;&lt;base64-encoded-value&gt;&quot; | base64 --decode</pre><h3>Conclusion</h3><p>With External Secrets Operator, Kubernetes can seamlessly integrate with Vault to manage secrets securely. This approach eliminates the need to manually create Kubernetes secrets and ensures they stay updated with changes in Vault. Happy automating!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a375cd94ad1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Active Connections in PostgreSQL to Drop a Database]]></title>
            <link>https://anju-chaurasiya2012.medium.com/managing-active-connections-in-postgresql-to-drop-a-database-fb21baf8d8ed?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb21baf8d8ed</guid>
            <category><![CDATA[postgresql-database]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 12:38:32 GMT</pubDate>
            <atom:updated>2025-03-17T12:38:32.309Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with PostgreSQL, you may encounter situations where you need to drop a database but can’t because of active connections. In this blog, we’ll go through the steps to identify and terminate active connections before successfully dropping a database.</p><h3>Common Error: Database is Being Accessed by Other Users</h3><p>When you try to drop a database that has active connections, PostgreSQL throws the following error:</p><pre>postgres=# DROP DATABASE appdb;<br>ERROR:  database &quot;appdb&quot; is being accessed by other users<br>DETAIL:  There are 20 other sessions using the database.</pre><p>This happens because there are active sessions connected to the database. To proceed, we need to terminate these connections first.</p><h3>Steps to Identify and Terminate Active Sessions</h3><h3>Step 1: Connect to the PostgreSQL Pod</h3><p>If you’re working in a Kubernetes environment, start by accessing the PostgreSQL pod:</p><pre>kubectl exec -it appdb-postgres-0 -- bash</pre><p>Once inside the pod, switch to the PostgreSQL CLI:</p><pre>psql -U postgres</pre><h3>Step 2: List All Active Sessions</h3><p>To check which sessions are currently connected to the database, run:</p><pre>SELECT * FROM pg_stat_activity;</pre><p>This will display all active connections along with their process IDs (PIDs), users, and client addresses.</p><p>Sample output:</p><pre>datid  | datname  |  pid  | usename  | application_name | client_addr | state  | query<br>--------+---------+-------+----------+------------------+-------------+--------+----------------------------<br> 16384  | appdb   | 94607 | appdb    | PostgreSQL JDBC Driver | 10.244.3.129 | idle   | SET application_name = &#39;PostgreSQL JDBC Driver&#39;<br> 16384  | appdb   | 94652 | appdb    | PostgreSQL JDBC Driver | 10.244.3.129 | idle   | SET application_name = &#39;PostgreSQL JDBC Driver&#39;<br> ...</pre><h3>Step 3: Terminate Active Connections</h3><p>To terminate all active connections to the appdb database, execute:</p><pre>SELECT pg_terminate_backend(pg_stat_activity.pid)<br>FROM pg_stat_activity<br>WHERE pg_stat_activity.datname = &#39;appdb&#39;<br>AND pid &lt;&gt; pg_backend_pid();</pre><p>Output:</p><pre>pg_terminate_backend<br>----------------------<br> t<br> t<br> t<br> t<br> t<br> t<br> t<br> t<br> t<br> t<br>(10 rows)</pre><p>If the sessions persist, you may need to revoke connection privileges to ensure no new connections are established.</p><h3>Step 4: Revoke Connection Privileges</h3><p>To prevent new connections from being established while you drop the database, revoke access:</p><pre>REVOKE CONNECT ON DATABASE appdb FROM PUBLIC, appdb;</pre><h3>Step 5: Verify and Drop the Database</h3><p>Once all connections are terminated, you can safely drop the database:</p><pre>DROP DATABASE appdb;</pre><p>If everything was successful, you should see:</p><pre>DROP DATABASE</pre><h3>Conclusion</h3><p>When dropping a PostgreSQL database, active connections can prevent the operation. By identifying and terminating these sessions using pg_stat_activity and pg_terminate_backend(), along with revoking access, you can ensure a smooth database removal process. These steps are particularly useful in Kubernetes or cloud environments where multiple services interact with the database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb21baf8d8ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating PostgreSQL Database Between Pods in Kubernetes]]></title>
            <link>https://anju-chaurasiya2012.medium.com/migrating-postgresql-database-between-pods-in-kubernetes-162ba3ce14d6?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/162ba3ce14d6</guid>
            <category><![CDATA[db-migration]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 12:33:51 GMT</pubDate>
            <atom:updated>2025-03-17T12:33:51.112Z</atom:updated>
            <content:encoded><![CDATA[<p>Database migrations are a common task in cloud-native environments, especially when working with containerized databases. This guide will walk you through migrating a PostgreSQL database from an existing pod (appdb) to a new one using pg_dump and pg_restore.</p><p>We’ll cover:</p><ul><li>Accessing PostgreSQL running in a Kubernetes pod</li><li>Dumping and copying the database backup</li><li>Restoring the database on a new pod</li><li>Handling authentication and troubleshooting</li></ul><h3>1. Checking the Current PostgreSQL Pod</h3><p>Before performing the migration, we need to identify the PostgreSQL pod in the current environment. Run the following command:</p><pre>kubectl get pods| grep -i appdb</pre><p>This will list all pods related to appdb. Identify the primary pod from the output.</p><h3>2. Dumping the Database from the Existing Pod</h3><p>Once the PostgreSQL pod is identified, execute a shell session inside the pod:</p><pre>kubectl exec -it &lt;appdb-postgres-primary-pod-name&gt; bash</pre><p>Now, create a database dump using pg_dump:</p><pre>pg_dump -U postgres appdb &gt; /tmp/appdb_backup.sql</pre><p>You will be prompted to enter the PostgreSQL password.</p><h3>Copying the Backup to the Local Machine</h3><p>Exit the pod and run the following command to copy the backup file from the pod to your local machine:</p><pre>kubectl cp &lt;appdb-postgres-primary-pod-name&gt;:/tmp/appdb_backup.sql ./appdb_backup.sql</pre><p>At this point, you have successfully extracted the appdb database backup from the old pod.</p><h3>3. Preparing the New PostgreSQL Pod</h3><p>On the new pod, it’s a good practice to back up the existing pg_hba.conf file before making any modifications:</p><pre>cat /opt/bitnami/postgresql/conf/pg_hba.conf &gt; /tmp/pghba</pre><h3>Modifying pg_hba.conf for Trust Authentication</h3><p>Since we are migrating the database, we need to temporarily enable trust authentication to avoid password authentication errors. Run the following command:</p><pre>/opt/bitnami/scripts/postgresql/entrypoint.sh /bin/bash -c &#39;export PGPASSWORD=&quot;&lt;OLD_POSTGRES_PASSWORD&gt;&quot;; echo &quot;local all postgres trust&quot; &gt; /opt/bitnami/postgresql/conf/pg_hba.conf; pg_ctl reload; time pg_dumpall -c -h &lt;OLD_POSTGRES_POD_IP&gt; -U postgres | psql -U postgres&#39;</pre><p>This command does the following:</p><ol><li>Sets PGPASSWORD for authentication.</li><li>Modifies pg_hba.conf to allow trust authentication.</li><li>Reloads PostgreSQL to apply the new configuration.</li><li>Dumps all databases from the old PostgreSQL pod and pipes them into psql for restoration.</li></ol><h3>4. Restoring the Original Configuration</h3><p>After the migration is complete, revert pg_hba.conf to its original state:</p><pre>cat /tmp/pghba &gt; /opt/bitnami/postgresql/conf/pg_hba.conf<br>pg_ctl reload</pre><p>This ensures that normal authentication settings are restored, preventing unauthorized access.</p><h3>5. Verifying the Migration</h3><p>Once the migration is complete, verify that the database was successfully transferred.</p><h3>Connect to the Database</h3><pre>psql -U postgres</pre><h3>List Available Databases</h3><pre>\l</pre><p>Expected output:</p><pre>List of databases<br>        Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges<br>    ------------+----------+----------+---------+-------+-----------------------<br>     appdb      | postgres | UTF8     | en_US   | en_US | <br>     postgres   | postgres | UTF8     | en_US   | en_US | <br>     template0  | postgres | UTF8     | en_US   | en_US | <br>     template1  | postgres | UTF8     | en_US   | en_US |</pre><h3>Check the Tables in appdb</h3><pre>\c appdb<br>\dt</pre><p>Example output:</p><pre>List of relations<br> Schema |     Name      | Type  |  Owner  <br>--------+---------------+-------+---------<br> public | users         | table | postgres<br> public | orders        | table | postgres<br> public | products      | table | postgres</pre><p>If the tables are present, the migration was successful.</p><h3>6. Troubleshooting Common Issues</h3><h3>Authentication Errors</h3><p>If you encounter an error like:</p><pre>psql: error: connection to server on socket &quot;/tmp/.s.PGSQL.5432&quot; failed: FATAL:  no pg_hba.conf entry for host &quot;[local]&quot;, user &quot;appdb&quot;, database &quot;appdb&quot;, no encryption</pre><p>It means the pg_hba.conf file does not allow the appdb user to authenticate. Ensure that it includes an appropriate rule:</p><pre>local   all             all                                     md5</pre><p>Then reload the PostgreSQL configuration:</p><pre>pg_ctl reload</pre><h3>Connection Refused</h3><p>If you see:</p><pre>psql: could not connect to server: Connection refused</pre><p>Check if PostgreSQL is running:</p><pre>pg_ctl status</pre><p>If it’s not running, start it manually:</p><pre>pg_ctl start</pre><h3>Errors During Restoration</h3><p>If the restoration process throws errors about existing databases or roles, they can often be ignored. However, if a specific table is missing, manually restore the backup:</p><pre>psql -U postgres appdb &lt; appdb_backup.sql</pre><h3>Conclusion</h3><p>Migrating a PostgreSQL database between pods in Kubernetes involves careful planning and execution. In this guide, we covered:</p><ul><li>Extracting the database dump from an old PostgreSQL pod.</li><li>Copying the dump to a new pod.</li><li>Temporarily modifying pg_hba.conf for authentication.</li><li>Restoring the database on the new pod.</li><li>Troubleshooting authentication and connection issues.</li></ul><p>By following these steps, you can successfully migrate PostgreSQL databases with minimal downtime. If you run into issues, double-check the authentication settings and database connections. Happy migrating! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=162ba3ce14d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gitlab ci/cd configuration file]]></title>
            <link>https://anju-chaurasiya2012.medium.com/gitlab-ci-cd-configuration-file-e485a3f88874?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/e485a3f88874</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Wed, 12 Mar 2025 12:02:34 GMT</pubDate>
            <atom:updated>2025-03-12T12:02:34.375Z</atom:updated>
            <content:encoded><![CDATA[<p>In GitLab CI/CD, there are <strong>four main ways</strong> to define and use the .gitlab-ci.yml configuration file:</p><p><strong>1. Single </strong><strong>.gitlab-ci.yml File (Monolithic Approach)</strong></p><p>This is the most straightforward method where all pipeline configurations are defined in a single .gitlab-ci.yml file at the root of the repository. Suitable for small to medium-sized projects.</p><p>Example:</p><pre>stages:<br>  - build<br>  - test<br>  - deploy<br><br>build-job:<br>  stage: build<br>  script:<br>    - echo &quot;Building the application...&quot;<br><br>test-job:<br>  stage: test<br>  script:<br>    - echo &quot;Running tests...&quot;<br><br>deploy-job:<br>  stage: deploy<br>  script:<br>    - echo &quot;Deploying the application...&quot;</pre><p><strong>2. Using </strong><strong>include to Modularize Configurations</strong></p><p>Allows splitting configurations into multiple files and including them in the main .gitlab-ci.yml file. Useful for managing large projects, reusing configurations, and keeping the main file clean.</p><p>Example:</p><pre>include:<br>  - local: &#39;ci/build.yml&#39;<br>  - remote: &#39;https://example.com/path/to/config.yml&#39;<br>  - template: &#39;Security/SAST.gitlab-ci.yml&#39;<br>  - project: &#39;ci/pipeline&#39;<br>    ref: &#39;branch&#39;<br>    file: &#39;pipeline.yml&#39;</pre><p>Types of include:</p><ul><li><strong>Local</strong>: Includes another YAML file from the same repository.</li><li><strong>Remote</strong>: Includes an external YAML file from a URL.</li><li><strong>Template</strong>: Includes predefined GitLab CI/CD templates.</li><li><strong>Project</strong>: Includes existing pipeline in another project</li></ul><p><strong>3. Project-Level CI/CD Configuration in GitLab UI</strong></p><ul><li>Instead of storing .gitlab-ci.yml in the repository, you can define CI/CD configuration <strong>directly in GitLab UI</strong>.</li><li>Navigate to <strong>Project → Settings → CI/CD → Pipeline Editor</strong> and enter the pipeline configuration.</li><li>Useful when testing quick changes or for projects without a repository-based CI/CD file.</li></ul><p><strong>4. Project-Level CI/CD Configuration in GitLab UI</strong></p><ul><li>Last option is to mention it using a built-in variable named CI_CONFIG_PATH</li></ul><pre>CI_CONFIG_PATH=.gitlab/ci/custom-ci.yml</pre><p>These three methods provide flexibility in managing GitLab CI/CD pipelines based on project needs and administrative control.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e485a3f88874" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Compose For Keycloak]]></title>
            <link>https://anju-chaurasiya2012.medium.com/docker-compose-for-keycloak-c089cfe7cf05?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/c089cfe7cf05</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Wed, 12 Mar 2025 11:53:58 GMT</pubDate>
            <atom:updated>2025-03-12T11:53:58.075Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker Compose simplifies the management of multi-container applications by defining and running services in a single configuration file. In this blog, we’ll explore how to use Docker Compose to set up multiple Keycloak authentication servers using the provided docker-compose.yml configuration.</p><h3>What is Docker Compose?</h3><p>Docker Compose is a tool that helps define and run multi-container Docker applications. Instead of running multiple docker run commands, you can specify your services, networks, and volumes in a docker-compose.yml file and launch them with a single command: docker-compose up.</p><h3>Breakdown of the Docker Compose Configuration</h3><p>The provided docker-compose.yml file defines two Keycloak authentication servers:</p><ol><li><strong>my-auth-server</strong>: Runs a Keycloak instance accessible on port 8180.</li><li><strong>external-auth-server</strong>: Another Keycloak instance, accessible on port 8280.</li><li><strong>internal network</strong>: Ensures both services can communicate securely.</li></ol><h3>The docker-compose.yml File Explained</h3><pre>version: &#39;3.3&#39;<br>services:<br>  my-auth-server:<br>    image: &quot;quay.io/keycloak/keycloak:25.0&quot;<br>    command: start-dev<br>    networks:<br>      internal:<br>    extra_hosts:<br>      my.auth.com: 127.0.0.1<br>      external.auth.com: 127.0.0.1<br>    ports:<br>      - &quot;8180:8080&quot;<br>    volumes:<br>      - ./realms:/tmp/realms<br>    environment:<br>      KEYCLOAK_ADMIN: admin<br>      KEYCLOAK_ADMIN_PASSWORD: admin<br>      # KEYCLOAK_IMPORT: /tmp/realms/my_auth_realm.json<br>  <br>  external-auth-server:<br>    image: &quot;quay.io/keycloak/keycloak:25.0&quot;<br>    command: start-dev<br>    ports:<br>      - &quot;8280:8080&quot;<br>    volumes:<br>      - ./realms:/tmp/realms<br>    environment:<br>      KEYCLOAK_ADMIN: admin<br>      KEYCLOAK_ADMIN_PASSWORD: admin<br>      # KEYCLOAK_IMPORT: /tmp/realms/external_auth_realm.json<br>    networks:<br>      internal:<br>    extra_hosts:<br>      my.auth.com: 127.0.0.1<br>      external.auth.com: 127.0.0.1</pre><pre>networks:<br>  internal:</pre><h3>Key Components Explained</h3><h4>1. Services</h4><p>Each Keycloak server is defined as a service inside Docker Compose:</p><ul><li><strong>my-auth-server</strong> runs on port 8180.</li><li><strong>external-auth-server</strong> runs on port 8280.</li><li>Both services use the Keycloak image quay.io/keycloak/keycloak:25.0.</li><li>The command start-dev starts the Keycloak instance in development mode.</li></ul><h4>2. Networks</h4><p>A custom network (internal) is created to allow seamless communication between the two authentication servers without exposing them unnecessarily.</p><h4>3. Extra Hosts</h4><p>The extra_hosts section maps domain names (my.auth.com and external.auth.com) to 127.0.0.1, enabling host-based routing for authentication.</p><h4>4. Environment Variables</h4><p>Each Keycloak container is initialized with admin credentials:</p><ul><li>KEYCLOAK_ADMIN: Defines the default admin username (admin).</li><li>KEYCLOAK_ADMIN_PASSWORD: Sets the default admin password (admin).</li><li>KEYCLOAK_IMPORT: (Commented out) Specifies an optional JSON file for preloading realm configurations.</li></ul><h4>5. Volumes</h4><ul><li>The volume mapping ./realms:/tmp/realms ensures that Keycloak realms are persisted across container restarts, allowing seamless configuration loading.</li></ul><h4><strong>Update the hosts file:</strong></h4><pre>$ cat /etc/hosts        <br>#<br># Host Database<br>#<br># localhost is used to configure the loopback interface<br># when the system is booting.  Do not change this entry.<br>##<br>127.0.0.1 localhost<br>255.255.255.255 broadcasthost<br>::1             localhost<br># keycloak example<br>127.0.0.1 external.auth.com my.auth.com</pre><h3>Running the Setup</h3><p>To start the authentication servers, run the following command in the directory containing docker-compose.yml:</p><pre>docker-compose up -d</pre><ul><li>The -d flag runs the services in detached mode (background).</li><li>Once started, Keycloak will be available at:</li><li>http://localhost:8180 (for my-auth-server)</li><li>http://localhost:8280 (for external-auth-server)</li></ul><p>To stop and remove the containers, use:</p><pre>docker-compose down</pre><h3>Conclusion</h3><p>Using Docker Compose, we efficiently manage multiple Keycloak authentication servers with isolated networks and persistent configurations. This setup is particularly useful for testing different authentication realms and user management strategies.</p><p>By leveraging Compose, we reduce manual configuration overhead and improve maintainability in multi-container environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c089cfe7cf05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitLab Services in CI/CD Pipelines]]></title>
            <link>https://anju-chaurasiya2012.medium.com/gitlab-services-in-ci-cd-pipelines-a1f16764e047?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1f16764e047</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[multiple-images]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 09:13:42 GMT</pubDate>
            <atom:updated>2025-03-11T09:13:42.769Z</atom:updated>
            <content:encoded><![CDATA[<p>GitLab CI/CD allows users to run automated pipelines to build, test, and deploy applications. One of the key features of GitLab CI/CD is <strong>services</strong>, which enable running additional containers that support the main job execution. Services are commonly used to set up databases, caching layers, or other dependent services needed for tests and builds.</p><p>This blog post explains how GitLab services work with an example snippet and demonstrates practical use cases.</p><h4>What Are GitLab Services?</h4><p>In GitLab CI/CD, <strong>services</strong> are additional Docker containers that run alongside the primary job container. These containers provide dependencies such as databases, configuration servers, or message queues.</p><p>Services are especially useful when:</p><ul><li>Running integration tests that require external services.</li><li>Setting up dependencies like databases, config servers, or caching layers.</li><li>Ensuring test environments closely resemble production setups.</li></ul><h4>Example: Using a Spring Cloud Config Server as a Service</h4><p>Let’s break down the example GitLab CI/CD configuration snippet you provided:</p><pre>.config-vars:<br>  services:<br>    - name: hyness/spring-cloud-config-server:4.1-jre17<br>      alias: localhost  <br>  before_script:<br>    - set -o allexport<br>    - source .env<br>    - set +o allexport<br>    - echo &quot;Environment variables successfully set&quot;  <br>    - echo &quot;Waiting for config server to be ready...&quot;<br>    - timeout 30 bash -c &#39;until curl -s &quot;http://localhost:8888/actuator/health&quot; | grep UP; do sleep 5; done&#39; || echo &quot;Service not reachable&quot;<br>    - export SPRING_CLOUD_CONFIG_URI=http://localhost:8888/</pre><h4><strong>Defining Services</strong></h4><pre>services:<br>  - name: hyness/spring-cloud-config-server:4.1-jre17<br>    alias: localhost </pre><ul><li>Here, the hyness/spring-cloud-config-server:4.1-jre17 image is used as a service.</li><li>The alias localhost allows referencing this service using <a href="http://localhost:8888/">http://localhost:8888/.</a></li></ul><ol><li><strong>Setting Environment Variables</strong></li></ol><pre>before_script:<br>  - set -o allexport<br>  - source .env<br>  - set +o allexport</pre><p><em>This snippet loads environment variables from an </em><em>.env file, making them available in the job.</em></p><p><strong>2. Waiting for the Service to Start</strong></p><pre>- echo &quot;Waiting for config server to be ready...&quot;<br>- timeout 30 bash -c &#39;until curl -s &quot;http://localhost:8888/actuator/health&quot; | grep UP; do sleep 5; done&#39; || echo &quot;Service not reachable&quot;</pre><p><em>The script continuously checks whether the config server is running. If the server is </em><em>UP, the job continues; otherwise, it prints a failure message after 30 seconds.</em></p><p><strong>3. Exporting the Config Server URL</strong></p><pre>- export SPRING_CLOUD_CONFIG_URI=http://localhost:8888/</pre><p><em>This ensures that the application can access the configuration server by setting the appropriate environment variable.</em></p><p>4. <strong>Running Multiple Services</strong></p><p>If your application depends on multiple services, you can define them under services:</p><pre>services:<br>  - name: postgres:13<br>    alias: db<br>  - name: redis:latest<br>    alias: cache</pre><p>This ensures that both PostgreSQL and Redis are available for your pipeline.</p><p>5. <strong>Using a Custom Docker Network</strong></p><p>To improve communication between services, you can define a custom Docker network:</p><pre>variables:<br>  DOCKER_DRIVER: overlay<br>services:<br>  - name: mysql:latest<br>    alias: mysql_db<br>    command: [&quot;--default-authentication-plugin=mysql_native_password&quot;]<br>  - name: rabbitmq:3-management<br>    alias: rabbit<br>    variables:<br>      RABBITMQ_DEFAULT_USER: user<br>      RABBITMQ_DEFAULT_PASS: password</pre><p>6. <strong>Running Integration Tests with Services</strong></p><p>If you need to run integration tests with services, use needs to ensure proper sequencing:</p><pre>stages:<br>  - build<br>  - test</pre><pre>build-job:<br>  stage: build<br>  script:<br>    - echo &quot;Building application...&quot;</pre><pre>integration-tests:<br>  stage: test<br>  services:<br>    - name: mongo:latest<br>      alias: mongo_db<br>  script:<br>    - echo &quot;Running tests against MongoDB...&quot;<br>  needs: [build-job]</pre><h4>Benefits of Using Services in GitLab CI/CD</h4><ul><li><strong>Isolation</strong>: Each service runs in its own container, ensuring a clean test environment.</li><li><strong>Reproducibility</strong>: CI/CD pipelines remain consistent since services are always started with predefined configurations.</li><li><strong>Ease of Setup</strong>: Services eliminate the need for complex installation scripts by pulling ready-to-use Docker images.</li></ul><h3>Conclusion</h3><p>GitLab services are an essential tool in CI/CD pipelines, enabling dependency management with minimal effort. Whether integrating a configuration server, database, or caching layer, services ensure that your CI/CD environment closely mirrors production. By leveraging GitLab services, teams can build more robust and reliable pipelines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1f16764e047" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heredocs in Bash Scripting]]></title>
            <link>https://anju-chaurasiya2012.medium.com/heredocs-in-bash-scripting-5f4d8b7589d1?source=rss-9a06aa352229------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f4d8b7589d1</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[bash-scripting]]></category>
            <category><![CDATA[heredoc]]></category>
            <dc:creator><![CDATA[Anju]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 06:58:07 GMT</pubDate>
            <atom:updated>2025-03-11T06:58:07.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyoCR00KWx8vefQtBc2Ypw.png" /></figure><p>Heredocs (short for “here documents”) are a powerful feature in Bash that allows multi-line input redirection into a command or script. They simplify working with large text blocks, making scripting more readable and efficient. This blog post explains what heredocs are, how they work, and when to use them.</p><h3>What is a Heredoc?</h3><p>A heredoc is a form of input redirection in Bash that allows inserting multiple lines of text into a command without requiring multiple echo statements. It is typically used for embedding structured content in scripts, such as configuration files, SQL queries, or help messages.</p><h4>Syntax of a Heredoc</h4><p>The basic syntax of a heredoc is:</p><pre>command &lt;&lt;DELIMITER<br>multiline text<br>DELIMITER</pre><ul><li>command is the command that will receive the input.</li><li>DELIMITER is a user-defined word (often EOF, but can be anything).</li><li>Everything between &lt;&lt;DELIMITER and the closing DELIMITER is considered input for the command.</li></ul><h4>Example 1: Basic Heredoc with cat</h4><pre>cat &lt;&lt;EOF<br>This is a multiline string.<br>It is being printed using a heredoc.<br>EOF</pre><p><strong>Output:</strong></p><pre>This is a multiline string.<br>It is being printed using a heredoc.</pre><h3>Practical Use Cases of Heredocs</h3><h4>1. Writing to a File</h4><p>Instead of using multiple echo statements, you can use a heredoc to create or overwrite files.</p><pre>cat &lt;&lt;EOF &gt; myfile.txt<br>This is line 1.<br>This is line 2.<br>EOF</pre><h4>2. Using Heredoc in Scripts</h4><p>Heredocs can be used to provide interactive prompts or messages in scripts.</p><pre>#!/bin/bash<br>cat &lt;&lt;END<br>Welcome to the Bash Scripting Guide!<br>Choose an option:<br>1. Start<br>2. Help<br>3. Exit<br>END</pre><h4>3. Passing Input to Commands (e.g., SQL Queries)</h4><p>Heredocs can be used to pass multiple lines of input to a command, such as an SQL client.</p><pre>mysql -u root -p mydatabase &lt;&lt;SQL<br>SELECT * FROM users;<br>SQL</pre><h4>4. Using Variables in Heredocs</h4><p>By default, variables inside heredocs are expanded.</p><pre>name=&quot;John&quot;<br>cat &lt;&lt;EOF<br>Hello, $name!<br>EOF</pre><p><strong>Output:</strong></p><pre>Hello, John!</pre><h4>5. Preventing Variable Expansion</h4><p>If you want to prevent variables from being expanded, quote the delimiter.</p><pre>cat &lt;&lt;&#39;EOF&#39;<br>Hello, $name!<br>EOF</pre><p><strong>Output:</strong></p><pre>Hello, $name!</pre><h3>Heredoc vs. Here Strings</h3><p>A heredoc is often confused with a “here string” (&lt;&lt;&lt;). The main difference is that a heredoc is used for multi-line input, while a here string is for single-line input.</p><h4>Example of Here String:</h4><pre>cat &lt;&lt;&lt; &quot;This is a single-line input&quot;</pre><h3>Advanced Examples of Heredocs in Bash</h3><h4>1. Using Heredoc with SSH to Execute Remote Commands</h4><p>Heredocs are useful when executing multiple commands on a <strong>remote server via SSH</strong>.</p><pre>ssh user@remote_host &lt;&lt;EOF<br>echo &quot;Updating system...&quot;<br>sudo apt update &amp;&amp; sudo apt upgrade -y<br>echo &quot;System updated successfully!&quot;<br>EOF</pre><h4>2. Creating Configuration Files Dynamically</h4><pre>cat &lt;&lt;EOF &gt; /etc/myconfig.conf<br># Application Configuration<br>HOSTNAME=$(hostname)<br>PORT=8080<br>LOG_LEVEL=INFO<br>EOF</pre><h4>3. Passing Multi-line Input to a SQL Database</h4><pre>mysql -u root -p mydatabase &lt;&lt;EOF<br>CREATE TABLE users (<br>    id INT PRIMARY KEY AUTO_INCREMENT,<br>    name VARCHAR(100),<br>    email VARCHAR(100) UNIQUE<br>);<br>INSERT INTO users (name, email) VALUES (&#39;Alice&#39;, &#39;alice@example.com&#39;);<br>SELECT * FROM users;<br>EOF</pre><h4>4. Running Interactive Scripts</h4><pre>#!/bin/bash<br>python3 &lt;&lt;EOF<br>print(&quot;Enter your name:&quot;)<br>name = input()<br>print(f&quot;Hello, {name}!&quot;)<br>EOF</pre><h4>5. Using tee to Write to Multiple Files</h4><pre>tee file1.txt file2.txt &lt;&lt;EOF<br>This text will be written to multiple files.<br>EOF</pre><h4>6. Formatting Email Body with mail Command</h4><pre>mail -s &quot;Server Alert&quot; admin@example.com &lt;&lt;EOF<br>Dear Admin,</pre><pre>There was an unexpected error on the server.</pre><pre>Please check the logs immediately.</pre><pre>Best,<br>Your Server<br>EOF</pre><h4>7. Using Heredoc with docker exec</h4><pre>docker exec -i mycontainer bash &lt;&lt;EOF<br>echo &quot;Running inside Docker!&quot;<br>ls -l /app<br>EOF</pre><h4>8. Using heredoc for Multi-line Environment Variables</h4><pre>export CONFIGURATION=$(cat &lt;&lt;EOF<br>{<br>    &quot;host&quot;: &quot;localhost&quot;,<br>    &quot;port&quot;: 8080,<br>    &quot;database&quot;: &quot;mydb&quot;<br>}<br>EOF<br>)</pre><h4>9. Indenting Heredocs Properly with &lt;&lt;-</h4><pre>cat &lt;&lt;-EOF<br>    This is indented text.<br>    It remains properly formatted<br>    but ignores leading tabs.<br>EOF</pre><h4>10. Using Heredocs with sed for Inline Text Processing</h4><pre>sed -i &quot;/pattern_to_replace/ r /dev/stdin&quot; file.txt &lt;&lt;EOF<br>New line inserted after matching pattern.<br>EOF</pre><h3>Conclusion</h3><p>Heredocs are a great way to handle multi-line text in Bash scripts efficiently. They improve script readability and maintainability while reducing the need for multiple echo statements. Whether writing files, passing input to commands, or embedding structured data, heredocs are an essential tool for any Bash scripter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f4d8b7589d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>