<?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 Suraj Dev Anand on Medium]]></title>
        <description><![CDATA[Stories by Suraj Dev Anand on Medium]]></description>
        <link>https://medium.com/@suraj2001dev?source=rss-f837fa3655d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Wgx5fxPwtljUv6o37g98dw.jpeg</url>
            <title>Stories by Suraj Dev Anand on Medium</title>
            <link>https://medium.com/@suraj2001dev?source=rss-f837fa3655d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:28:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suraj2001dev/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[Introduction to Grafana Tanka for Kubernetes]]></title>
            <link>https://medium.com/@suraj2001dev/introduction-to-grafana-tanka-for-kubernetes-c8514ee47def?source=rss-f837fa3655d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8514ee47def</guid>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[otel]]></category>
            <dc:creator><![CDATA[Suraj Dev Anand]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 17:12:21 GMT</pubDate>
            <atom:updated>2026-10-31T17:17:09.864Z</atom:updated>
            <content:encoded><![CDATA[<p>短歌</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*VQPDK7Fh4cfO-CaK" /></figure><h3>Introduction</h3><p>If you’ve deployed anything to Kubernetes, you already know the drill: a Deployment YAML, a Service YAML, maybe a ConfigMap, and then you copy-paste the whole folder for staging, tweak a few lines, copy-paste again for prod, tweak a few more. It works, until the day you need to change one thing across all three environments and discover you have to hunt it down in three separate files that have quietly drifted apart.</p><p>At a recent <strong>Grafana and Friends Chennai</strong> session, I walked through an alternative: Grafana Labs’ own tool, Tanka, using Kubernetes itself as the example (the same approach applies whether you’re deploying a web app, an AI service, or anything else that needs to run the same way across multiple environments).</p><h3>Kubernetes, the intuitive way</h3><p>Before Tanka, it helps to picture Kubernetes itself simply. Think of it as an ocean, and your application as a container image sitting on land, outside the cluster.</p><p>A Deployment is the submarine that carries that image into the water. Once submerged, it doesn’t travel alone. It releases Pods, running instances of your image, and keeps the number of them steady.</p><p>But Pods are invisible from the surface. If you’re standing on land and want to reach them, you need a Service, which works like an echo locator: it finds the Pods and gives you one stable way to talk to them, even as individual Pods come and go.</p><p>And if you’re running more than one thing, you rope off sections of the ocean. That’s a namespace, the same cluster, same water, but separate zones so your ai-dev workloads and your ai-prod workloads never bump into each other.</p><p>Deployment, Service, namespace. That’s the whole picture. The question is how you write the configuration that creates them, and that’s where Helm and Tanka diverge.</p><h3>What Tanka does differently ?</h3><p>Rather than show this in the abstract, here’s a tiny, complete example.</p><h4>Prerequisites:</h4><p>Before working through the example below, you’ll need a few things installed:</p><ul><li><strong>Tanka</strong> (tk) — the CLI that evaluates your Jsonnet and talks to the cluster. On macOS: brew install tanka.</li><li><strong>jsonnet-bundler</strong> (jb) — Jsonnet’s dependency manager, used to pull in the Kubernetes helper library. On macOS: brew install jsonnet-bundler.</li><li><strong>kubectl</strong>, pointed at a cluster you can deploy to. A local one works fine for following along, <a href="https://kind.sigs.k8s.io/">kind</a> or <a href="https://minikube.sigs.k8s.io/">minikube</a> are the easiest ways to spin one up if you don’t already have something running.</li><li><strong>git</strong>, since the whole point of this example is a directory you can push and version.</li></ul><p>Confirm everything’s in place before moving on:</p><pre>tk --version<br>jb --version<br>kubectl version --client</pre><p><strong>1. Initialize the project and pull in a helper library</strong></p><pre>mkdir tanka-blog-example &amp;&amp; cd tanka-blog-example<br>jb init<br>jb install github.com/jsonnet-libs/k8s-libsonnet/1.33@main<br>mkdir -p lib environments/dev environments/prod</pre><p>jb init creates jsonnetfile.json, Jsonnet’s dependency list, and its presence is also how Tanka knows this is a project root. jb install downloads a Kubernetes helper library into vendor/ so you’re not hand-writing every field of a Deployment from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*sOBvPEAeGjnuFXz7XboFhw.png" /></figure><p><strong>2. Re-export the library under a short name</strong></p><p>Create lib/k.libsonnet:</p><pre>import &#39;github.com/jsonnet-libs/k8s-libsonnet/1.34/main.libsonnet&#39;</pre><p>Just one line, but it’s doing real work: every other file in the project imports &#39;k.libsonnet&#39; instead of that long path, so the library’s exact version lives in exactly one place.</p><p><strong>3. Write the shared function once</strong></p><p>Create lib/hello.libsonnet:</p><pre>local k = import &#39;k.libsonnet&#39;;<br><br>local deployment = k.apps.v1.deployment;<br>local container = k.core.v1.container;<br>local port = k.core.v1.containerPort;<br>local service = k.core.v1.service;<br><br>local defaults = {<br>  name: &#39;hello&#39;,<br>  image: &#39;nginx:1.27-alpine&#39;,<br>  replicas: 1,<br>  port: 80,<br>};<br><br>{<br>  new(config={})::<br>    local c = defaults + config;<br>    {<br>      deployment: deployment.new(<br>        name=c.name,<br>        replicas=c.replicas,<br>        containers=[<br>          container.new(c.name, c.image)<br>          + container.withPorts([port.new(c.port)]),<br>        ],<br>      ),<br>      service: service.new(<br>        c.name,<br>        { name: c.name },<br>        [{ port: c.port, targetPort: c.port }],<br>      ),<br>    },<br>}</pre><p>defaults plays the role Helm’s values.yaml plays. new(config={}) is a function: the double colon :: hides it so it doesn’t leak into the output, and local c = defaults + config merges your overrides on top of the defaults, whatever you pass wins, everything else keeps its default.</p><p><strong>4. Point two environments at it</strong></p><p>environments/dev/spec.json and environments/prod/spec.json each declare their own cluster context and namespace:</p><p><strong>environments/dev/spec.json</strong></p><pre>{<br>  &quot;apiVersion&quot;: &quot;tanka.dev/v1alpha1&quot;,<br>  &quot;kind&quot;: &quot;Environment&quot;,<br>  &quot;metadata&quot;: { &quot;name&quot;: &quot;environments/dev&quot; },<br>  &quot;spec&quot;: {<br>    &quot;contextNames&quot;: [&quot;kind-grafana-demo&quot;],<br>    &quot;namespace&quot;: &quot;ai-dev&quot;<br>  }<br>}</pre><p><strong>environments/prod/spec.json</strong></p><pre>{<br>  &quot;apiVersion&quot;: &quot;tanka.dev/v1alpha1&quot;,<br>  &quot;kind&quot;: &quot;Environment&quot;,<br>  &quot;metadata&quot;: { &quot;name&quot;: &quot;environments/prod&quot; },<br>  &quot;spec&quot;: {<br>    &quot;contextNames&quot;: [&quot;kind-grafana-demo&quot;],<br>    &quot;namespace&quot;: &quot;ai-prod&quot;<br>  }<br>}</pre><p>Then the environments call the shared function with different arguments:</p><p>Create environments/dev/main.jsonnet:</p><pre>// environments/dev/main.jsonnet<br>local hello = import &#39;hello.libsonnet&#39;;<br>hello.new({ replicas: 2 })</pre><p>Create environments/prod/main.jsonnet:</p><pre>// environments/prod/main.jsonnet<br>local hello = import &#39;hello.libsonnet&#39;;<br>hello.new({ replicas: 4, image: &#39;nginx:1.27-alpine&#39; })</pre><p><strong>5. Preview, then apply</strong></p><pre>tk show environments/dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HYQFFt9klAlAUJTu1xl4kA.png" /><figcaption>tk show environments/dev</figcaption></figure><pre>tk diff environments/dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3OcGRH5pBGULxM4vCbSUw.png" /><figcaption>tk diff environments/dev</figcaption></figure><pre>tk apply environments/dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjrxZTU3UM7vXSyjTR43uQ.png" /><figcaption>tk apply environments/dev</figcaption></figure><p>tk show prints the YAML with no cluster contact. tk diff compares it against what’s actually running. tk apply shows that same diff and asks you to confirm before touching anything.</p><p>Nothing in lib/hello.libsonnet changed between dev and prod. That’s the whole point: one function, two call sites, and the only thing that ever drifts is what you explicitly chose to override.</p><h3>Wrapping up</h3><p>The shift from Helm to Tanka isn’t really about syntax, YAML versus Jsonnet, it’s about whether your configuration is text you template or data you compute. Once it’s data, reuse stops being a copy-paste exercise and becomes an actual function call, and the small, honest tradeoff is that you’re trading a familiar templating language for one with a steeper, but shallower-in-the-end, learning curve.</p><p>If you want to see the full example from this post, the hello-world Deployment and Service, shared across dev and prod environments, it’s up on GitHub: <a href="https://github.com/Suraj01Dev/grafana_tanka_demo"><strong>github.com/Suraj01Dev/grafana_tanka_demo</strong></a>. Clone it, run through the prerequisites above, and tk apply it against your own cluster.</p><p>For everything beyond this one example, Tanka’s own docs are the best next stop: <a href="https://grafana.com/oss/tanka/"><strong>grafana.com/oss/tanka</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8514ee47def" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Control Plane You Didn’t Know You Needed]]></title>
            <link>https://medium.com/@suraj2001dev/the-control-plane-you-didnt-know-you-needed-0103b299278e?source=rss-f837fa3655d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/0103b299278e</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[paltform-engineering]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Suraj Dev Anand]]></dc:creator>
            <pubDate>Wed, 29 Jul 2026 18:01:35 GMT</pubDate>
            <atom:updated>2026-07-29T18:01:35.477Z</atom:updated>
            <content:encoded><![CDATA[<p>Achieving multitenancy in kubernetes using KCP with AWS ACK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBtslY2_ItU_yWCFBlHCng.png" /></figure><h3>Introduction</h3><p>Kubernetes is a great tool for building systems that are scalable, reliable, and maintainable. One problem, however, is its lack of built-in multitenancy support which is exactly what this blog is about.</p><p>Multitenancy can be achieved in Kubernetes using namespaces, RBAC, and network policies. But as teams grow, this approach becomes increasingly difficult to manage. A single misconfigured policy can compromise the entire system, and the blast radius of a mistake is never truly contained.</p><p>What if there was a way to implement multitenancy at the API level itself where each team gets their own isolated API surface, not just a fenced-off corner of a shared one? That’s what we’ll be exploring today.</p><h3>What is KCP ?</h3><p>KCP stands for Kubernetes Control Plane, a CNCF sandbox project. It is a control plane built around Kubernetes-style APIs, but without the nodes, pods, or workloads that come with a typical cluster.</p><p>The core idea is simple: instead of spinning up a full cluster for every team, KCP lets you create multiple logical clusters on one process. Each logical cluster gets its own URL and behaves like a real cluster from the outside. In KCP, these logical clusters are called workspaces.</p><p>Theory only gets you so far. Let’s build something.</p><p>Let’s get started with the practical implementation by cloning the repository below.</p><pre>git clone https://github.com/Suraj01Dev/kcp_aws_ack_implementation.git</pre><p>Once cloned, run the install script to pull down all the binaries needed for this implementation.</p><pre>bash prerequisites/install.sh</pre><p>This drops everything into a bin folder inside the repo. No system-wide installs, no PATH conflicts.</p><p>Now spin up a terminal and run the following from the root of the repo. We will be hopping between terminal tabs throughout this implementation, so keep track of which tab you are in.</p><p><strong>Terminal 1</strong></p><p>Set up the environment variables and start KCP.</p><pre>export KUBECONFIGS_DIR=&quot;kubeconfigs&quot;<br>export PATH=&quot;bin:${PATH}&quot;<br>mkdir -p $KUBECONFIGS_DIR</pre><pre>kcp start</pre><p>KCP is now running. Leave this terminal alone and open a new tab.</p><p><strong>Terminal 2</strong></p><p>Export the environment variables again in the new tab.</p><pre>export KUBECONFIGS_DIR=&quot;kubeconfigs&quot;<br>export KREW_ROOT=&quot;./bin/.krew&quot;<br>export PATH=&quot;./bin/.krew/bin:./bin:${PATH}&quot;</pre><p>Install the KCP kubectl plugins.</p><pre>kubectl krew index add kcp-dev https://github.com/kcp-dev/krew-index.git<br>kubectl krew install kcp-dev/kcp<br>kubectl krew install kcp-dev/ws<br>kubectl krew install kcp-dev/create-workspace<br>cp $(which kubectl-create_workspace) $KREW_ROOT/bin/kubectl-create-workspace</pre><p>When KCP starts, it creates a .kcp directory containing the admin kubeconfig for the control plane. Point kubectl at it.</p><pre>export KUBECONFIG=&quot;.kcp/admin.kubeconfig&quot;<br>ln -s $KUBECONFIG $KUBECONFIGS_DIR/admin.kubeconfig 2&gt;/dev/null || true<br>kubectl version<br></pre><p>Now we have everything setup let’s explore KCP workspaces. Below image is the setup that we are going to replicate in KCP, let’s get started with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3lRx4ytsXepPRVOFtkv5Q.png" /></figure><p>Verify you are connected to the KCP control plane.</p><pre>kubectl ws .</pre><p>This should return root as the current workspace. Root is the default entry point in KCP, and everything else in the workspace tree lives under it.</p><p>Now create the providers and consumers workspaces under root.</p><pre>kubectl create workspace providers<br>kubectl create workspace consumers</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1pyVrgOudno1GQ5wFAw9A.png" /></figure><p>List the workspaces to see what was created.</p><pre>kubectl get workspaces</pre><p>Notice the output. Each workspace has its own cluster URL, for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1qNV4zpEDIJOEo_JCC_8fA.png" /></figure><p><strong>This is the key point. Each workspace is not just a label or a namespace. It is a fully independent API endpoint. Hand someone a kubeconfig pointing at </strong><strong>root:consumers and they cannot reach </strong><strong>root:providers at all. That is API level isolation, something namespaces in standard Kubernetes cannot give you.</strong></p><p>Now let’s create nested workspaces under providers and consumers.</p><pre>kubectl ws use providers<br>kubectl create workspace storage<br>kubectl create workspace compute</pre><p>Move back to root.</p><pre>kubectl ws ..</pre><p>Now do the same under consumers.</p><pre>kubectl ws use consumers<br>kubectl create workspace team-a<br>kubectl create workspace team-b</pre><p>Go back to root and check the full workspace tree.</p><pre>kubectl ws ..<br>kubectl ws tree</pre><p>You should see something like this:</p><pre>.<br>└── root<br>    ├── consumers<br>    │   ├── team-a<br>    │   └── team-b<br>    └── providers<br>        ├── compute<br>        └── storage</pre><p>Now let’s prove that the isolation is real, not just cosmetic.</p><p>Navigate to team-a and create a ConfigMap.</p><pre>kubectl ws use consumers:team-a<br>kubectl create configmap test --from-literal=test=one</pre><p>Now switch to team-b and try to list ConfigMaps.</p><pre>kubectl ws use consumers:team-b<br>kubectl get cm</pre><p>The ConfigMap created in team-a is nowhere to be found. That is not RBAC doing the work. There is no policy blocking team-b from seeing it. The two workspaces simply have no shared state at all. They are different clusters as far as the API is concerned.</p><p>This is the difference between namespace isolation and workspace isolation. With namespaces, the data lives in the same etcd, the same API server responds to both, and a misconfigured RBAC rule can leak resources across tenants. With workspaces, team-a and team-b talk to different API endpoints entirely. There is nothing to leak.</p><p><strong>The problem</strong></p><p>This all works well for API level isolation. But KCP does not run workloads. No pods, no nodes, no controllers. So if team-a creates a resource in their workspace, nothing actually happens with it. The resource just sits there.</p><p>To make workspaces useful for real infrastructure, we need to connect KCP to a real Kubernetes cluster where controllers can actually run and do things. That is exactly what we will set up next.</p><h3>Problem Statement</h3><p>team-a is the storage team. They only need access to S3 buckets on AWS, nothing else.</p><p>The challenge is that in a standard Kubernetes setup, giving them access to the ACK S3 controller means giving them access to the entire cluster. Every CRD, every resource, every other team’s workloads are potentially visible.</p><p>We want team-a to have exactly one API: the Bucket resource. Their own cluster URL, their own isolated workspace, and nothing outside of it. Let&#39;s build that.</p><h3><strong>Solution</strong></h3><p>The goal is straightforward: give team-a access to only the S3 Bucket API, backed by a real ACK controller running in a separate Kubernetes cluster. Let&#39;s build it piece by piece.</p><p><strong>Setting up the Kubernetes cluster and ACK</strong></p><p>Open a new terminal tab.</p><p><strong>Terminal 3</strong></p><pre>export KUBECONFIGS_DIR=&quot;kubeconfigs&quot;<br>export PATH=&quot;bin:${PATH}&quot;</pre><p>Create a local Kubernetes cluster using kind. This is the provider cluster where the actual ACK controller and CRDs will live.</p><pre>kind create cluster --name provider --kubeconfig $KUBECONFIGS_DIR/provider.kubeconfig<br>export KUBECONFIG=$KUBECONFIGS_DIR/provider.kubeconfig</pre><p>Now install the ACK S3 controller into the provider cluster. ACK (AWS Controllers for Kubernetes) is what actually talks to AWS on our behalf. When a Bucket object is created in Kubernetes, ACK picks it up and calls the real AWS S3 API.</p><pre>export SERVICE=s3<br>export AWS_REGION=us-east-1<br>export ACK_SYSTEM_NAMESPACE=ack-system<br>export RELEASE_VERSION=$(curl -sL \<br>  https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest \<br>  | jq -r &#39;.tag_name | ltrimstr(&quot;v&quot;)&#39;)</pre><p>These variables tell Helm which ACK controller to install and where. RELEASE_VERSION is fetched dynamically from the GitHub API so you always get the latest stable release.</p><p>Log into the AWS ECR public registry. ACK Helm charts are hosted there.</p><pre>aws ecr-public get-login-password --region us-east-1 \<br>  | helm registry login --username AWS --password-stdin public.ecr.aws</pre><p>Install the ACK S3 controller via Helm.</p><pre>helm install --create-namespace \<br>  -n $ACK_SYSTEM_NAMESPACE \<br>  ack-$SERVICE-controller \<br>  oci://public.ecr.aws/aws-controllers-k8s/$SERVICE-chart \<br>  --version=$RELEASE_VERSION \<br>  --set=aws.region=$AWS_REGION</pre><p>This installs the controller into the ack-system namespace and also registers the Bucket CRD into the cluster.</p><p>Now the ACK controller is running but it has no way to authenticate with AWS yet. Since this is a local kind cluster, there is no IAM role or IRSA available. We inject the credentials directly as environment variables into the controller deployment.</p><p>First, find the actual deployment name since Helm names it using both the release name and chart name combined.</p><pre>kubectl -n ack-system get deployments</pre><p>Inject the AWS credentials.</p><pre>kubectl -n ack-system set env deployment/ack-s3-controller-s3-chart \<br>  AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id) \<br>  AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key) \<br>  AWS_REGION=$AWS_REGION</pre><p>Wait for the controller to restart with the new credentials and confirm it is running.</p><pre>kubectl -n ack-system rollout status deployment/ack-s3-controller-s3-chart<br>kubectl -n ack-system get pods</pre><p>At this point the provider cluster is ready. It has the ACK S3 controller running, the Bucket CRD installed, and valid AWS credentials injected. The next step is connecting this cluster to KCP so that team-a can provision S3 buckets from their own isolated workspace without ever touching this cluster directly.</p><p>Before doing that, let’s verify the bucket was actually created in AWS by checking the S3 console or running:</p><pre>aws s3 ls | grep kind-cluster-s3-demo-1</pre><p>You should see the bucket listed. This confirms ACK is talking to AWS correctly. Now delete this test bucket before moving on, since we will be creating buckets through KCP shortly.</p><pre>kubectl delete -f manifests/bucket.yaml</pre><p><strong>Connecting KCP with the provider cluster</strong></p><p>Now that the provider cluster is ready, let’s wire everything together. Switch back to Terminal 2.</p><p><strong>Terminal 2</strong></p><p>Go back to root and create a dedicated kubeconfig for the storage workspace. We keep this separate from the admin kubeconfig so the syncagent has a fixed context pointing at providers:storage.</p><pre>k ws :<br>cp .kcp/admin.kubeconfig $KUBECONFIGS_DIR/storage.kubeconfig<br>export KUBECONFIG=$KUBECONFIGS_DIR/storage.kubeconfig<br>kubectl ws use providers:storage</pre><p>Before connecting anything, take a look at what the provider cluster is exposing.</p><pre>kubectl api-resources | grep s3</pre><pre>buckets       s3.services.k8s.aws/v1alpha1      true         Bucket</pre><p>This is the API we want to make available in team-a&#39;s workspace. The plan is to publish it from the provider cluster into KCP&#39;s providers:storage workspace using an APIExport, and then let team-a bind to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhGea3d-ID86aK8oiyd4CA.png" /></figure><p>Create the APIExport in the storage workspace. This is a KCP native object that declares which API group this workspace is offering to consumers.</p><pre>kubectl apply -f manifests/export.yaml</pre><p>At this point the export exists but has no schema yet. The syncagent will fill that in once it connects.</p><p><strong>Terminal 4</strong></p><p>Open a new terminal tab and export the environment.</p><pre>export KUBECONFIGS_DIR=&quot;kubeconfigs&quot;<br>export KREW_ROOT=&quot;./bin/.krew&quot;<br>export PATH=&quot;./bin/.krew/bin:./bin:${PATH}&quot;<br>export KUBECONFIG=&quot;.kcp/admin.kubeconfig&quot;</pre><p>Navigate to team-a and bind the APIExport from the storage workspace.</p><pre>kubectl ws use consumers<br>kubectl ws use team-a<br>kubectl kcp bind apiexport root:providers:storage:s3.services.k8s.aws</pre><p>This creates an APIBinding in team-a&#39;s workspace. From this point on, team-a will see the Bucket API as if it were native to their workspace. They have no idea it originates from the provider cluster.</p><p><strong>Terminal 3</strong></p><p>Now for the last piece. The syncagent is what physically bridges KCP and the provider cluster. Before running it, we need to tell the provider cluster what it is allowed to export. This is done using a KCP specific CRD called PublishedResource.</p><p>Install the PublishedResource CRD into the provider cluster.</p><pre>kubectl apply --server-side -f \<br>    https://raw.githubusercontent.com/kcp-dev/api-syncagent/refs/tags/v0.2.0/deploy/crd/kcp.io/syncagent.kcp.io_publishedresources.yaml</pre><p>Now create a PublishedResource object that tells the syncagent to expose the Bucket resource from the s3.services.k8s.aws API group.</p><pre>kubectl apply -f manifests/published_resources_bucket.yaml</pre><p>The naming.namespace field set to kcp-sync tells the syncagent to place all synced objects into a namespace called kcp-sync inside the provider cluster, keeping them isolated from everything else running there.</p><p><strong>Terminal 4</strong></p><p>Run the syncagent. It needs two connections simultaneously: one to the provider cluster via KUBECONFIG, and one to KCP via --kcp-kubeconfig.</p><pre>export KUBECONFIG=$KUBECONFIGS_DIR/provider.kubeconfig<br>KUBECONFIG=$KUBECONFIGS_DIR/provider.kubeconfig \<br>api-syncagent \<br>    --namespace default \<br>    --apiexport-ref s3.services.k8s.aws \<br>    --kcp-kubeconfig=$KUBECONFIGS_DIR/storage.kubeconfig</pre><p>When the syncagent starts, it reads the PublishedResource from the provider cluster, pulls the full schema from the Bucket CRD, generates an APIResourceSchema in KCP, and wires it into the APIExport. From this moment, the Bucket API is live in team-a&#39;s workspace.</p><p><strong>Creating a bucket from team-a</strong></p><p>Switch to Terminal 4 and navigate to team-a.</p><pre>export KUBECONFIG=&quot;.kcp/admin.kubeconfig&quot;<br>kubectl ws use consumers:team-a</pre><p>Apply the consumer bucket manifest.</p><pre>kubectl apply -f manifests/consumer-bucket.yaml</pre><p>Watch it sync.</p><pre>kubectl get bucket -w</pre><p>Within a few seconds the status updates. The syncagent picked up the object from KCP, created a copy in the provider cluster under the kcp-sync namespace, ACK saw it and called the AWS S3 API, and the status flowed back into team-a&#39;s workspace.</p><p>Verify the bucket exists in AWS.</p><pre>aws s3 ls | grep &lt;your-bucket-name&gt;</pre><p>team-a just created a real S3 bucket using nothing but kubectl apply against their own isolated workspace. They never touched the provider cluster. They never saw a single AWS credential. They did not even know ACK was involved. That is multitenancy at the API level.</p><h3><strong>Conclusion</strong></h3><p>We started with a real problem and built a real solution. team-a can now create S3 buckets using plain kubectl apply against their own workspace, without touching the provider cluster, without seeing AWS credentials, and without knowing ACK exists.</p><p>KCP is still a CNCF sandbox project and the API is evolving, but the idea is solid. If you are building a platform for multiple teams on Kubernetes, it is worth paying attention to. The days of choosing between a giant shared cluster with complex RBAC and one expensive cluster per team may have a third option now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0103b299278e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Practical Guide to AWS VPC Ingress Routing: Building a Network Inspection Lab]]></title>
            <link>https://medium.com/@suraj2001dev/a-practical-guide-to-aws-vpc-ingress-routing-building-a-network-inspection-lab-9824d68c9b23?source=rss-f837fa3655d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9824d68c9b23</guid>
            <category><![CDATA[aws-vpc]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-devops]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Suraj Dev Anand]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 15:59:33 GMT</pubDate>
            <atom:updated>2025-07-29T15:59:33.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcHwHr2r7zvY0G3waERBQw.jpeg" /></figure><p>In this blog, we will dwell into a simple project using the concept of “<strong>VPC Ingress Routing”</strong> and its use cases.</p><p>Visualising the Target Architecture, A high level view !</p><ol><li>A user initiates a HTTP request over the internet to a <strong>“Application Server”</strong></li><li>The request travels through the internet gateway attached in the VPC</li><li>The gateway route table attached to the internet gateway send the packets to a middle man the “<strong>Network Inspector</strong>”</li><li>Since it’s a simple demonstration of a concept the “<strong>Network Inspector</strong>” is not designed to perform any inspection, but just acts like a man in the middle</li><li>The “<strong>Network Inspector</strong>” then forward the traffic to the <strong>“Application Server”</strong></li></ol><h3>Building the Infrastructure</h3><p>Steps involved in the process :</p><ol><li><strong>Creating the VPC</strong></li></ol><p>Login into the AWS console, and create a VPC with the below spec.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_vmeO2_4Z0S2JvPj0DLmA.png" /><figcaption>VPC</figcaption></figure><p><strong>2. Creating/Attaching Internet Gateway</strong></p><p>Create a IGW and attach it to the above VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6E-0JBt7kKEsY2p-TFcM-w.png" /><figcaption>IGW</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*697MyriZD_ZFsELkRyr29w.png" /><figcaption>IGW Attach</figcaption></figure><p><strong>3. Creating Subnets</strong></p><p>Lets go ahead and create two subnets, one for our “<strong>Network Inspector</strong>” and other one for <strong>“Application Server”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhCEB8WfNtpV5UmRM0HY1Q.png" /><figcaption>Subnet 1</figcaption></figure><p>CIDR for Network Inspect Subnet is 10.0.1.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6GIXhQmLCJEjChJTJd4Jw.png" /><figcaption>Subnet 2</figcaption></figure><p>CIDR for APP Subnet is 10.0.2.0/24</p><p><strong>4. Configuring Route Tables</strong></p><p>For setting the <strong>“Application Server” </strong>and “<strong>Network Inspector</strong>” lets make both the subnets <strong>public</strong> temporarily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnPiXpVmV9lV56ae7hVrSA.png" /><figcaption>IGW Route Tables</figcaption></figure><p>To make it public lets allow all traffic that is 0.0.0.0/0 to the IGW. And this has to be done on both the default route tables of the subnets.</p><p><strong>5. Deploying “<em>Network Inspector</em>” and “<em>Application Server</em>”</strong></p><p>Now lets go and deploy two instances both in “<strong><em>Network Inspect Subnet</em></strong>” and “<strong><em>APP Subnet</em></strong>”,</p><p><strong><em>Application Server Spec:</em></strong></p><ol><li>OS and Image</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*85W5Rt2yuPCujGVnjnpZFQ.png" /><figcaption>OS</figcaption></figure><p>2. Instance Type</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RajPcfQBaKBw4xttBaK67g.png" /></figure><p>3. VPC and Subnets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0AnjQLwrBJMkfeA6TkMMQ.png" /></figure><p><strong><em>Make sure to enable public ip !</em></strong></p><p>4. Firewall and SG</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5r9kJlBnPXHr2YRPnrJ4w.png" /></figure><p>Lets allow all traffic !</p><p><strong>6. Setting up the App Server</strong></p><p>Lets login into the app server using a terminal,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqj8N9tVQDBVhQ5mrIpxyQ.png" /></figure><p>Now let’s setup a simple <em>web server</em> on this instance</p><pre>#!/bin/bash<br>sudo yum update -y<br>sudo yum install -y httpd<br>sudo systemctl enable httpd<br>sudo systemctl start httpd<br><br># Create a simple index.html file<br>echo &quot;&lt;h1&gt;Hello from your Amazon Linux Webserver!&lt;/h1&gt;&lt;p&gt;Network inspector demo&lt;/p&gt;&quot; | sudo tee /var/www/html/index.html<br>sudo chown -R apache:apache /var/www/html<br>sudo chmod -R 755 /var/www/html<br><br>echo &quot;Webserver setup complete!&quot;</pre><p>Save the above script as <em>appserver.sh </em>and execute it using the below command</p><pre>bash appserver.sh</pre><p>This will start the web server, which can be accessed on the instance public IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9yt6FJX0C3qUeb66Bjvg-g.png" /><figcaption>Web Server Display</figcaption></figure><p><strong>7. Setting up the Network Inspector Server</strong></p><p>Follow the same process of step 5, except change the subnet to Network Inspector Subnet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K-Jil0B-lBwlnGslEVXeJg.png" /></figure><p>Let’s login into this instance and enable <strong>Kernel IP Forwarding,</strong></p><pre># Check the current status (will be 0)<br>sysctl net.ipv4.ip_forward<br><br># Enable IPv4 forwarding<br>sudo sysctl -w net.ipv4.ip_forward=1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOaldik3k4vNFKPb_XozWw.png" /></figure><p>To know more about Kernel IP Forwarding check this <a href="https://linuxconfig.org/how-to-turn-on-off-ip-forwarding-in-linux">reference</a>.</p><p>Let’s also enable to stop source destination check on this instance,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9VHbrkmV7We_fN66Qpl8Q.png" /></figure><p>To know more about source destination check refer this <a href="https://docs.aws.amazon.com/vpc/latest/userguide/work-with-nat-instances.html#EIP_Disable_SrcDestCheck">doc</a>.</p><p><strong>8. Setting up the Gateway Route Table</strong></p><p>In this section we will create a gateway route table, and also modify the existing routing configurations of our subnets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELf9fULaso3YUqAfrmd-kQ.png" /><figcaption>Gateway Route Table</figcaption></figure><p>After creating the gateway route table, it should not be attached to a subnet but attached to the IGW that we created, since this is going to route the traffic coming in via this IGW !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Y8UKkfh5JBM85iB_SmzWg.png" /></figure><p>Now lets set the rules for this gateway route table,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7Jxjky4RdGhG1aYfRRZig.png" /><figcaption>Process</figcaption></figure><p>The above diagram will give a clear understanding of what is happening behind the hood.</p><p>The incoming traffic must first reach Network inspector server before reaching APP server, lets set the rules keeping that in mind,</p><p>To forward all the traffic to network inspector server, we have set the below config</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7aibiQF8yYuUNH3qXSxoxA.png" /></figure><p>where the network interface is the eni of the Network Inspector Server and the destination is cidr block of APP subnet.</p><p>Before testing there is one more change we have to do APP server route table, we have forward all the traffic to the eni of the Network inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrmm0bEALXgwO92vSxztiA.png" /></figure><p>All traffic must pass through the network interface of Network Inspector.</p><p><strong>8. Testing</strong></p><p>Now that, we have setup the entire architecture, lets try accessing the web server running on the App Server, using the browser,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xStnAUQG1r7-4eSqCtJxxA.png" /></figure><p>We can also verify the flow of traffic through the network inspector using the below command</p><pre>sudo tcpdump -i ens5 -n &#39;port 80&#39;</pre><h3>Conclusion</h3><ul><li>The project effectively demonstrated how <strong>AWS VPC Ingress Routing</strong> can intercept and redirect internet traffic.</li><li>It successfully routed traffic through a “Network Inspector” instance before it reached the “Application Server” by using strategic route table configurations.</li><li>Completing the project provides valuable hands-on experience with a key AWS networking feature, enabling the creation of more secure and scalable cloud designs.</li></ul><h3>Future Ideas</h3><p>While this lab demonstrates the concept, its single “Network Inspector” is a point of failure and won’t scale.</p><p>For a production-ready solution that is both highly available and scalable, the next logical step is to use an <strong>AWS Gateway Load Balancer (GWLB)</strong>. It’s purpose-built to deploy, manage, and scale a fleet of virtual inspection appliances, making your architecture resilient and robust.</p><h3>References</h3><ul><li><a href="https://www.baeldung.com/linux/kernel-ip-forwarding">https://www.baeldung.com/linux/kernel-ip-forwarding</a></li><li><a href="https://aws.amazon.com/blogs/aws/new-vpc-ingress-routing-simplifying-integration-of-third-party-appliances/">https://aws.amazon.com/blogs/aws/new-vpc-ingress-routing-simplifying-integration-of-third-party-appliances/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9824d68c9b23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Jenkins Slave Container Node with Docker]]></title>
            <link>https://medium.com/@suraj2001dev/creating-a-jenkins-slave-container-node-with-docker-d0f79345ab1e?source=rss-f837fa3655d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0f79345ab1e</guid>
            <dc:creator><![CDATA[Suraj Dev Anand]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 02:16:08 GMT</pubDate>
            <atom:updated>2024-02-12T02:16:08.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*RoGnyGsIDpGwq5UCdHpWpg.png" /></figure><h3>Introduction</h3><p>This tutorial is about creating a Jenkins slave container with docker. The various advantages of creating a Jenkins slave container are as follows:</p><ul><li><strong>Scalability</strong><br>New slaves can be created based on different needs for the pipelines.</li><li><strong>Isolation<br></strong>Creating a separate Jenkins slave, rather than building it on the default Jenkins node helps prevent the misconfigurations in the default container.</li><li><strong>Declarative setup</strong><br>Specify dependencies and tools within the Docker image, streamlining setup and eliminating manual configuration.</li></ul><h3>Steps involved in this tutorial</h3><ul><li>Prerequisites</li><li>Setting up Jenkins</li><li>Setting a remote Jenkins Node with Docker</li><li>Connecting the Remote Node with Jenkins</li><li>Testing and Conclusion</li><li>References</li></ul><h3>Prerequisites</h3><ul><li>The host machine should have Linux based operating system.</li><li>The host machine should have Docker installed.</li></ul><h3>Setting up Jenkins</h3><h4>One of the easy ways to set up Jenkins is to spin up the <a href="https://hub.docker.com/r/jenkins/jenkins">Jenkins</a> Docker Container.</h4><pre>docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins</pre><ul><li>After running the above command the Jenkins container will start running. And the Jenkins initial setup password will appear in the logs, make sure to copy that. It can also be found inside the Jenkins container at /var/jenkins_home/secrets/initialAdminPassword</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*QOPGT6hoP7L602ozZ2XAQw.png" /><figcaption>Jenkins Logs Password</figcaption></figure><ul><li>Navigate to <a href="http://localhost:8080/">http://localhost:8080</a> where the Jenkins UI will be running.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*zarW01vSdN0qVs6ZWf4Lpw.png" /><figcaption>Jenkins Unlock Stage</figcaption></figure><p>Enter the saved password from the Jenkins Startup Logs into the <strong>Administrator password</strong> section in the Jenkins UI and click Continue.</p><ul><li>Click on <strong>Install suggested plugins</strong> in the next step.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoQ_e2IXv9vfR1cpKiF2yA.png" /><figcaption>Jenkins Plugins Stage</figcaption></figure><ul><li>Enter the required information to create an admin user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suiaipuusHAXHisUDrPXtw.png" /><figcaption>Jenkins Admin Stage</figcaption></figure><ul><li>Enter the Jenkins URL accordingly. And click on Save and Finish.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNgr3zR8_xxtnVk8cJ_mmA.png" /><figcaption>Jenkins URL Stage</figcaption></figure><p>We have successfully set up the Jenkins CI CD tool.</p><h3>Setting a remote Jenkins Node with Docker</h3><p>After running the Jenkins container, we will be building a pipeline in Jenkins to perform various jobs. By default, all the jobs and commands will be executed in the Jenkins Node itself. And this is not a good practice and it has its drawbacks like,</p><ul><li>Not having root permission to execute privileged commands.</li><li>Trouble installing new packages.</li><li>Risk of messing with the default Jenkins configuration, etc.</li></ul><p>Thus a better approach will be to set up a separate node to execute Jenkins’s jobs. And connect this node to Jenkins using SSH.</p><p>This new node should have the following requirements.</p><ul><li>There should be a user named jenkins.</li><li>Docker should be installed.</li><li>The user jenkins should be able to execute docker commands without sudo.</li><li>The node should have SSH enabled.</li></ul><p>One easy way to create this node is to spin up a Ubuntu container on the same network as the Jenkins container.</p><p>First, let&#39;s go ahead and create a docker network named jenkins.</p><pre>docker network create jenkins</pre><p>This will create a Docker bridge network named jenkins.</p><p>Since we already have the Jenkins container running, let&#39;s go ahead and connect the Jenkins container to this network.</p><p>First, let&#39;s find the container ID of the running Jenkins container.</p><pre>docker ps | grep jenkins/jenkins</pre><p>Execute the above command, and copy the first field which is the container ID.</p><p>To connect it to the network Jenkins, execute the below command.</p><pre>docker network connect jenkins &lt;container_id&gt;</pre><p>Now, let&#39;s go ahead and create the Remote Jenkins Node.</p><h4>Creating a Ubuntu container with Docker.</h4><p>Firstly let&#39;s spin up a Ubuntu container, by executing the below command.</p><pre>docker run -it --name jenkins-node --network jenkins -v /var/run/docker.sock:/var/run/docker.sock  ubuntu:20.04</pre><p>The above command does the following:</p><ul><li>Creates a docker Ubuntu container named Jenkins-node.</li><li>Connects it to the network, which we created earlier.</li><li><strong>Binds the host’s docker socket into the container’s docker socket, to run docker inside of docker.</strong></li></ul><p>Once executing the above command you will be logged into the Jenkins-node container as root.</p><p>Let&#39;s go ahead and install some necessary packages.</p><pre>apt update -y &amp;&amp; \<br>apt install vim sudo docker.io openssh-server openjdk-17-jdk -y</pre><p><strong>Execute the below command to verify that, we can access docker inside of docker.</strong></p><pre>docker -v</pre><p>Starting the ssh service.</p><pre>service ssh start</pre><p>Checking the SSH service status.</p><pre>service ssh status</pre><h4>Creating Jenkins user and SSH Configurations.</h4><p>Creating a jenkins user.</p><pre>useradd -m jenkins -s /bin/bash -G sudo,root</pre><p>Creating password for jenkins user.</p><pre>passwd jenkins</pre><h3>Connecting the Remote Node with Jenkins</h3><ul><li>Go to the Jenkins UI at http://localhost:8080</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zk4FXIXofRQdN9NVcjMJ9Q.png" /><figcaption>Jenkins UI</figcaption></figure><ul><li>Click on <strong>Manage Jenkins-&gt; Nodes</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3J3DN9S4HBxz8YCaV6nTlA.png" /><figcaption>Jenkins Manage Nodes</figcaption></figure><ul><li>Click on <strong>New Node</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RTDtF2cQ-oslNfVgO4zFXA.png" /><figcaption>Jenkins New Node</figcaption></figure><ul><li>Give a name for the <strong>Node name</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IiZlABNUlETm3DM2qiwXhA.png" /><figcaption>Jenkins Node Name</figcaption></figure><ul><li>Enter the details as follows</li><li>Remote root directory as /home/jenkins</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPW3ytNFlN2RqvGVtXHIpA.png" /><figcaption>Jenkins Details</figcaption></figure><ul><li>Select the launch method as Launch agents via SSH</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mnhbXOP52MkYSZhJcl33Uw.png" /><figcaption>Jenkins SSH</figcaption></figure><ul><li>Create Credentials with Kind <strong>Username with password</strong>, and enter the username as Jenkins and password for the same user, created earlier.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVx0hnYjPu-osd0sE6056Q.png" /><figcaption>Jenkins Credentials</figcaption></figure><ul><li>Click on save after the changes and relaunch the agent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mqlAN344pz6kaBxz4tXww.png" /><figcaption>Jenkins Relaunch</figcaption></figure><ul><li>We have successfully created a slave Jenkins node and connected it to Jenkins.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eyphqlN1EGsU3W_9B1u-Q.png" /><figcaption>Jenkins Final</figcaption></figure><h3>Testing and Conclusion</h3><p>Now let’s go ahead and test the setup, by running a free-style job.</p><p>Before that, we have to restrict the default Jenkins node to run the Jenkins Job, to do so navigate to <em>Dashboard → Manage Jenkins → Nodes -&gt; Built-in Node -&gt; Configure</em></p><p>And set the Number of executors to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CqFhoEI8inOPL-DRPzXiQ.png" /></figure><p>Now head back to <strong>Dashboard</strong> and click on <strong>New Item. </strong>Give a name to the free-style project and select <strong>Freestyle project.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdBYdqJOW4AR0YxQH9CA-Q.png" /></figure><p>Head to <strong>Dashboard -&gt; Project -&gt; Configuration.</strong></p><p>Under the build steps select Execute Shell and enter any bash command of your choice.</p><pre>echo &quot;Hello World&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klzz_xD-TLYHaqcjUpDMiQ.png" /></figure><p>and select save.</p><p>After saving the config click on Build Now to check the Console Output of the job that has been executed on the remote node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-li_mkeGAR2IReqrRsVsw.png" /></figure><p>From this we can conclude that the job has been executed on the remote node since we have restricted the job execution on the built-in node.</p><h3>References</h3><ul><li><a href="https://www.youtube.com/@DineshMistry"><strong>https://www.youtube.com/@DineshMistry</strong></a></li><li><a href="https://www.youtube.com/@JavaHomeCloud"><strong>https://www.youtube.com/@JavaHomeCloud</strong></a></li><li><a href="https://www.jenkins.io/doc/"><strong>https://www.jenkins.io/doc/</strong></a></li><li><a href="https://stackoverflow.com/questions/27879713/is-it-ok-to-run-docker-from-inside-docker"><strong>https://stackoverflow.com/questions/27879713/is-it-ok-to-run-docker-from-inside-docker</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0f79345ab1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Scraping Nifty 500 Key Financial Ratios using Python]]></title>
            <link>https://medium.com/@suraj2001dev/web-scraping-nifty-500-key-financial-ratios-using-python-6db7455e2fa8?source=rss-f837fa3655d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/6db7455e2fa8</guid>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[nifty]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[finance]]></category>
            <dc:creator><![CDATA[Suraj Dev Anand]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 00:51:02 GMT</pubDate>
            <atom:updated>2023-06-20T02:21:24.049Z</atom:updated>
            <content:encoded><![CDATA[<p>Scraping nifty 500 vital financial ratios for fundamental analysis.</p><figure><img alt="If your wondering why there is a bull picture, its because bull represent a positive growth in a stock market." src="https://cdn-images-1.medium.com/max/1024/1*eS285gvpbF05l0qW45vJfg.jpeg" /></figure><h3>Introduction</h3><p>The Nifty 500 is a list of the top 500 companies that shows the overall performance of the Indian market from different sectors. And the Nifty 500 index fund replicates the performance of the Nifty 500 companies. Thus investing in the nifty 500 indexes is similar to investing in the growth of the Indian market.</p><p>Although investing in the Nifty 500 index fund financial instrument is a great idea, it would be great to analyze and filter the stocks based on their financial ratios. Thus the major requirement in analyzing the stocks individually based on their financial ratios is a <strong>dataset</strong> will all the financial ratios of the 500 stocks over the past <strong>5 years</strong>.</p><p>The main aim of this blog post is to explain the project that was built to scrape the financial ratios of nifty 500 stocks.</p><h3>Steps involved in building the project</h3><ul><li>Planning the flow of scraping data.</li><li>Installing and importing necessary modules.</li><li>Coding the scraper</li><li>Running the scraper</li><li>Output</li><li>Summary</li><li>References</li></ul><h3>Planning the Flow of Scraping Data</h3><p>In this section, we will go through the <a href="http://www.moneycontrol.com/">www.moneycontrol.com</a> website and plan how to scrape the data.</p><p>Let us go ahead to the Money Control website of the nifty 500 index composition(Page 1). On this page, we get the list of all the nifty 500 stocks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qeTTMYrN5Y5BGn9Yf2uuWA.png" /><figcaption><a href="https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7">Page 1</a></figcaption></figure><p>By clicking the link for the individual stocks we get to page 2 where there is detailed information on the particular stock which is <strong>360 ONE WAM.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_SFMqplM4fMcIp6NTHNnQQ.png" /><figcaption><a href="https://www.moneycontrol.com/india/stockpricequote/finance-others/360onewam/IIFLW54277">Page 2</a></figcaption></figure><p>After reaching the second page and scrolling down quite a bit we get the link for the <strong>Financial Ratios </strong>under the <strong>FINANCIALS. </strong>Let&#39;s go to the 3 pages after clicking the ratios link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jz7UvxvpRXl8jvczFcY2Q.png" /><figcaption><a href="https://www.moneycontrol.com/financials/360onewam/ratiosVI/IIFLW54277#IIFLW54277">Page 3</a></figcaption></figure><p>On page 3 we get all the financial ratios of the stock. We have to perform the same steps for all the securities on page 1 to get the ratios. We will explore the various tags and elements that will help us in scraping the data in <strong>section 3</strong>.</p><h3>Installing and Importing Necessary Modules</h3><p>In this section, we will go through all the steps to set up and start the project.</p><ul><li>Make sure python3 is installed on the machine</li><li>Using Anaconda is a good practice for managing Python environments and isolating them from other environments</li><li>Installing scrapy web scraping framework for web scraping.</li></ul><p><strong>Let&#39;s execute the steps one by one.</strong></p><ul><li>Creating a new environment in Anaconda</li></ul><pre>conda create --name scrapeenv</pre><ul><li>Activating the <em>scrapeenv</em> environment using Anaconda.</li></ul><pre>conda activate scrapeenv</pre><ul><li>Installing the scrapy framework using pip3.</li></ul><pre>pip3 install scrapy</pre><ul><li>Starting a nifty500_scraper project using scrapy.</li></ul><pre>scrapy startproject nifty500_scraper</pre><ul><li>Let&#39;s go ahead and create a spider for crawling the web pages.</li></ul><pre>cd nifty500_scraper</pre><pre>scrapy genspider niftyspider https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7</pre><p>Opening the project in <strong>vs-code</strong> the structure of the directory will be similar to the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*wFoXuJHbGXvTG4uNHmhnsw.png" /><figcaption>Folder Structure</figcaption></figure><p>Let&#39;s move to the next section.</p><h3>Coding the Scraper</h3><ul><li>Let&#39;s open the <strong>niftyspider.py</strong> file.</li><li>Replace the start_url with the <a href="https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7">nifty 500 index composition</a> web page.</li></ul><pre>import scrapy<br><br><br>class NiftyspiderSpider(scrapy.Spider):<br>    name = &quot;niftyspider&quot;<br>    allowed_domains = [&quot;www.moneycontrol.com&quot;]<br>    start_urls = [&quot;https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7&quot;]<br><br>    def parse(self, response):<br>        pass</pre><ul><li>Inspecting the Index Composition page.</li></ul><p>Using the CSS selectors of the scrapy let&#39;s get the contents of the tr tags as stocks and store them in lists, using the below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0j6sYiAttqtWAVfhorDH6w.png" /><figcaption><a href="https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7">Inspecting Page 1</a></figcaption></figure><pre>import scrapy<br><br><br>class NiftyspiderSpider(scrapy.Spider):<br>    name = &quot;niftyspider&quot;<br>    allowed_domains = [&quot;www.moneycontrol.com&quot;]<br>    start_urls = [&quot;https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7&quot;]<br><br>    def parse(self, response):<br>        stocks=response.css(&#39;div.MT10 table.tbldata14 tr&#39;)<br>        stocks.pop(0)</pre><ul><li>Getting the link to <strong>page 2 </strong>from the contents of the tr tags that are stored in the stocks list.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0WUpIS-z0zsydAiGSLgYA.png" /><figcaption><a href="https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7">Inspecting Page 1</a></figcaption></figure><p>By iterating through each stock we get the <strong>td</strong> tag with class <strong>brdrgtgry </strong>using the scrapy’s css selector. And then the <strong>href</strong> tag which contains the link can be extracted using the<strong> tag.</strong></p><pre>import scrapy<br><br><br>class NiftyspiderSpider(scrapy.Spider):<br>    name = &quot;niftyspider&quot;<br>    allowed_domains = [&quot;www.moneycontrol.com&quot;]<br>    start_urls = [&quot;https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7&quot;]<br><br>    def parse(self, response):<br>        stocks=response.css(&#39;div.MT10 table.tbldata14 tr&#39;)<br>        stocks.pop(0)<br><br>        for stock in stocks:<br>            stock_link=&quot;moneycontrol.com&quot;+stock.css(&quot;td.brdrgtgry a&quot;)[0].attrib[&quot;href&quot;]<br>            yield response.follow(stock_link, callback=self.ratio_link_find)</pre><p>After getting the stock link, we can yield to use the callback function to follow the link of page 2 using the function <strong>ratio_link_find.</strong></p><ul><li>Building the function <strong>ratio_link_find</strong>. This function is to get the link of the ratios page to get to <strong>page 3</strong>.</li><li>Inspecting Page 2 for scraping the link for Page 3.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8SjvFtUMCox1A-lSJAaREA.png" /><figcaption><a href="https://www.moneycontrol.com/india/stockpricequote/finance-others/360onewam/IIFLW54277">Inspecting Page 2</a></figcaption></figure><p>We can get the link for page 3 by grabbing the below tags.</p><pre>response.css(&#39;div.financials_container div.sub2menu_content div.right_block div.quick_links li a&#39;)[7].attrib[&#39;href&#39;]</pre><ul><li><strong>ratio_link_find</strong> Function</li></ul><pre>def ratio_link_find(self,response):<br>    ratio_link=response.css(&#39;div.financials_container div.sub2menu_content div.right_block div.quick_links li a&#39;)[7].attrib[&#39;href&#39;]<br>    yield response.follow(ratio_link, callback=self.ratio_stat_find)</pre><ul><li>After getting the link we again yield a callback function <strong>ratio_stat_find.</strong></li><li>Building the <strong>final function</strong> ratio_stat_find to scrape the ratios of <strong>page 3</strong>.</li></ul><pre>def ratio_stat_find(self,response):<br>    ratios={}<br>    stock_name=response.css(&#39;h1.pcstname::text&#39;).get()<br>    stage1=response.css(&#39;table.mctable1  tr&#39;)<br>    stage2=stage1.css(&#39;tr&#39;)<br><br><br>    ratios[&#39;stock_name&#39;]=stock_name<br><br><br>    for ratio in stage2:<br>        <br>        un_class_name=ratio.css(&#39;tr&#39;).attrib[&#39;class&#39;]<br><br><br>        if un_class_name==&#39;lightbg&#39; or un_class_name==&#39;darkbg&#39;:<br>            continue<br>        else:<br>            values=ratio.css(&#39;td::text&#39;).getall()[:-1]<br><br>            ratio_name=values[0]<br>            for i in range(1,6):<br>                if i &lt;len(values):<br>                    ratios[ratio_name+&quot;_yr&quot;+str(i)]=values[i]<br>                else:<br>                    ratios[ratio_name+&quot;_yr&quot;+str(i)]=None<br><br>    yield ratios</pre><p>In the above function, we first declare a dictionary variable <strong>ratios.</strong></p><ul><li>Getting the stock name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2zZh9yvZ6gbQpxSkLWc_-A.png" /><figcaption><a href="https://www.moneycontrol.com/financials/360onewam/ratiosVI/IIFLW54277#IIFLW54277">Inspecting Page 3</a></figcaption></figure><pre>stock_name=response.css(&#39;h1.pcstname::text&#39;).get()</pre><ul><li>Finally grabbing the key financial ratios</li></ul><pre>  def ratio_stat_find(self,response):<br>      ratios={}<br>      stock_name=response.css(&#39;h1.pcstname::text&#39;).get()<br>      ratios[&#39;stock_name&#39;]=stock_name<br><br>      stage1=response.css(&#39;table.mctable1  tr&#39;)<br>      stage2=stage1.css(&#39;tr&#39;)<br><br>      for ratio in stage2:<br>          <br>          un_class_name=ratio.css(&#39;tr&#39;).attrib[&#39;class&#39;]<br><br><br>          if un_class_name==&#39;lightbg&#39; or un_class_name==&#39;darkbg&#39;:<br>              continue<br>          else:<br>              values=ratio.css(&#39;td::text&#39;).getall()[:-1]<br><br>              ratio_name=values[0]<br>              for i in range(1,6):<br>                  if i &lt;len(values):<br>                      ratios[ratio_name+&quot;_yr&quot;+str(i)]=values[i]<br>                  else:<br>                      ratios[ratio_name+&quot;_yr&quot;+str(i)]=None<br><br>      yield ratios</pre><p>In the above code, we first grab the table <strong>mctable1 </strong>and get the tag <strong>tr. </strong>Next, we iterate through the contents of the <strong>tr</strong> tag and grab all the ratios dynamically over the last 5 years.</p><h3>Entire Code</h3><pre>import scrapy<br><br><br>class NiftyspiderSpider(scrapy.Spider):<br>    name = &quot;niftyspider&quot;<br>    allowed_domains = [&quot;www.moneycontrol.com&quot;]<br>    start_urls = [&quot;https://www.moneycontrol.com/stocks/marketstats/indexcomp.php?optex=NSE&amp;opttopic=indexcomp&amp;index=7&quot;]<br><br>    def parse(self, response):<br>        stocks=response.css(&#39;div.MT10 table.tbldata14 tr&#39;)<br>        stocks.pop(0)<br><br>        for stock in stocks:<br>            stock_link=&quot;moneycontrol.com&quot;+stock.css(&quot;td.brdrgtgry a&quot;)[0].attrib[&quot;href&quot;]<br>            yield response.follow(stock_link, callback=self.ratio_link_find)<br><br>    def ratio_link_find(self,response):<br>        ratio_link=response.css(&#39;div.financials_container div.sub2menu_content div.right_block div.quick_links li a&#39;)[7].attrib[&#39;href&#39;]<br>        yield response.follow(ratio_link, callback=self.ratio_stat_find)<br><br>    def ratio_stat_find(self,response):<br>        ratios={}<br>        stock_name=response.css(&#39;h1.pcstname::text&#39;).get()<br>        ratios[&#39;stock_name&#39;]=stock_name<br><br>        stage1=response.css(&#39;table.mctable1  tr&#39;)<br>        stage2=stage1.css(&#39;tr&#39;)<br><br>        for ratio in stage2:<br>            <br>            un_class_name=ratio.css(&#39;tr&#39;).attrib[&#39;class&#39;]<br><br><br>            if un_class_name==&#39;lightbg&#39; or un_class_name==&#39;darkbg&#39;:<br>                continue<br>            else:<br>                values=ratio.css(&#39;td::text&#39;).getall()[:-1]<br><br>                ratio_name=values[0]<br>                for i in range(1,6):<br>                    if i &lt;len(values):<br>                        ratios[ratio_name+&quot;_yr&quot;+str(i)]=values[i]<br>                    else<br>                        ratios[ratio_name+&quot;_yr&quot;+str(i)]=None<br><br>        yield ratios</pre><h3><strong>Running the Scraper</strong></h3><pre>scrapy crawl niftyspider -o nifty500.csv</pre><h3><strong>Output</strong></h3><ul><li>The nifty500.csv file can be directly opened using a text editor to check the output</li><li>Another preferable method can be using a jupyter notebook, creating a .ipynb file, and pasting the following code.</li></ul><pre>import pandas as pd<br>df=pd.read_csv(&quot;nifty500.csv&quot;)<br>df</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdKTVe7krqxmWPasQGYrHA.png" /></figure><p><strong>The dataset has been submitted to </strong><a href="https://www.kaggle.com/datasets/surajdev2001/nifty-500-key-financial-ratios"><strong>Kaggle</strong></a><strong>.</strong></p><h3><strong>Summary</strong></h3><ul><li>Explored the money control website to use the right web pages to grab the required data</li><li>Installed the necessary modules and set the project for scraping</li><li>Coded the web scraper using scrapy by using various tags and functions.</li><li>After running the web scraper, the results were captured in the <strong>nifty500.csv </strong>file.</li><li>The entire project is available in this GitHub <a href="https://github.com/Suraj01Dev/Data-Science-Projects/tree/main/Web%20Scraping%20Projects/Scraping%20Nifty500%20Stocks">repository</a>.</li><li>The dataset can be accessed directly in <a href="https://www.kaggle.com/datasets/surajdev2001/nifty-500-key-financial-ratios"><strong>Kaggle</strong></a> for analysis.</li></ul><h3>References</h3><ul><li><a href="https://www.youtube.com/watch?v=mBoX_JCKZTE&amp;t=5491s">Scrapy tutorial 1</a></li><li><a href="https://www.youtube.com/watch?v=s4jtkzHhLzY&amp;t=72s">Scrapy tutorial 2</a></li><li><a href="https://www.geeksforgeeks.org/">Geek for Geeks</a></li><li><a href="https://scrapy.org/">Scrapy documentation</a></li><li><a href="https://docs.python.org/3/">Python documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6db7455e2fa8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>