<?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 Akshit Sadana on Medium]]></title>
        <description><![CDATA[Stories by Akshit Sadana on Medium]]></description>
        <link>https://medium.com/@akshitsadana?source=rss-363accb914ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*812YfzVK0LgQLs_7n6fdYA.jpeg</url>
            <title>Stories by Akshit Sadana on Medium</title>
            <link>https://medium.com/@akshitsadana?source=rss-363accb914ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:25:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshitsadana/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[Learn Terraform the Easy Way: A Beginner’s Guide to Provisioning Infrastructure]]></title>
            <link>https://akshitsadana.medium.com/learn-terraform-the-easy-way-a-beginners-guide-to-provisioning-infrastructure-9bd43b37695e?source=rss-363accb914ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bd43b37695e</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Akshit Sadana]]></dc:creator>
            <pubDate>Sat, 23 Nov 2024 11:21:31 GMT</pubDate>
            <atom:updated>2024-11-23T11:21:31.963Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMJqZYIYeh6tESBgRT22OA.png" /></figure><p><a href="https://www.terraform.io/">Terraform</a> is an open-source Infrastructure as Code (IaC) tool that allows you to define and provision infrastructure resources using declarative configuration files. With Terraform, you can automate the process of creating, updating, and managing infrastructure across a variety of cloud platforms (AWS, GCP, Azure, etc.) using simple code.</p><p>In this article, we’ll walk through how to quickly get started with Terraform and provision a virtual machine on Google Cloud Platform (GCP). We’ll focus on using the easiest approach for beginners — <strong>understanding GCP’s console options first and then mapping those directly to Terraform code</strong>. By the end, you’ll have a solid understanding of how to write Terraform code without getting overwhelmed by the complexity of the documentation.</p><h3>Prerequisites</h3><p>Before we start writing Terraform code, you’ll need to set up a few things:</p><ol><li><strong>Install Terraform CLI</strong>:</li></ol><p>Follow the official <a href="https://developer.hashicorp.com/terraform/install">Terraform installation guide</a> for your operating system.</p><ol><li><strong>Set up Google Cloud SDK</strong>:</li></ol><p>Install the <a href="https://cloud.google.com/sdk/docs/install-sdk">Google Cloud SDK</a> and authenticate your Google Cloud account by running:</p><pre># to initialise the sdk<br>gcloud init<br><br># to authorize the Terraform SDK to access GCP <br># using your user account credentials<br>gcloud auth application-default login</pre><p>Once you have Terraform and the GCP SDK installed, you’re ready to start provisioning infrastructure.</p><h3>Provisioning a Compute Instance on GCP Using Terraform</h3><p>Now, let’s dive into creating a GCP Compute Engine instance using Terraform. Here’s how to proceed:</p><h3>Step 1: Understanding GCP Console Options</h3><p>Before writing Terraform code, it’s helpful to use the GCP Console to understand what options you need for the virtual machine (VM). For example, when creating a Compute Engine instance, you’ll be prompted to set parameters like:</p><ul><li>Machine type (e.g., e2-medium)</li><li>OS image (e.g., ubuntu-2204-lts)</li><li>Region and Zone (e.g., us-central1-a)</li></ul><p>Take note of these settings as you’ll use them in the Terraform configuration.</p><h3>Step 2: Finding Equivalent Terraform Resources</h3><p>Instead of diving straight into the overwhelming Terraform documentation, follow this strategy:</p><ol><li>Open the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance">Terraform GCP provider documentation</a>.</li><li>Look for the resource type that matches what you’re trying to provision. In this case, it’s google_compute_instance.</li><li>Check the required parameters and see if they match the options you selected in the GCP Console.</li></ol><p>For example, if you choose an e2-medium machine in the GCP Console, you&#39;ll find the corresponding machine_type in Terraform as e2-medium. This process makes it much easier to map console options to Terraform code.</p><h3>Step 3: Writing the Terraform Code</h3><p>Now that you understand the GCP options, you can start writing the Terraform configuration. Here’s a minimal example to create a Compute Engine instance: Copy paste this code in any file extension .tf .</p><pre>provider &quot;google&quot; {<br>  project = &quot;gcp project id&quot;<br>  region  = &quot;gcp region&quot;<br>}<br><br>resource &quot;google_service_account&quot; &quot;default&quot; {<br>  account_id   = &quot;1234-sa&quot;<br>  display_name = &quot;11234 service account&quot;<br>}<br><br>resource &quot;google_compute_instance&quot; &quot;default&quot; {<br>  name         = &quot;instance name&quot;<br>  machine_type = &quot;e2-medium&quot;<br>  zone         = &quot;us-east1-b&quot;<br><br>  tags = [&quot;example tag&quot;]<br><br>  boot_disk {<br>    initialize_params {<br>      image = &quot;ubuntu-2004-lts&quot;<br>    }<br>  }<br><br>  network_interface {<br>    network = &quot;default&quot;<br><br>    access_config {<br>      network_tier = &quot;STANDARD&quot;<br>    }<br>  }<br><br>  metadata = {<br>    &quot;ssh-keys&quot; = &lt;&lt;EOT<br>      &lt;-- you SSH KEY --&gt;<br>    EOT<br>  }<br><br>  metadata_startup_script = &quot;echo hi &gt; /test.txt&quot;<br><br>  service_account {<br>    email  = google_service_account.default.email<br>    scopes = [&quot;compute-rw&quot;]<br>  }<br>}</pre><p>Once you’ve written your Terraform configuration, run the following commands to provision the VM:</p><ol><li><strong>Initialise the Terraform project</strong>. This command is similar to npm init which creates few files and folders like .terraform, .terraform.lock.hcl that are used by terraform to manage state of the resource created or pending.</li></ol><pre>terraform init</pre><p>2. <strong>Check the execution plan to see what Terraform will do</strong>. This command will show you what resources will be created with your code.</p><pre>terraform plan</pre><p>3. <strong>Apply the configuration to create the VM</strong>:</p><pre>terraform apply</pre><p>After you run terraform apply, Terraform will create the Compute Engine instance with the parameters you defined in the configuration file. You might notice a code block on top of file that defines a `provider`. Well it’s a terraform syntax to initialise an external provider. You can read more about it <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started">here</a>.</p><h3>Pro Tip for GCP Users</h3><p>A neat feature when using GCP’s console is that whenever you configure a cloud resource, such as a Compute Engine instance, an equivalent Terraform code snippet is generated automatically for you. This makes it incredibly easy to copy and paste Terraform code for the resources you configure in the console.</p><p>You can access this feature by clicking on the <strong>“EQUIVALENT CODE”</strong> button in the GCP console when you’re configuring any resource. The Terraform code will be displayed in a panel on the right, ready for you to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Vl_Gw63ALw_qL4ZwCLxpg.png" /></figure><h3>Next Steps: More Resources to Automate with Terraform</h3><p>Now that you’ve learned how to create a basic VM on GCP, the next logical step is to explore more GCP resources you can manage with Terraform. Here are a few ideas:</p><ol><li><strong>Google Kubernetes Engine (GKE)</strong>: Automate the creation of Kubernetes clusters with <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster">google_container_cluster</a>.</li><li><strong>Cloud Run</strong>: Deploy serverless applications with <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service">google_cloud_run_service</a>.</li><li><strong>Cloud SQL</strong>: Provision managed databases with <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance">google_sql_database_instance</a>.</li></ol><p>By applying the same principles you learned in this article, you can confidently automate the provisioning of more complex cloud resources.</p><h3>Conclusion</h3><p>Terraform is a powerful tool for automating cloud infrastructure, but it doesn’t have to be overwhelming. By taking the time to understand the console options first and mapping them to Terraform resources, you can quickly start managing your infrastructure as code. Once you’ve mastered the basics, you’ll be able to scale your knowledge to manage more complex resources and even deploy multi-cloud environments.</p><p>Start experimenting with Terraform, and you’ll soon realise how much simpler it makes managing cloud infrastructure!</p><p>For further reading:</p><ul><li><a href="https://developer.hashicorp.com/terraform/tutorials">Terraform Docs</a></li><li><a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs">Google Cloud Provider</a> for Terraform</li></ul><p>Feel free to share your experiences or questions in the comments below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bd43b37695e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Free SSL on Kubernetes with Let’s Encrypt and cert-manager]]></title>
            <link>https://medium.com/adg-vit/free-ssl-on-kubernetes-with-lets-encrypt-and-cert-manager-8a2466a611d9?source=rss-363accb914ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a2466a611d9</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[cert-manager]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Akshit Sadana]]></dc:creator>
            <pubDate>Tue, 18 May 2021 13:51:47 GMT</pubDate>
            <atom:updated>2021-05-18T14:23:50.022Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*CmmrgCr0yDv52dDxC4z1CQ.png" /></figure><p>SSL certificate is the single most crucial component enabling secure communication between server and client. When deploying a fleet of services on Kubernetes, securing both the internal and external network traffic can be tricky. To our rescue comes <strong>Cert-manager</strong>, a Kubernetes native certificate manager.</p><p>At the end of this tutorial, we’ll have secure cluster ingress traffic with a free SSL certificate issued from <strong>Let’s Encrypt</strong> using cert-manager.</p><p>All the source code and commands used in the tutorial can be found <a href="https://github.com/Akshit8/k8s-certmanager"><strong><em>here</em></strong></a>.</p><h3>What is cert-manager?</h3><p>Cert-manager is a native Kubernetes certificate management controller. It can help with issuing certificates from a variety of sources, such as Let’s Encrypt, HashiCorp Vault, self-signed certs, etc.</p><p>It will ensure certificates are valid and up to date, and attempt to renew certificates at a configured time before expiry.</p><p>Well, cert-manager comprises a variety of components and extensions, but we’ll discuss those that are required for this tutorial. Do check out related concepts <a href="https://cert-manager.io/docs/concepts/"><strong><em>here</em></strong></a>.</p><ul><li><strong>Issuer</strong> — component that talks to <em>CA authorities</em> and requests a certificate on demand.</li><li><strong>Certificate</strong> — it defines a certificate request as a Kubernetes resource, and this request is pushed to <em>Issuer</em>, and the issued certificate is then stored as a k8s secret object.</li></ul><figure><img alt="https://cert-manager.io/docs/" src="https://cdn-images-1.medium.com/max/737/1*lTPj4Ep4HhXLYfeHp2Gh2Q.png" /><figcaption>source: <a href="https://cert-manager.io/docs/">https://cert-manager.io/docs/</a></figcaption></figure><h3>Requirements</h3><p>Kubernetes cluster installed with <strong><em>Nginx-ingress</em></strong> and accessible with <strong><em>kubectl</em></strong> is required. I am using <a href="https://kind.sigs.k8s.io/"><em>Kind</em></a> to deploy a test Kubernetes cluster, but you can choose any distribution of Kubernetes of your choice.</p><p>For using Kind, you may refer to its <a href="https://kind.sigs.k8s.io/docs/user/quick-start/"><em>installation docs</em></a>.</p><h3>Installing cert-manager with regular manifests</h3><p>Install the <strong><em>CustomResourceDefinitions</em></strong> and <strong><em>cert-manager:</em></strong></p><pre>kubectl create ns cert-manager</pre><pre>kubectl -n cert-manager apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml</pre><p>You can download any other stable release for cert-manager from its <a href="https://github.com/jetstack/cert-manager/"><em>releases page</em></a>.</p><p>It’s a good practice to store the YAML files that you apply to the cluster, in case something goes wrong you can restore the state of the cluster by re-applying them. To store the cert-manager manifest we just applied, run the following scripts.</p><pre>curl -LO <a href="https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml">https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml</a></pre><pre>mv cert-manager.yaml cert-manager-1.3.1.yaml</pre><p>To verify the installation</p><pre>kubectl -n cert-manager get all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*sFwet5mq42KkKPw-xAlU_A.png" /></figure><h3>Deploying sample app</h3><p>For testing issued SSL certificate, let’s deploy a simple REST API in the cluster as well. Once deployed we’ll route the traffic to this app using <strong><em>Nginx-ingress</em></strong>.</p><p>The source code for the sample app is inside the <a href="https://github.com/Akshit8/k8s-certmanager/tree/master/app"><strong><em>app</em></strong></a> directory and infrastructure files are contained inside the <a href="https://github.com/Akshit8/k8s-certmanager/tree/master/infra"><strong><em>infra</em></strong></a> folder.</p><pre>kubectl apply -f ./deployment.yaml</pre><pre>kubectl apply -f ./service.yaml</pre><p>Do make sure service and deployment components are up and running.</p><h3>Setting up domain and ingress controller</h3><p>Since we’ll obtain SSL certificate from <strong><em>let’s encrypt</em></strong>, in order to verify ownership of the domain, let’s encrypt will send an <a href="https://cert-manager.io/docs/configuration/acme/"><strong><em>ACME</em></strong></a> challenge. So before setting up Issuer and certificate we need to point our domain name to our cluster.</p><p>If you are using a cloud provider point domain to the <strong><em>load balancer</em></strong>, for kind cluster or any other bare metal setup pointing to public IP of host machine will work fine.</p><p>Also, make sure the ingress controller is running and accepting traffic for your domain. Ping <strong><em>your-domain.com</em></strong> and you should be able to see a <strong>404 Not Found</strong> page. This indicates there are no routes to <strong>“/”</strong>and the ingress controller is running.</p><p>If you are not able to get the above result, make sure Nginx-ingress is installed and enabled inside the cluster. Refer to its <a href="https://kubernetes.github.io/ingress-nginx/deploy/"><strong><em>installation guide</em></strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97864fe69aac6b34f0b6a3d0883f7b7b/href">https://medium.com/media/97864fe69aac6b34f0b6a3d0883f7b7b/href</a></iframe><p>Copy the above code to <strong><em>ingress.yaml</em></strong> and apply it in the default namespace.</p><pre>kubectl apply -f ./ingress.yaml</pre><p>To verify the routing, access any endpoint of your REST API.</p><h3>Let’s issue a free SSL!</h3><p>Files used in this section are present in <a href="https://github.com/Akshit8/k8s-certmanager/tree/master/certmanager"><strong><em>certmanager</em></strong></a> dir.</p><h4>Step 1 Create a Let’s Encrypt Issuer for our cluster</h4><p>Creating a <strong>ClusterIssuer</strong>, allows us to issue and manage certificates in any namespace.</p><pre>kubectl apply -f issuer.yaml</pre><p>Verify the issuer is running and set to make the request.</p><pre>kubectl describe clusterissuer letsencrypt-cluster-issuer</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*pYHDWIzYfiAirkaqs-J98g.png" /></figure><h4>Step 2 Issue a certificate for our domain</h4><pre>kubectl apply -f certificate.yaml</pre><p>Verify if the certificate has been issued.</p><pre>kubectl describe certificate certmanager-app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*HBTlJ19maRZLTfXBsRgeww.png" /></figure><p>A tls secret would have been successfully created.</p><pre>kubectl get secrets</pre><pre>NAME                       TYPE                  DATA   AGE<br>cert-manager-app-tls       kubernetes.io/tls     2      84m</pre><p>To learn more about Kubernetes secret and tls secret click <a href="https://kubernetes.io/docs/concepts/configuration/secret/"><em>here</em></a>.</p><h4>Step 3 Update the ingress to enforce issued SSL</h4><p>Copy the ingress configuration from <a href="https://github.com/Akshit8/k8s-certmanager/blob/master/certmanager/ingress.yaml"><strong><em>certmanager/ingress.yaml</em></strong></a><strong><em> </em></strong>and paste it inside <strong><em>ingress.yaml</em></strong></p><pre>kubectl apply -f ./ingress.yaml</pre><p>Open the link <a href="https://your-domain.com/"><strong><em>https://your-domain.com</em></strong></a> inside the browser and you’ll be able to see the lock sign(left to the domain) ensuring that the SSL certificate is installed and the payload to-from server is encrypted.</p><h3>Conclusion</h3><p>While there are many ways to set up SSL certificates inside your cluster, I like to use cert-manager as its</p><ul><li>Easy to install.</li><li>Supports ACME (Let’s Encrypt), HashiCorp Vault, Venafi, self-signed, and internal certificate authorities.</li><li>Provide tools to manage certificates.</li></ul><p>If you want to use any other CA or configuration, checkout <a href="https://cert-manager.io/docs/configuration/"><strong><em>certmanager-configuration-docs</em></strong></a><strong><em>.</em></strong></p><p><a href="https://github.com/Akshit8/k8s-certmanager">Akshit8/k8s-certmanager</a></p><p>Cheers!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a2466a611d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adg-vit/free-ssl-on-kubernetes-with-lets-encrypt-and-cert-manager-8a2466a611d9">Free SSL on Kubernetes with Let’s Encrypt and cert-manager</a> was originally published in <a href="https://medium.com/adg-vit">ADGVIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The all-in-one guide for using Mongodb with Go]]></title>
            <link>https://medium.com/adg-vit/the-all-in-one-guide-for-using-mongodb-with-go-684060df9d69?source=rss-363accb914ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/684060df9d69</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[unittest]]></category>
            <category><![CDATA[go-mongo-driver]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Akshit Sadana]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 06:30:00 GMT</pubDate>
            <atom:updated>2021-03-16T06:39:20.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*eOBhPa5TyXbXws9fJUmHLg.png" /></figure><p><strong>Note:</strong> This article is not a particular code walkthrough or guide. It mostly highlights key-points about the source code that can be found <a href="https://github.com/Akshit8/go-mongodb"><em>here</em></a>.</p><h3>Introduction</h3><p>The repository is a sand-box that illustrates the usage pattern of Mongodb in Go using the <a href="https://github.com/mongodb/mongo-go-driver"><em>go-mongo</em></a>. The code is structured in a way making it easily pluggable with clean/onion/hexagonal architecture. The purpose of creating this sand-box is</p><ul><li>minimal dependency of business logic implementation on Mongodb and mongo-driver.</li><li>proper implementation of singleton client and its usage across the app.</li><li>solid unit testing of db queries in a concurrent environment.</li><li>easy migration of db layer if required.</li></ul><h3>Folder specs</h3><ul><li>.<strong>github</strong> — contains action workflows and repository assets.</li><li><strong>config</strong> — manages application configuration and environment variables.</li><li><strong>entity</strong> — contains entities of all logical constituents.</li><li><strong>random</strong> — functions to generate random data like string, integers, etc.</li><li><strong>repository/mongo</strong> — implementation of mongo client, CRUD ops on all entities, unit testing of all CRUD functions.</li></ul><h3>A note on update operation</h3><p>If you have noticed, instead of updating specific fields, the updateOne() function takes the complete updated entity and replaces it against a given matching parameter.</p><p>This is useful as it</p><ul><li>makes update operation consistent</li><li>independent of any kind of persistence implementation(Sql, NoSql, Message-Ques, Cache).</li><li>can handle updates on a large number of fields simultaneously.</li><li>compatible with event-driven architectures.</li></ul><h3>Using UUID instead of ObjectID</h3><p>I have chosen to use <strong>UUID</strong> as slug instead of objectID as it is only native to Mongodb and adds lots of conversion and validation related code. Using UUID makes all this excess code disappear.</p><h3>Testing on CI</h3><p>Following github action lints the source code and run unit tests.</p><pre>name: mongodb CI<br><br>on:<br>  workflow_dispatch:<br><br>jobs:<br>  ci:<br>    name: CI<br>    runs-on: ubuntu-latest<br><br>    services:<br>      mongodb:<br>        image: mongo<br>        env:<br>          MONGO_INITDB_ROOT_USERNAME: root<br>          MONGO_INITDB_ROOT_PASSWORD: rootpassword<br>        ports:<br>          - 27017:27017<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Set up Go<br>        uses: actions/setup-go@v2<br>        with:<br>          go-version: 1.15<br><br>      - name: install dependencies<br>        run: |<br>          make install<br>          go get golang.org/x/lint/golint<br><br>      - name: Lint code<br>        run: |<br>          make lint<br><br>      - name: Test code<br>        run: |<br>          make test</pre><h3>Running tests parallelly</h3><pre>t.Parallel()</pre><p>the above snippet makes the enclosing test function in a separate go-routine.</p><p><a href="https://github.com/Akshit8/go-mongodb">Akshit8/go-mongodb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=684060df9d69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adg-vit/the-all-in-one-guide-for-using-mongodb-with-go-684060df9d69">The all-in-one guide for using Mongodb with Go</a> was originally published in <a href="https://medium.com/adg-vit">ADGVIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backing-up, restoring and migrating Kubernetes cluster with Velero .]]></title>
            <link>https://medium.com/adg-vit/backing-up-restoring-and-migrating-kubernetes-cluster-with-velero-61ce454b7a2b?source=rss-363accb914ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/61ce454b7a2b</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[velero]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[cloud-storage]]></category>
            <dc:creator><![CDATA[Akshit Sadana]]></dc:creator>
            <pubDate>Thu, 25 Feb 2021 05:30:37 GMT</pubDate>
            <atom:updated>2021-02-25T05:30:37.000Z</atom:updated>
            <content:encoded><![CDATA[<h3>Backing-up, restoring and migrating Kubernetes cluster with Velero📦 .</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*NtsTcTTFo6d5XiHtzlUlaQ.png" /></figure><p><strong>Velero</strong> is a light weight tool to safely <em>backup</em>, <em>restore</em>, handle cluster-failovers, and migrate Kubernetes cluster resources and persistent volumes.</p><p>All the source code used in this tutorial can be found <a href="https://github.com/Akshit8/Velero"><em>here</em></a><em>.</em></p><h3>Kubernetes cluster with Kind</h3><p><a href="https://kind.sigs.k8s.io/"><strong>Kind</strong></a> is a light weight utility to create single-node Kubernetes cluster on a Docker container for testing purposes. Using Kind will allow us to create two test cluster of different versions quickly, thus allowing us to simulate cluster-migrations.</p><p>For installing kind:</p><ul><li>checkout <a href="https://kind.sigs.k8s.io/docs/user/quick-start/"><strong>kind-quickstart</strong></a></li><li>Or watch <a href="https://www.youtube.com/watch?v=m-IlbCgSzkc"><strong>this</strong></a> video</li></ul><p><strong>CAUTION</strong> 🛑 🛑 :</p><ul><li>Make sure Docker is installed on your machine.</li><li>If you are using Kubernetes(version <strong>1.17</strong>), do check if <strong>coredns</strong> is working. For verifying status of coredns check this post <a href="https://stackoverflow.com/questions/53075796/coredns-pods-have-crashloopbackoff-or-error-state"><strong>here</strong></a>.</li></ul><h3>GCP service account to use with Terraform and Velero</h3><p>A service account that has admin access to <strong><em>google cloud storage</em></strong> is required for <strong>Terraform</strong> to provision a bucket and for <strong>Velero</strong> to read/write backups to this bucket.</p><p>Open <a href="https://console.cloud.google.com/"><strong>google cloud console</strong></a> and navigate to <strong><em>IAM &amp; Admin</em></strong>&gt;<strong><em>Service accounts</em></strong></p><ul><li>Create a new service account.</li><li>Give <strong><em>cloud storage admin</em></strong> permission to this account.</li><li>Create a key for this account in <strong><em>json</em></strong> format and download it.</li><li>Rename it to <strong><em>credentials.json</em></strong> and place it inside <a href="https://github.com/Akshit8/velero/tree/master/gcpServiceAccount"><strong><em>gcpServiceAccount</em></strong></a><strong><em> </em></strong>folder.</li></ul><h3>Setting up storage plugin for Velero</h3><p>Velero requires a storage site for pushing back-up files and retrieving them back in case of restoration. We’ll be using <strong>Google cloud storage bucket</strong> for this tutorial, but you can explore wide variety of storage plugin offered by Velero <a href="https://velero.io/plugins/"><strong>here</strong></a>.</p><h4>Creating a storage bucket with Terraform</h4><p>You can grab <strong>Terraform</strong> CLI from <a href="https://www.terraform.io/downloads.html"><strong>here</strong></a> or else use a Docker container that comes pre-installed with terraform. The infrastructure files for terraform are placed inside <a href="https://github.com/Akshit8/velero/tree/master/storage"><strong><em>storage</em></strong></a> folder. Make sure your <strong><em>credentials.json</em></strong> is present inside <a href="https://github.com/Akshit8/velero/tree/master/gcpServiceAccount"><strong><em>gcpServiceAccount</em></strong></a> folder.</p><pre>docker run -it --rm -v ${PWD}/storage:/storage -w /storage<br>akshit8/terraform</pre><p><strong>Note</strong>: akshit8/terraform is a Debian docker container installed with Terrafotm CLI (v 0.14.7).</p><p>Once the container has been created, run the following commands to create a storage bucket on GCP.</p><pre><em># to download gcp provider and any dependency<br></em>terraform init</pre><pre><em># to apply changes on the cloud<br></em>terraform apply</pre><p>If no error is thrown, you’ll be able to see a newly created bucket in your cloud console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*5iAfNg94yY0ZAsU2zBTqeA.png" /></figure><h3>Test cluster with Kind(version 1.18)</h3><p>With storage bucket in place, let us create a <strong><em>test-cluster</em></strong> with Kubernetes version <strong>1.18.</strong></p><pre>kind create cluster --name test-cluster --image kindest/node:v1.18.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xE7oNAh5w4UlMTSkgDWTg.png" /></figure><h3>Installing Kubectl and Velero CLI</h3><p>To install both CLI’s we can use a <strong>Debian</strong> Docker container.</p><pre>docker run -it --rm -v ${HOME}:/root/ -v ${PWD}:/work -w /work --net host debian:buster</pre><p>mounting <strong>$HOME</strong> directory provides access to <strong>KUBE_CONFIG</strong> generated by Kind CLI.</p><ul><li>Installing Kubectl</li></ul><pre>curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s <a href="https://storage.googleapis.com/kubernetes-release/release/stable.txt%60/bin/linux/amd64/kubectl">https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl</a></pre><pre>chmod +x ./kubectl</pre><pre>mv ./kubectl /usr/local/bin/kubectl</pre><p>To verify kubectl and our <strong><em>test-cluster,</em></strong> run following command</p><pre>root@my-vm:/work# kubectl get nodes</pre><pre>NAME                         STATUS   ROLES    AGE     VERSION</pre><pre>test-cluster-control-plane   Ready    master   5m15s   v1.18.0</pre><ul><li>Installing velero CLI</li></ul><pre>curl -L -o /tmp/velero.tar.gz https://github.com/vmware-tanzu/velero/releases/download/v1.5.1/velero-v1.5.1-linux-amd64.tar.gz</pre><pre>tar -C /tmp -xvf /tmp/velero.tar.gz</pre><pre>mv /tmp/velero-v1.5.1-linux-amd64/velero /usr/local/bin/velero</pre><pre>chmod +x /usr/local/bin/velero</pre><h3>Deploying Kubernetes objects in a sample namespace</h3><p>Kubernetes objects used for this tutorial is located in <strong><em>k8s-objects</em></strong> folder.</p><pre>kubectl create ns sample</pre><pre>kubectl -n sample apply -f ./k8s-objects</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BZt-ZsxxYagpoy8vtbPgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyqrnLQMpAXk1JbTLy6VlQ.png" /></figure><h3>Configuring Velero for backing-up sample namespace</h3><p>Using Velero CLI installed previously, we need to deploy some components(that velero use) inside our cluster and configure them, so that Velero can access our <strong><em>cloud storage bucket</em></strong>.</p><pre><em># setting the bucket name<br></em>export BUCKET=velero-akshit</pre><pre><em># installing velero with provider gcp<br></em>velero install \<br>--provider gcp \<br>--plugins velero/velero-plugin-for-gcp:v1.1.0 \<br>--bucket $BUCKET \<br>--secret-file ./gcpServiceAccount/credentials.json</pre><p><strong>Note</strong>: it will create a new namespace velero to hold all components.</p><p>To verify above installation, run following commands</p><pre>root@my-vm:/work# kubectl -n velero get pods</pre><pre>NAME                      READY   STATUS    RESTARTS   AGE</pre><pre>velero-86bb45cdfb-987ps   1/1     Running   0          23s</pre><pre>root@my-vm:/work# kubectl logs deployment/velero -n velero</pre><p><strong><em>If installation and connection to our storage bucket is successful, no error messages would be there inside deployment logs.</em></strong></p><h3>Backing-up the sample namespace</h3><p>For adding <strong><em>sample</em></strong> namespace to Velero backup pool</p><pre>velero backup create sample-namespace-backup --include-namespaces sample</pre><pre>velero backup describe sample-namespace-backup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*80Fkc9kcjY4-z-ob8AQZJg.png" /></figure><p>If some error occurs, inspect the backup logs</p><pre>velero backup logs sample-namespace-backup</pre><p>Listing backups</p><pre>velero get backups</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*QDZDvyzjULlemIPaD3sQyg.png" /></figure><p>Verify on Google Cloud Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GiWKZU2p2qBEHCaRQLoSzg.png" /></figure><p>Our bucket contain backup files of all <strong>Kuberntes objects</strong> that were deployed inside <strong><em>sample</em></strong> namespace.</p><h3>Deleting object inside sample namespace(cluster-failover)</h3><pre>kubectl -n sample delete -f ./k8s-objects</pre><p>Let’s now recover the deleted objects with Velero.</p><pre>velero restore create sample-namespace-backup --from-backup sample-namespace-backup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ltoYd8qD82nHo3-niucUbg.png" /></figure><p>In case of any error, refer the logs</p><pre>velero backup logs sample-namespace-backup</pre><p>Let’s verify whether <strong><em>sample</em></strong> namespace has been restored or not</p><pre>kubectl get all -n sample</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*bAXzji7DiMS1pVlZfWVWYQ.png" /></figure><h3>Migrating cluster from version 1.18 to 1.19(cluster-migration)</h3><p>As before we’ll use kind to spin another light weight cluster with version <strong>1.19</strong></p><pre>kind create cluster --name test-cluster-2 --image kindest/node:v1.19.0</pre><p>Check if the cluster is ready and accessible:</p><pre>root@my-vm:/work# kubectl get nodes</pre><pre>NAME                           STATUS   ROLES    AGE    VERSION</pre><pre>test-cluster-2-control-plane   Ready    master   6m1s   v1.19.0</pre><h4>Installing Velero inside new cluster</h4><ul><li>repeat the above steps to install Velero again</li><li>make sure deployment logs displays no error</li><li>verify all components inside namespace velero are running.</li></ul><h3>Migrating backup to new cluster</h3><pre>velero get backup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*QDZDvyzjULlemIPaD3sQyg.png" /></figure><p>Starting the restore</p><pre>velero restore create sample-namespace-backup --from-backup sample-namespace-backup</pre><p>Verifying the restore</p><pre>root@my-vm:/work/velero# velero restore describe sample-namespace-backup</pre><pre>Phase:  Completed</pre><pre>Started:    2021-02-24 09:52:47 +0000 UTC<br>Completed:  2021-02-24 09:52:48 +0000 UTC</pre><p>Checking if all the components has been recovered</p><pre>kubectl get all -n sample</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BZt-ZsxxYagpoy8vtbPgA.png" /></figure><p><strong>Note: </strong>during migration, velero syncs with our storage bucket to get list of all backups, but it doesn’t apply or creates these backups automatically in your cluster.</p><h3>Conclusion</h3><ul><li>We have successfully simulated a cluster-failover and migration, while restoring our cluster back to original state.</li><li>Velero can also backup stateful workloads and volumes. The focus of this tutorial was to only backup stateless workloads.</li></ul><p>Source code for the above tutorial can be found below👇.</p><p><a href="https://github.com/Akshit8/velero">Akshit8/velero</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61ce454b7a2b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adg-vit/backing-up-restoring-and-migrating-kubernetes-cluster-with-velero-61ce454b7a2b">Backing-up, restoring and migrating Kubernetes cluster with Velero📦 .</a> was originally published in <a href="https://medium.com/adg-vit">ADGVIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating your own Docker with Go]]></title>
            <link>https://medium.com/adg-vit/creating-your-own-docker-with-go-9a9e978c3918?source=rss-363accb914ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9e978c3918</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Akshit Sadana]]></dc:creator>
            <pubDate>Wed, 10 Feb 2021 17:59:18 GMT</pubDate>
            <atom:updated>2021-02-10T18:25:38.713Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2OpiRGp_e15yGUX0IcUdJA.jpeg" /></figure><p>Docker, and the containers it makes has completely changed the way of packaging applications and deploying them. It injects our source code with mobility enabling them to run at scale. I use Docker for practically everything on my laptop, creating local development environments, testing environments and using disposable containers for doing some crazy stuff and deleting them right away if things get messy😅. I am sure that everyone who has ever used Docker must be amazed that how a single <strong><em>docker-run</em></strong> command, let us create isolated and independent machines(called containers) within a few seconds.</p><p>Let’s understand this magic while implementing our own <strong>Docker</strong> with a few lines <strong>Go code</strong>.</p><h3><strong>What we’ll do?</strong></h3><p>At the end of this post we’ll be having a Go binary that would be capable of running any valid linux command/executable inside an isolated process(practically known as container).</p><pre>docker         run   image          &lt;cmd&gt; &lt;params&gt;</pre><pre>go run main.go run  {some command}  &lt;cmd&gt; &lt;params&gt;</pre><h3><strong>Requirements</strong></h3><ol><li><strong>Go SDK</strong>(Linux)</li><li>Any <strong>Linux</strong> distribution</li><li><strong>Docker</strong> for Linux</li></ol><p>Linux is required because containers are practically a wrap around some awesome Linux technologies that we’ll be exploring next.</p><h3><strong>Some Linux technologies</strong></h3><ol><li><strong>Namespaces</strong> — what an isolated process can see is defined and controlled by namespaces. It creates isolation by providing each process its own pseudo environment.</li><li><strong>Chroots</strong> — it control root filesystem for each process.</li><li><strong>Cgroups</strong> — what an isolated process can use as resource from host machine is enforced by Cgroups(control groups).</li></ol><h3><strong>A bit about Namespaces</strong></h3><p>Namespaces provide the isolation needed to run multiple containers on one machine while giving each what appears like it’s own environment. We have following 6 namespaces thus providing different levels and kinds of isolation.</p><ul><li>Unix Timesharing System</li><li>Process IDs</li><li>Mounts</li><li>Networks</li><li>User IDs</li><li>InterProcess Communication</li></ul><h3><strong>Container v/s Host</strong></h3><p>Enough with theory and definitions, now let’s actually see how a container behaves differently from host machine.</p><p>We’ll create an ubuntu docker container passing <strong><em>/bin/bash</em></strong> as entrypoint. Use the following snippet.</p><pre>docker run -it --rm ubuntu /bin/bash</pre><p>We’ll run a few Linux commands inside container(ubuntu 20.04) and host machine(ubuntu 20.04) and observer their behaviour inside both environments:</p><ul><li><strong>hostname</strong> — return name of the host inside which bash is running.</li><li><strong>ps</strong> — return list of active process running inside the environment.</li></ul><p><strong><em>Container</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iCZQF7Y3jlY3fvdM3RErlQ.png" /></figure><p><strong><em>Host</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZCc0w3tjOVzCl_eNwPVJA.png" /></figure><p>We can see that, when we run same commands in docker container and host machine we get different results.</p><ul><li>Container is assigned a hostname from docker(container ID), while our system have a completely different hostname.</li><li>Lots of process are running inside our host but our container is only aware of process running inside it, thus providing <em>process isolation</em>.</li></ul><h3><strong>Let’s dive deep</strong></h3><p>We have got a taste of a how these containers function and be distinguished. It’s time to open our editor and write some Go code to achieve something similar that docker does.</p><p>Create a <strong><em>main.go</em></strong> file with <em>main package</em> and start adding the following components. Do read the comments mentioned in these code snippet for a better understanding.</p><ul><li><strong>Command Switch</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/562dbc3a51bb4e206ec64e1ad8870b4f/href">https://medium.com/media/562dbc3a51bb4e206ec64e1ad8870b4f/href</a></iframe><p>The command switch picks the command-line argument passed, and runs the function mapped to that argument.</p><ul><li><strong>Run function</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f484f4b8e40cc565dad1c7d5096d0588/href">https://medium.com/media/f484f4b8e40cc565dad1c7d5096d0588/href</a></iframe><p>The<em> </em><strong><em>run()</em></strong> function is responsible for creating an isolated process(container) and then execute the very same go program inside this isolated process, this time invoking <strong><em>child()</em></strong> function</p><ul><li><strong>Child function</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da3fa645265b05f3fef7f8402a852b94/href">https://medium.com/media/da3fa645265b05f3fef7f8402a852b94/href</a></iframe><p>The <strong><em>child()</em></strong> function is invoked by <strong><em>run()</em></strong> as a child process inside container created by <strong><em>run()</em></strong>. It is responsible for some <strong>system calls</strong> for setting some container properties and finally execute the command dispatched from user.</p><ul><li><strong>Must function</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba575e08b94eb2346fb6cc60d10da19c/href">https://medium.com/media/ba575e08b94eb2346fb6cc60d10da19c/href</a></iframe><p>The <strong><em>must()</em></strong> is a simple error wrapper that panics if any system call invoked inside child function fails.</p><h3><strong>Let’s create some containers</strong></h3><p>Now that we have a mini docker program that can actually create isolated and independent containers on our host machine. Let’s put it to some use!</p><p>The command that we would be running inside our container is <strong><em>/bin/bash</em></strong>, that will start a new bash program inside our container.</p><p>Run following snippet to run the binary that will create the container.</p><pre>go run main.go run /bin/bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySr9IjwA6DesqTXa-aaeHg.png" /></figure><p>When we run the above command passing <strong><em>/bin/bash</em></strong> as argument following changes happen</p><ul><li>a new container is created running a bash process in isolation to the host system.</li><li><em>running [/bin/bash] as 279518</em> means our bash process running in the container has a <strong>pid</strong> of 279518 on host, while <em>Running [/bin/bash] as 1</em> is the <strong>pid</strong> of the same process inside our container.</li><li>both <strong><em>root@maverick </em></strong>and <strong><em>hostname</em></strong> command tells us that hostname of our container is maverick, that is passed as s<strong><em>ystem call</em></strong> by our Go program.</li><li>running <strong><em>ps</em></strong> return only the process running inside our container and has no information about other system processes.</li><li>since we mounted the <strong><em>root dir</em></strong> of our host machine as <strong><em>Chroot</em></strong> of our container, upon running <strong><em>ls</em></strong> we can see all those root files.</li></ul><p>Now we are sure that our bash is running as an isolated process, let’s <strong><em>exit</em></strong> from it and observe come changes w.r.t host machine.</p><ul><li>upon exit, we kill our container and return back to host machine</li><li><em>hostname</em> and <em>ps</em> return different metrics and values that represents our host machine.</li></ul><h3><strong>Understanding the Chroots</strong></h3><p>In above execution we mounted root directory of host machine as our container’s <strong><em>root dir</em></strong>. This practically gives all executables and metadata which our host machine holds, thus creating a vulnerability. A better approach to this, could be creating a pseudo root directory with stripped down executable and thus mounting is as container’s <strong><em>root dir</em></strong>.</p><h3><strong>Conclusion</strong></h3><p>We have successfully created a <strong>Go</strong> program that runs a <strong>Linux executable</strong> as an isolated container with its own hostname, own process management and pseudo<strong><em> root-dir</em></strong>. For creating a fully isolated and independent container similar to a Docker container we’ll have to touch all six namespaces, configure all Cgroups, dynamically create Chroots for every container and do <strong>layer caching(</strong><em>which makes docker awesome to use 😀</em><strong>)</strong> is beyond the scope of this article.</p><p>I hope this article helped you understand how Docker works and how it wraps cool pieces of technology that comes with Linux kernel.</p><p>For an in-depth understanding of <strong><em>how docker works?</em></strong>, I would recommend you to check <strong>containers from scratch</strong> by <em>Liz Rice</em>.</p><p>For complete source code, checkout</p><p><a href="https://github.com/Akshit8/my-docker">https://github.com/Akshit8/my-docker</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9e978c3918" width="1" height="1" alt=""><hr><p><a href="https://medium.com/adg-vit/creating-your-own-docker-with-go-9a9e978c3918">Creating your own Docker with Go</a> was originally published in <a href="https://medium.com/adg-vit">ADGVIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>