<?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 HEMANT JANGIR on Medium]]></title>
        <description><![CDATA[Stories by HEMANT JANGIR on Medium]]></description>
        <link>https://medium.com/@jangirhemant53?source=rss-31ed259a1fd7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DBqWe5GVsLSylDF7</url>
            <title>Stories by HEMANT JANGIR on Medium</title>
            <link>https://medium.com/@jangirhemant53?source=rss-31ed259a1fd7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:45:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jangirhemant53/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[Building a High-Performance Reddit Clone with Kubernetes Ingress]]></title>
            <link>https://medium.com/@jangirhemant53/building-a-high-performance-reddit-clone-with-kubernetes-ingress-874655261aaa?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/874655261aaa</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Thu, 21 Dec 2023 11:02:33 GMT</pubDate>
            <atom:updated>2023-12-21T11:02:33.338Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we begin with the Project, we need to make sure we have the following prerequisites installed:</p><ol><li>EC2 ( AMI- Ubuntu, Type- t2.micro ) - CI server</li><li>EC2 ( AMI- Ubuntu, Type- t2.medium ) - Deployment server</li></ol><p>You can Install all this by doing the below steps one by one. and these steps are for Ubuntu AMI.</p><pre># For Docker Installation<br>sudo apt-get update<br>sudo apt-get install docker.io -y<br>sudo usermod -aG docker $USER &amp;&amp; newgrp docker</pre><pre># For Minikube &amp; Kubectl<br>curl -LO <a href="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64">https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64</a><br>sudo install minikube-linux-amd64 /usr/local/bin/minikube </pre><pre>sudo snap install kubectl --classic<br>minikube start --driver=docker</pre><h3>Step 1: Clone the source code</h3><p>The first step is to clone the source code for the app. You can do this by using this command git clone <a href="https://trainwithshubham.hashnode.dev/deployed-a-reddit-copy-on-kubernetes-with-ingress-enabled#heading-step-2-containerize-the-application-using-docker">https://github.com/LondheShubham153/reddit-clone-k8s-ingress.git</a></p><h3>Step 2: Containerize the Application using Docker</h3><ul><li>Write a Dockerfile with the following code:</li></ul><pre>FROM node:19-alpine3.15</pre><pre>WORKDIR /reddit-clone</pre><pre>COPY . /reddit-clone</pre><pre>RUN npm install </pre><pre>EXPOSE 3000</pre><pre>CMD [&quot;npm&quot;,&quot;run&quot;,&quot;dev&quot;]</pre><h3>Step 3) Building Docker-Image</h3><p>Now it’s time to build Docker Image from this Dockerfile. docker build -t &lt;DockerHub_Username&gt;/&lt;Imagename&gt; . use this command to build a docker image.</p><h3>Step 4) Push the Image To DockerHub</h3><ul><li>Then use docker push &lt;DockerHub_Username&gt;/&lt;Imagename&gt; for pushing to the DockerHub.</li><li>You can use an existing docker image i.e <strong><em>trainwithshubham/reddit-clone</em></strong> for deployment.</li></ul><h3>Step 5) Write a Kubernetes Manifest File</h3><p>Now, You might be wondering what this manifest file in Kubernetes is. Don’t worry, I’ll tell you in brief.</p><h3>Write Deployment.yml file</h3><p>Let’s Create a Deployment File For our Application. Use the following code for the <strong><em>Deployment.yml</em></strong> file.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: reddit-clone-deployment<br>  labels:<br>    app: reddit-clone<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: reddit-clone<br>  template:<br>    metadata:<br>      labels:<br>        app: reddit-clone<br>    spec:<br>      containers:<br>      - name: reddit-clone<br>        image: trainwithshubham/reddit-clone<br>        ports:<br>        - containerPort: 3000</pre><p>kubectl apply -f Deployment.yml</p><p>kubectl get deployment</p><h3>Write Service.yml file</h3><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: reddit-clone-service<br>  labels:<br>    app: reddit-clone<br>spec:<br>  type: NodePort<br>  ports:<br>  - port: 3000<br>    targetPort: 3000<br>    nodePort: 31000<br>  selector:<br>    app: reddit-clone</pre><p>kubectl apply -f Service.yml</p><p>kubectl get services</p><h3>Expose the app</h3><p>expose our service:</p><p>minikube service reddit-clone-service --url (reddit-clone-service is a service name)</p><p>curl -L <a href="http://192.168.49.2:31000/">http://192.168.49.2:31000</a></p><p>Here we app is running in the CLI terminal</p><p>expose our deployment :</p><p>kubectl expose deployment reddit-clone-deployment --type=NodePort</p><p>To run the application in the browser :</p><p>open port: 3000 <em>in a security group</em></p><p>kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0</p><p>kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 &amp;</p><h3>Let’s Configure Ingress</h3><h3>Ingress:</h3><p>An API object that manages external access to the services in a cluster, typically HTTP.</p><p>Ingress may provide load balancing, SSL termination and name-based virtual hosting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*8ZUfNDVikUhTXU97.png" /></figure><p>Let’s write ingress.yml and put the following code in it:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: ingress-reddit-app<br>spec:<br>  rules:<br>  - host: &quot;domain.com&quot;<br>    http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/test&quot;<br>        backend:<br>          service:<br>            name: reddit-clone-service<br>            port:<br>              number: 3000<br>  - host: &quot;*.domain.com&quot;<br>    http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/test&quot;<br>        backend:<br>          service:<br>            name: reddit-clone-service<br>            port:<br>              number: 3000</pre><p>Minikube doesn’t enable ingress by default; we have to enable it first using the minikube addons enable ingress command.</p><p>curl -L <a href="http://domain.com/test">domain.com/test</a></p><p>Now application running in the CLI terminal using ingress.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=874655261aaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Persistent Volumes and Persistent Volumes Claim]]></title>
            <link>https://medium.com/@jangirhemant53/persistent-volumes-and-persistent-volumes-claim-72a7ed7feca9?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/72a7ed7feca9</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 14:56:08 GMT</pubDate>
            <atom:updated>2023-12-17T14:56:08.180Z</atom:updated>
            <content:encoded><![CDATA[<h3>Persistent Volumes (PV)</h3><p>Persistent Volumes are resources in Kubernetes that provide storage implementations, such as NFS, iSCSI, or cloud-specific storage systems like AWS EBS, GCE Persistent Disk, and Azure Disk. A PV has a lifecycle independent of any individual Pod that uses the PV. This means the data remains intact, even when no Pod is using it.</p><h3>Persistent Volume Claim (PVC)?</h3><p>A PVC is a request for storage by a user. It’s similar to a Pod: while Pods consume node resources, PVCs consume PV resources. Once a PVC is bound to a PV, it can be mounted to a Pod and utilized as a regular disk.</p><ol><li>Creating a Persistent Volume:</li></ol><p>Here’s a basic example of a PV that provides 1Gi of storage on a local node:</p><pre>apiVersion: v1<br> kind: PersistentVolume<br> metadata:<br>   name: my-pv<br>   namespace: mysql<br> spec:<br>   capacity:<br>     storage: 1Gi<br>   volumeMode: Filesystem<br>   accessModes:<br>     - ReadWriteOnce<br>   hostPath:<br>     path: &quot;/home/ubuntu/volume&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*_hYHiBQiqDWxSQyD2Nsi-w.png" /></figure><p>2. Creating a Persistent Volume Claim:</p><p>A PVC will claim storage from the available PVs. Here’s an example:</p><pre>kind: PersistentVolumeClaim<br>metadata:<br>  name: my-pv-claim <br>  namespace: mysql<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 500Mi</pre><p>Once the above PVC is created, Kubernetes will bind it to a suitable PV.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*RenoXXuZsp2LKaU52KujtA.png" /></figure><p>Deployment.yml file</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mysql-deployment<br>  namespace: mysql<br>  labels:<br>    app: mysql<br><br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: mysql<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql<br>    spec:<br>      containers:<br><br>        - name: mysql<br>          image: mysql<br>          ports:<br>            - containerPort: 3306<br><br>          env:<br>          # Define the environment variable<br>            - name: MYSQL_DATABASE # Notice that the case is different here<br>                                     # from the key name in the ConfigMap.<br>              valueFrom:<br>                configMapKeyRef:<br>                  name: mysql-config         # The ConfigMap this value comes from.<br>                  key: MYSQL_DATABASE  # The key to fetch.<br>            - name: MYSQL_ROOT_PASSWORD<br>              valueFrom:<br>                secretKeyRef:<br>                  name: mysql-secret<br>                  key: MYSQL_PASSWORD<br>          volumeMounts:<br>            - name: mysql-persistent-storage<br>              mountPath: /var/lib/mysql           # container path<br>      volumes:<br>      - name: mysql-persistent-storage<br>        persistentVolumeClaim:<br>          claimName: mysql-pv-claim</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72a7ed7feca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ConfigMaps and Secrets in Kubernetes]]></title>
            <link>https://medium.com/@jangirhemant53/configmaps-and-secrets-in-kubernetes-2965d01f0e24?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2965d01f0e24</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 08:38:48 GMT</pubDate>
            <atom:updated>2023-12-17T13:49:22.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>ConfigMaps</h3><p>A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. It allows you to decouple environment-specific configuration from your containerized application, making your application more portable. ConfigMap does not provide secrecy or encryption. If the data you want to store are confidential, use a Secret rather than a ConfigMap.</p><h3>Secrets</h3><p>Secrets, as the name suggests,A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Use Cases for Secrets: Storing database credentials, API tokens, SSL certificates.</p><p>Kubernetes <strong>objects</strong> are entities in a Kubernetes cluster that represent the cluster’s state</p><p><strong>deployment.yml</strong> file</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mysql-deployment<br>  namespace: mysql<br>  labels:<br>    app: mysql<br><br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: mysql<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql<br>    spec:<br>      containers:<br>      - name: mysql<br>        image: mysql<br>        ports:<br>        - containerPort: 3306</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*ZTpgyqyKTY1yRxtGDQdfyg.png" /></figure><p>because we can’t created database so out mysql creash every time when it’s created.</p><p><strong>Creating a ConfigMap:</strong></p><p>You can create a ConfigMap using a YAML file or directly from the command line. Here’s an example using a YAML file:</p><p>Create <strong>configmap.yml</strong> file</p><pre>apiVersion: v1<br>kind: ConfigMap <br>metadata:  <br>  name: mysql-config<br>  namespace: mysql<br>  labels:<br>    app: mysql<br><br>data: <br>  MYSQL_DATABASE: &#39;cooldb&#39;</pre><p>Apply it with:</p><pre>kubectl apply -f configmap.yml -n config-secret<br><br>kubectl get configmaps -n config-secret //checking the status of the ConfigMaps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*6pPqlvwUSFQ7xuPlEDXOkQ.png" /></figure><p><strong>deployment.yml</strong> file after Create <strong>configmap.yml</strong> file (database)</p><pre>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: mysql<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql<br>    spec:<br>      containers:<br><br>        - name: mysql<br>          image: mysql<br>          ports:<br>            - containerPort: 3306<br><br>          env:<br>          # Define the environment variable<br>            - name: MYSQL_DATABASE # Notice that the case is different here<br>                                     # from the key name in the ConfigMap.<br>              valueFrom:<br>                configMapKeyRef:<br>                  name: mysql-config  # The ConfigMap name,value comes from.<br>                  key: MYSQL_DATABASE  # The key to fetch.</pre><p>This time it also give error because we don’t give pasword in mysql database.</p><h3>Creating a Secret:</h3><p>Before we create a secret, we need to create a base64 encoded string of the database password that we will use in our deployment.yml file.</p><p>I’m taking the following details as secret key. Following details as secret key:</p><ul><li>Password : test123</li></ul><pre>echo -n &#39;test123&#39; | base64</pre><p>For verifying the secret key, we can use the following command:</p><pre>echo -n &#39;dGVzdDEyMw==&#39; | base64 --decode</pre><p><strong>secret.yml</strong> file</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: mysql-secret<br>  namespace: mysql<br>  labels:<br>    app: mysql<br><br>type: Opaque<br>data:<br><br>  MYSQL_PASSWORD: dGVzdDEyMw==</pre><p>What is the <strong>Opaque</strong> type? : The opaque type is used to store sensitive data such as passwords, certificates, and tokens.</p><p>Apply the updated deployment using the command:</p><pre>kubectl apply -f secret.yml -n config-secret<br>kubectl get secrets -n config-secret</pre><p><strong>deployment.yml</strong> file after Create <strong>secret.yml</strong> file (password)</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mysql-deployment<br>  namespace: mysql<br>  labels:<br>    app: mysql<br><br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: mysql<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql<br>    spec:<br>      containers:<br><br>        - name: mysql<br>          image: mysql<br>          ports:<br>            - containerPort: 3306<br><br>          env:<br>          # Define the environment variable<br>            - name: MYSQL_DATABASE # Notice that the case is different here<br>                                     # from the key name in the ConfigMap.<br>              valueFrom:<br>                configMapKeyRef:<br>                  name: mysql-config         # The ConfigMap this value comes from.<br>                  key: MYSQL_DATABASE  # The key to fetch.<br>            - name: MYSQL_ROOT_PASSWORD<br>              valueFrom:<br>                secretKeyRef:<br>                  name: mysql-secret<br>                  key: MYSQL_PASSWORD</pre><pre>kubectl apply -f deployment.yml -n config-secret<br>kubectl get pods -n config-secret</pre><h3>worker node :</h3><p>here we can see inside the container a database created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*b36Xe0YKujEfaHPxW8tdFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2965d01f0e24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetese project in]]></title>
            <link>https://medium.com/@jangirhemant53/kubernetese-project-in-b41b4a2b3c79?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b41b4a2b3c79</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 08:09:00 GMT</pubDate>
            <atom:updated>2023-12-17T08:09:00.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetese project ingress</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b41b4a2b3c79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kuberneties Fundamental]]></title>
            <link>https://medium.com/@jangirhemant53/kuberneties-fundamental-9ecd4f8c7ac8?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ecd4f8c7ac8</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Sat, 16 Dec 2023 04:06:35 GMT</pubDate>
            <atom:updated>2023-12-21T06:39:31.803Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Kubernetes?</h3><p><strong>Kubernetes</strong> is an open-source <strong>Orchestration</strong> <strong>tool</strong> or we can say <strong>container management tool</strong> which designed is used to automate the container deployment, scaling,management and load balancing of containerized applications.</p><p><strong>Orchestration: </strong>the process of automating and managing a large number of containers and how they interact.</p><p>It schedules, runs and manages isolated containers which are running on virtual/physical/ cloud machines.</p><p>Kubernetes main role managing containers. But what are <strong>containers</strong>? Containers hold the entire packages that is needed to run the application. In other words, we can say that the image is a template and the container is a copy if that template.</p><p><strong>History</strong>:<br>➢ In 2014, google introduced Kubernetes as an open-source platform written in Golang, and later donated to CNCF (cloud Native Computing Foundation).</p><p>Online platform for K8s:<br>i. Kubernetes playground<br>ii. Play with K8s<br>iii. Play with Kubernetes classroom</p><p><strong>Cloud based K8s services:<br></strong>i. GKE: Google Kubernetes Services<br>ii. AKS: Azure Kubernetes services<br>iii. Amazon EKS: Amazon Elastic Kubernetes Services</p><p><strong>Kubernetes installation tool:<br></strong>i. Minicube<br>ii. Kubeadm (min. 2 cpu , 4 GB ram)</p><h3>why we use Kubernetes :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XAJidwRcNhYQ3WHb8_5vNg.jpeg" /></figure><p><strong>Problems with scaling up the containers:<br></strong>➢ Containers cannot communicate with each other.<br>➢ Autoscaling and load balancing was not possible.<br>➢ Containers had to be managed carefully.</p><p><strong>Features of Kubernetes:<br></strong>➢ <strong>Orchestration</strong>: process of automating and managing a large number of containers and how they interact.<br>➢ Autoscaling [supports both horizontal scaling →(adding more machines or nodes) and vertical scaling →(adding more power (CPU, RAM, storage, etc.) to an existing machine)]<br>➢ Auto-healing<br>➢ Load balancing<br>➢ Platform independent (cloud/ virtual/ physical)<br>➢ Fault tolerance (node/ POD failure)➢ Rollback (going back to previous version)<br>➢ Health monitoring of containers<br>➢ Batch execution (one time, sequential, parellel)</p><h3>Kubernetes Architecture:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37ruKibAiFZbxrRsQBh7Sw.jpeg" /></figure><p><strong>Role of Master Node</strong>:<br>➢ Kubernetes cluster contains containers running or bare metal/ vm instances. Cloud instances/ all mix.<br>➢ Kubernetes designates one or more of these as master and all others as workers.<br>➢ The master is now going to run set of k8s processes. These processes will resume<br>smooth functioning of cluster. These processes are called “control plane”.<br>➢ Can be multi-master for high availability.<br>➢ Master runs control plane to run cluster smoothly.</p><h3><strong>Components of Control Plane (master):</strong></h3><ol><li>Kube-API server</li><li>Etcd</li><li>Kube-scheduler</li><li>Controller manager</li><li><strong>Kube-API server (for all communications):</strong><br>➢ This api-server interacts directly with user (i.e we apply .yml or json manifest to kube-apiserver).<br>➢ This kube-apiserver is meant to scale automatically as per load.<br>➢ Kube api-server is front-end of control-plane.<br>2. <strong>Etcd</strong>:<br>➢Stores metadata and status of cluster (set of nodes). Format: Key-Value. It is consistent and highly available.<br>➢ Etcd is consistent and high available store (key-value store).<br>➢ Source of touch for cluster state (info about state of cluster).<br>Etcd has following features: -<br>a. Fully replicated: the entire state is available on every node in the cluster.<br>b. Secure: implements automatic TLS with optional client-certificate<br>authentication.<br>c. Fast: benchmarked at 10,000 writes per second.<br><strong>3. Kube scheduler:<br></strong>➢ When users make request for the creation and management of PODs, kube scheduler is going to take action on these requests. When pod is been created, it finds the best suitable node and puts it there.<br>➢ Handles POD creation and management.<br>➢ Kube scheduler match/ assign any node to create and run PODs.<br>➢ A scheduler watches for newly created PODs that have no node assigned. For every POD that the scheduler discovers the scheduler becomes responsible for finding best node for that POD to run on.<br>➢ Scheduler gets the information for hardware configuration from configuration file and schedules the PODs on nodes accordingly.<br><strong>4. Controller Manager:<br></strong>➢ Make sure that actual state of cluster matches the desired state.<br>➢ Two possible choices for controller manager:<br>a. If k8s on cloud, then it will be cloud-controller-manager.<br>b. If k8s on non-cloud then it will be kube-controller-manager</li></ol><p><strong>Nodes (kublet and container engine.)</strong><br>Node is going to run 3 important pieces of software/ process.<br>1. Kublet<br>2. Container engine<br>3. Kubeproxy<br><strong>1. Kublet:<br></strong>➢ Agent running on the node.<br>➢ Listens to Kubernetes master. (e.g-POD creation request)<br>➢ Use port 10255.<br>➢ Send success/fail reports to master.<br><strong>2. Container Engine:<br></strong>➢ Works with kublet.<br>➢ Pilling images.<br>➢ Start/ stop containers.<br>➢ Exposing containers on ports specified in manifest.<br><strong>3. Kubeproxy:<br></strong>➢ Assign IP to each POD.<br>➢ It is required to assign IP address to PODs (dymanic).<br>➢ Kube-proxy runs on each node and this make sure that each POD will get its own unique IP address. These 3 components collectively called NODE.</p><p>POD:<br>➢ Smallest unit in Kubernetes.<br>➢ POD is a group of one or more containers that are deployed together on the same host.<br>➢ A cluster is a group of nodes.<br>➢ A cluster has at least one worker node and master node.<br>➢ In Kubernetes the control unit is the POD, not containers.<br>➢ It consists of one or more tightly coupled containers.<br>➢ POD runs on node which is control by master.<br>➢ Kubernetes only knows about PODs (does not know about individual container).<br>➢ Cannot start containers without a POD.<br>➢ One POD usually contains one container.</p><h3>There are primary two ways to create and manage resources:</h3><ol><li>Command-Line Interface</li></ol><h3>Command-Line Interface:</h3><p>The Kubernetes CLI referred to as kubectl is a tool that allows you to interact with the Kubernetes Cluster. It provides a set of commands to create, modify, and manage Kubernetes resources</p><p>For example:</p><blockquote><em>kubectl create to create a resource, </em><em>kubectl edit or </em><em>kubectl patch to modify the resource and </em><em>kubectl delete to delete any resources, </em><em>kubectl get pods to get all the pods in the default namespace. There are many more commands.</em></blockquote><h3>YAML Manifests:</h3><p>YAML manifests are configuration files written in YAML. These files define the desired state of Pods, Deployments, ConfigMaps, Secret, and many more.</p><blockquote><em>We will be using YAML Manifests to deploy our application.</em></blockquote><h3>What is Pods?</h3><blockquote>The code of our application runs inside containers, which are encapsulated within Pods in Kubernetes.</blockquote><ul><li>A Pod can <strong>contain one or more containers</strong>, and all the containers <strong>share the same resources</strong> such as CPU, memory, and storage</li><li>Pods have their <strong>own unique IP address</strong> within the cluster, enabling other Pods or services to communicate with them.</li><li>Pods in Kubernetes are considered ephemeral, meaning they can be <strong>created, scaled, or terminated dynamically</strong> based on the desired state of the system.</li></ul><blockquote><em>1 Pod = 1 container is recommendand as best practices.</em></blockquote><h3>Task 1: Create your First Pod.</h3><p>We will be creating a single pod using the YAML Manifests.</p><blockquote><em>pod.yml</em></blockquote><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: django-app<br>spec:<br>  containers:<br>  - name: django-app<br>    image: trajendra/django-todo:latest<br>    ports: <br>    - containerPort: 8000</pre><p>In pod.yml file,</p><ul><li>apiVersion: v1 specifies the Kubernetes API version being used.</li><li>kind: Pod indicates that you are creating a Pod object.</li><li>metadata contains metadata about the Pod, including its name.</li><li>spec defines the desired state of the Pod.</li><li>containers is an array of container objects running inside the Pod. In this case, there is only one container.</li><li>name: crud-backend-app sets the name of the container to &quot;crud-backend-app&quot;.</li><li>image: trajendra/crudbackend:latest specifies the Docker image to be used for the container. In this case, it uses the image &quot;trajendra/django-todo&quot; with the &quot;latest&quot; tag.</li><li>ports defines the network ports that the container exposes. In this example, it exposes port 8000.</li></ul><pre>kubectl apply -f pod.yml</pre><p>Run this command, Kubernetes will read our YAML file, and update any resources in our cluster accordingly. To see the newly created pod in action, you can run kubectl get pods. You should see the pod running.</p><blockquote><em>Worker nodes are the machines in the Kubernetes cluster where Pods are scheduled and containers are run</em></blockquote><ul><li>Connect to Worker Node to verify if the container is successfully created.</li></ul><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ETVVVRPf0y6J2SD9.png" /></figure><ul><li>Let’s go inside the container and execute the curl command</li></ul><pre>docker exec -it 3551dae bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*8wU0KTRQbuYxKvuK.png" /></figure><blockquote><em>Hey ! We have successfully been able to create containers via pod using YAML Manifests</em></blockquote><h3>Namespaces</h3><p>Namespaces are logical groups created inside a Cluster. They allow multiple teams or applications to co-exist in the same cluster.</p><blockquote><em>Each namespace has its own set of resources, including Pods, Services, Deployments, ConfigMaps, and more.</em></blockquote><ul><li>By default, Kubernetes provides a default namespace where resources are created if no specific namespace is specified</li><li>You can define RBAC (Role-Based Access Control) policies to grant different levels of access to resources based on namespaces.</li></ul><h3>Step 5: Create a Namespace</h3><pre>kubectl create namespace my-django-app</pre><p>We will be creating my-django-app namespace for our application to include all the pods, services, deployment, and containers in this namespace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*lX-5SkzEoayL3_WX.png" /></figure><h3>Task 2: Create a Pod inside the Namespace</h3><blockquote><em>pod.yml</em></blockquote><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: django-app<br>  namespace: my-django-app<br>spec:<br>  containers:<br>  - name: django-app<br>    image: trajendra/django-todo:latest<br>    ports: <br>    - containerPort: 8000</pre><ul><li>To create the pod run the following command:</li></ul><pre>kubectl apply -f pod.yml</pre><ul><li>To verify the pods created inside the namespace</li></ul><pre>kubectl get pods -n=my-django-app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VkaCwwXL8qYkJpRk.png" /></figure><h3>Deleting a Pod</h3><pre>kubectl delete -f pod.yml</pre><p>Here, the pod will be deleted from the namespace my-django-app .</p><p>As we have added a namespace added in the metadata.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*pAngJvAAji3BA6cZ.png" /></figure><blockquote><em>We just learned to create a pod inside the namespace.</em></blockquote><h3>Deployment</h3><blockquote><em>Our app runs inside kubernetes cluster. Application consists of multiple pods, each representing a component of the application. Instead of manually creating and managing individual pods for your application, you can use a deployment.</em></blockquote><ul><li>It ensures that the<strong> desired number of replicas of each component</strong> is always available and <strong>handles any necessary updates or scaling.</strong></li><li>Kubernetes monitors the <strong>health of the Pods</strong> managed by a Deployment. If a Pod fails or becomes unresponsive,<strong> Kubernetes automatically replaces it to maintain the desired number of replicas.</strong></li></ul><h3>Step 6: Create a Deployment</h3><blockquote><em>deployment.yml</em></blockquote><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-django-app-deployment<br>  labels:<br>    app: django-app<br>  namespace: my-django-app<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: django-app<br>  template:<br>    metadata:<br>      labels:<br>        app: django-app<br>    spec:<br>      containers:<br>      - name: django-app-container<br>        image: trajendra/django-todo:latest<br>        ports:<br>        - containerPort: 8000</pre><p>In Manifest, we have declared</p><p>kind: Defines the type of resource, which is a Deployment in this case.</p><p>selector: Specifies the labels used to select which Pods are part of this Deployment.</p><ul><li>matchLabels: Defines the labels that Pods must have to be considered part of the Deployment. In this case, Pods with the label app: django-app will be included.</li><li>replicas: Defines the desired number of replicas (Pods) to maintain, set to 3 in this example.</li><li>template: Defines the Pod template used to create the Pods managed by the Deployment.</li></ul><p>spec: Specifies the specifications for the Pods created from the template.</p><pre>kubectl apply -f deployment.yml  # run the deployment</pre><pre>kubectl get pods -n=my-django-app  # get the list of pods in namespace</pre><p>You can then use the kubectl apply command to create or update the Deployment in your Kubernetes cluster.</p><p>To get the pods created inside a namespace kubectl get pods -n=my-django-app .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*-uO9ojuyhZQYckfD.png" /></figure><h3>Scale</h3><blockquote><em>It is used to scale number of replicas(Pods) in the Deployments</em></blockquote><h3>Task 3: Create 10 replicas using Kubernetes CLI commands</h3><pre>kubectl scale deployment my-django-app-deployment --replicas=10 -n=my-django-app</pre><ul><li>--replicas=10: Sets the desired number of replicas (Pods) to 10. This means that Kubernetes will adjust the number of Pods in the Deployment to match this value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JIqDValCUPz6TWdm.png" /></figure><blockquote><em>It has created 10 pods in Cluster</em></blockquote><h3>Service</h3><blockquote><em>You have a deployment with multiple pods running a web application. Each pod has its own IP address, which can change dynamically. If you expose these pods directly to clients, the clients would need to keep track of each pod’s IP address and handle potential changes. This approach becomes impractical as the number of pods scales up or down. To solve this problem, you can create a service.</em></blockquote><h3>It provides a way to expose your application running in Pods to other services or external users within the cluster.</h3><h3>Step 7: Expose your application to external users</h3><blockquote><em>service.yml</em></blockquote><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: my-django-app-service<br>  namespace: my-django-app<br>spec:<br>  type: NodePort<br>  selector:<br>    app: django-app<br>  ports:<br>      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.<br>    - port: 80<br>      targetPort: 8000<br>      # Optional field<br>      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)<br>      nodePort: 30009</pre><blockquote><em>NodePort: Exposes the Service on a port across each cluster node’s IP. Allows external access to the Service. We are using NodePort (</em>30000–32767<em>) range of IP allowed.</em></blockquote><ul><li>port: Specifies the port number on the Service itself. In this case, it is set to 80.</li><li>targetPort: Specifies the port number on the Pods that the Service should forward traffic to. In this example, it is set to 8000</li><li>nodePort: 30009 : it is set to 30009, meaning that traffic arriving at nodeIP:30009 will be directed to the Service.</li></ul><pre>kubectl apply -f service.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VAl6p0JkMKueLczd.png" /></figure><p>Edit the inbound rule in the security group of the EC2 instance and click on save rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VHS0Cgch_sfdX0X3.png" /></figure><h3>Access the Application</h3><p>To access the application: http://&lt;public_ip_of_instance&gt;:30009</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*AF6Lk1mrb0lCEoz3.png" /></figure><blockquote><em>Well, Done! we have successfully deployed a todo application on Kubernetes Cluster.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Ivc69l5-ETjYxrFQ.png" /></figure><h3>To Delete the Deployment</h3><pre>kubectl delete -f deployment.yml</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ecd4f8c7ac8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kuberneties project]]></title>
            <link>https://medium.com/@jangirhemant53/kuberneties-ingress-project-823d99217684?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/823d99217684</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Fri, 15 Dec 2023 07:15:11 GMT</pubDate>
            <atom:updated>2023-12-16T04:03:59.636Z</atom:updated>
            <content:encoded><![CDATA[<h3>with Djnago-app deployment</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37ruKibAiFZbxrRsQBh7Sw.jpeg" /></figure><p><em>In this blog post, we’ll walk you through the step-by-step process of deploying applications on Kubernetes, the popular container orchestration platform.</em></p><h3>What is Kubernetes?</h3><p><strong>Kubernetes</strong> is an open-source <strong>Orchestration</strong> <strong>tool</strong>(clustering of any number of containers running on different networks) or we can say <strong>container management tool</strong> which automates container deployment, container scaling and load balancing.</p><p>It schedules, runs and manages isolated containers which are running on virtual/physical/ cloud machines.</p><p>Kubernetes main role managing containers. But what are <strong>containers</strong>? Containers hold the entire packages that is needed to run the application. In other words, we can say that the image is a template and the container is a copy if that template.</p><blockquote><em>Let’s deploy our django application using kubernetes.</em></blockquote><p>Note: Please follow the steps for deployment</p><h3>Step 1: Pre-requisites:</h3><p>Installation of Kubernetes on master and worker nodes:</p><p><a href="https://github.com/RishikeshOps/Scripts/blob/main/k8sss.sh?source=post_page-----855b4b7e7cca--------------------------------">Scripts/k8sss.sh at main · RishikeshOps/Scripts</a></p><h3>Step 2: Clone a repository</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*FC1nP6141PpWKBAq.png" /></figure><pre>git clone https://github.com/tejashreeSalvi/django-todo-cicd.git</pre><p>Let’s look into the docker file in this repository:</p><pre>FROM python:3</pre><pre>WORKDIR /data</pre><pre>RUN pip install django==3.2</pre><pre>COPY . .</pre><pre>RUN python manage.py migrate</pre><pre>EXPOSE 8000</pre><pre>CMD [&quot;python&quot;,&quot;manage.py&quot;,&quot;runserver&quot;,&quot;0.0.0.0:8000&quot;]</pre><p>It’s a Django application running on port number 8000 and the entry point to the application is manage.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Ustk2JUkdzGVpqp5.png" /></figure><h3>What are Containers?</h3><p>Containers are a runtime environment where your application code, with dependencies, is packaged and executed.</p><blockquote><em>Containers are created from images.</em></blockquote><h3>Step 3: Build an Image from Dockerfile</h3><pre>docker build . -t trajendra/django-todo:latest</pre><ul><li>Go to the repository cd django-todo and run the above command to create an image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*h_6O76B7YcF7TJEC.png" /></figure><ul><li>Run the docker images command to get the list of images.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*H5EF01_Gf8sFKUWo.png" /></figure><p><strong><em>The image is successfully created.</em></strong></p><h3>Step 4: Push the docker image to a Registry</h3><ul><li>Login to the docker hub</li></ul><pre>docker login</pre><p>After running the command it will prompt for username and password. Enter the details and you are successfully logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*1QA91UMTdN87W8Of.png" /></figure><ul><li>Push the image to registry</li></ul><pre>docker push trajendra/django-todo:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Z0haakMNDUub14Vl.png" /></figure><ul><li>Verify whether we have successfully been able to push the docker image to the registry.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*CWOzc4J1JVy0uMR5.png" /></figure><blockquote><em>WoW ! You have successfully created the image and pushed to registry. We will be creating containers from this image.</em></blockquote><h3>There are primary two ways to create and manage resources:</h3><ol><li>Command-Line Interface</li><li>YAML Manifests</li></ol><h3>Command-Line Interface:</h3><p>The Kubernetes CLI referred to as kubectl is a tool that allows you to interact with the Kubernetes Cluster. It provides a set of commands to create, modify, and manage Kubernetes resources</p><p>For example:</p><blockquote><em>kubectl create to create a resource, </em><em>kubectl edit or </em><em>kubectl patch to modify the resource and </em><em>kubectl delete to delete any resources, </em><em>kubectl get pods to get all the pods in the default namespace. There are many more commands.</em></blockquote><h3>YAML Manifests:</h3><p>YAML manifests are configuration files written in YAML. These files define the desired state of Pods, Deployments, ConfigMaps, Secret, and many more.</p><blockquote><em>We will be using YAML Manifests to deploy our application.</em></blockquote><h3>What is Pods?</h3><blockquote>The code of our application runs inside containers, which are encapsulated within Pods in Kubernetes.</blockquote><ul><li>A Pod can <strong>contain one or more containers</strong>, and all the containers <strong>share the same resources</strong> such as CPU, memory, and storage</li><li>Pods have their <strong>own unique IP address</strong> within the cluster, enabling other Pods or services to communicate with them.</li><li>Pods in Kubernetes are considered ephemeral, meaning they can be <strong>created, scaled, or terminated dynamically</strong> based on the desired state of the system.</li></ul><blockquote><em>1 Pod = 1 container is recommendand as best practices.</em></blockquote><h3>Task 1: Create your First Pod.</h3><p>We will be creating a single pod using the YAML Manifests.</p><blockquote><em>pod.yml</em></blockquote><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: django-app<br>spec:<br>  containers:<br>  - name: django-app<br>    image: trajendra/django-todo:latest<br>    ports: <br>    - containerPort: 8000</pre><p>In pod.yml file,</p><ul><li>apiVersion: v1 specifies the Kubernetes API version being used.</li><li>kind: Pod indicates that you are creating a Pod object.</li><li>metadata contains metadata about the Pod, including its name.</li><li>spec defines the desired state of the Pod.</li><li>containers is an array of container objects running inside the Pod. In this case, there is only one container.</li><li>name: crud-backend-app sets the name of the container to &quot;crud-backend-app&quot;.</li><li>image: trajendra/crudbackend:latest specifies the Docker image to be used for the container. In this case, it uses the image &quot;trajendra/django-todo&quot; with the &quot;latest&quot; tag.</li><li>ports defines the network ports that the container exposes. In this example, it exposes port 8000.</li></ul><pre>kubectl apply -f pod.yml</pre><p>Run this command, Kubernetes will read our YAML file, and update any resources in our cluster accordingly. To see the newly created pod in action, you can run kubectl get pods. You should see the pod running.</p><blockquote><em>Worker nodes are the machines in the Kubernetes cluster where Pods are scheduled and containers are run</em></blockquote><ul><li>Connect to Worker Node to verify if the container is successfully created.</li></ul><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ETVVVRPf0y6J2SD9.png" /></figure><ul><li>Let’s go inside the container and execute the curl command</li></ul><pre>docker exec -it 3551dae bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*8wU0KTRQbuYxKvuK.png" /></figure><blockquote><em>Hey ! We have successfully been able to create containers via pod using YAML Manifests</em></blockquote><h3>Namespaces</h3><p>Namespaces are logical groups created inside a Cluster. They allow multiple teams or applications to co-exist in the same cluster.</p><blockquote><em>Each namespace has its own set of resources, including Pods, Services, Deployments, ConfigMaps, and more.</em></blockquote><ul><li>By default, Kubernetes provides a default namespace where resources are created if no specific namespace is specified</li><li>You can define RBAC (Role-Based Access Control) policies to grant different levels of access to resources based on namespaces.</li></ul><h3>Step 5: Create a Namespace</h3><pre>kubectl create namespace my-django-app</pre><p>We will be creating my-django-app namespace for our application to include all the pods, services, deployment, and containers in this namespace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*lX-5SkzEoayL3_WX.png" /></figure><h3>Task 2: Create a Pod inside the Namespace</h3><blockquote><em>pod.yml</em></blockquote><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: django-app<br>  namespace: my-django-app<br>spec:<br>  containers:<br>  - name: django-app<br>    image: trajendra/django-todo:latest<br>    ports: <br>    - containerPort: 8000</pre><ul><li>To create the pod run the following command:</li></ul><pre>kubectl apply -f pod.yml</pre><ul><li>To verify the pods created inside the namespace</li></ul><pre>kubectl get pods -n=my-django-app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VkaCwwXL8qYkJpRk.png" /></figure><h3>Deleting a Pod</h3><pre>kubectl delete -f pod.yml</pre><p>Here, the pod will be deleted from the namespace my-django-app .</p><p>As we have added a namespace added in the metadata.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*pAngJvAAji3BA6cZ.png" /></figure><blockquote><em>We just learned to create a pod inside the namespace.</em></blockquote><h3>Deployment</h3><blockquote><em>Our app runs inside kubernetes cluster. Application consists of multiple pods, each representing a component of the application. Instead of manually creating and managing individual pods for your application, you can use a deployment.</em></blockquote><ul><li>It ensures that the<strong> desired number of replicas of each component</strong> is always available and <strong>handles any necessary updates or scaling.</strong></li><li>Kubernetes monitors the <strong>health of the Pods</strong> managed by a Deployment. If a Pod fails or becomes unresponsive,<strong> Kubernetes automatically replaces it to maintain the desired number of replicas.</strong></li></ul><h3>Step 6: Create a Deployment</h3><blockquote><em>deployment.yml</em></blockquote><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-django-app-deployment<br>  labels:<br>    app: django-app<br>  namespace: my-django-app<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: django-app<br>  template:<br>    metadata:<br>      labels:<br>        app: django-app<br>    spec:<br>      containers:<br>      - name: django-app-container<br>        image: trajendra/django-todo:latest<br>        ports:<br>        - containerPort: 8000</pre><p>In Manifest, we have declared</p><p>kind: Defines the type of resource, which is a Deployment in this case.</p><p>selector: Specifies the labels used to select which Pods are part of this Deployment.</p><ul><li>matchLabels: Defines the labels that Pods must have to be considered part of the Deployment. In this case, Pods with the label app: django-app will be included.</li><li>replicas: Defines the desired number of replicas (Pods) to maintain, set to 3 in this example.</li><li>template: Defines the Pod template used to create the Pods managed by the Deployment.</li></ul><p>spec: Specifies the specifications for the Pods created from the template.</p><pre>kubectl apply -f deployment.yml  # run the deployment</pre><pre>kubectl get pods -n=my-django-app  # get the list of pods in namespace</pre><p>You can then use the kubectl apply command to create or update the Deployment in your Kubernetes cluster.</p><p>To get the pods created inside a namespace kubectl get pods -n=my-django-app .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*-uO9ojuyhZQYckfD.png" /></figure><h3>Scale</h3><blockquote><em>It is used to scale number of replicas(Pods) in the Deployments</em></blockquote><h3>Task 3: Create 10 replicas using Kubernetes CLI commands</h3><pre>kubectl scale deployment my-django-app-deployment --replicas=10 -n=my-django-app</pre><ul><li>--replicas=10: Sets the desired number of replicas (Pods) to 10. This means that Kubernetes will adjust the number of Pods in the Deployment to match this value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JIqDValCUPz6TWdm.png" /></figure><blockquote><em>It has created 10 pods in Cluster</em></blockquote><h3>Service</h3><blockquote><em>You have a deployment with multiple pods running a web application. Each pod has its own IP address, which can change dynamically. If you expose these pods directly to clients, the clients would need to keep track of each pod’s IP address and handle potential changes. This approach becomes impractical as the number of pods scales up or down. To solve this problem, you can create a service.</em></blockquote><h3>It provides a way to expose your application running in Pods to other services or external users within the cluster.</h3><h3>Step 7: Expose your application to external users</h3><blockquote><em>service.yml</em></blockquote><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: my-django-app-service<br>  namespace: my-django-app<br>spec:<br>  type: NodePort<br>  selector:<br>    app: django-app<br>  ports:<br>      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.<br>    - port: 80<br>      targetPort: 8000<br>      # Optional field<br>      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)<br>      nodePort: 30009</pre><blockquote><em>NodePort: Exposes the Service on a port across each cluster node’s IP. Allows external access to the Service. We are using NodePort (</em>30000–32767<em>) range of IP allowed.</em></blockquote><ul><li>port: Specifies the port number on the Service itself. In this case, it is set to 80.</li><li>targetPort: Specifies the port number on the Pods that the Service should forward traffic to. In this example, it is set to 8000</li><li>nodePort: 30009 : it is set to 30009, meaning that traffic arriving at nodeIP:30009 will be directed to the Service.</li></ul><pre>kubectl apply -f service.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VAl6p0JkMKueLczd.png" /></figure><p>Edit the inbound rule in the security group of the EC2 instance and click on save rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VHS0Cgch_sfdX0X3.png" /></figure><h3>Access the Application</h3><p>To access the application: http://&lt;public_ip_of_instance&gt;:30009</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*AF6Lk1mrb0lCEoz3.png" /></figure><blockquote><em>Well, Done! we have successfully deployed a todo application on Kubernetes Cluster.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Ivc69l5-ETjYxrFQ.png" /></figure><h3>To Delete the Deployment</h3><pre>kubectl delete -f deployment.yml</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=823d99217684" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kuberneties interview ques]]></title>
            <link>https://medium.com/@jangirhemant53/kuberneties-interview-ques-c112c8e5f0cc?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c112c8e5f0cc</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 13:18:18 GMT</pubDate>
            <atom:updated>2023-12-16T04:08:20.994Z</atom:updated>
            <content:encoded><![CDATA[<h3>jenkins question</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c112c8e5f0cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DOCKER interview question]]></title>
            <link>https://medium.com/@jangirhemant53/jenkins-interview-question-c8e904a3766f?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8e904a3766f</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 13:14:32 GMT</pubDate>
            <atom:updated>2023-12-19T13:09:16.850Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>What is <strong>Docker</strong>?</li></ol><p>➢ Docker is an <strong>an open platform for</strong> designed to create, deploy and run applications.<br>➢ Docker <strong>uses container</strong> on the host <strong>OS to run applications</strong>. It allows applications to use same Linux kernel as a system on the host computer rather than creating a whole virtual OS.<br>➢ We can <strong>install docker on any OS</strong> but <strong>docker engine runs natively on Linux distributions</strong>.<br>➢ Docker <strong>written in “GO”</strong> programming language.<br>➢ Docker is a tool that performs <strong>OS level virtualization</strong> also known as <strong>Containerization</strong>.<br>➢ Before docker many users face the problem that a particular code is running in the developer’s system but not in the user’s system.<br>➢ Docker was first <strong>release in 2013</strong>. It is developed by Solomon Hykes and Sebastian Pahl.<br>➢ Docker is a set of <strong>Platform-as-a-Service that uses OS level virtualization</strong> whereas VMWare uses hardware level of virtualization.</p><p><strong>PAAS: PAAS </strong>offers a <strong>ready-made environment</strong> that <strong>includes all tools</strong>, services, and a runtime <strong>for developers to build</strong>, <strong>deploy, and scale applications</strong> more efficiently.</p><p><strong>containerization: </strong>Docker <strong>containerization</strong> is a process that allows developers to package their applications and their dependencies together in a single container. This container can then be easily shipped and deployed on any platform that supports them. This makes it easier to deploy and run applications in different environments.</p><p><strong>Advantages</strong> of Docker:<br>➢ No pre allocation of RAM.<br>➢ CI efficiency: — docker enables you to build a container image and use that same image across every step of the deployment process.<br>➢ Less cost.<br>➢ It is light in weight.<br>➢ It can run on physical h/w / virtual h/w or on cloud.<br>➢ You can reuse this image.<br>➢ It took very less time to create container.</p><p><strong>Disadvantages</strong> of Docker:<br>➢ Docker is not a good solution for application that requires rich GUI.<br>➢ Difficult to manage large number of containers.<br>➢ Docker doesn’t provide cross platform compatibility means if an application is designed to run in a docker container in windows than it can’t run in Linux or vice-versa.<br>➢ Docker is suitable when the development O.S and testing O.S are same. If the O.S are different then we should use VM.<br>➢ No solution for data recovery and backup.</p><p><strong>Components of Docker</strong>:<br>1. <strong>Docker Daemon: </strong>background process. and manage container.<br>2. <strong>Docker Client</strong><br>3. <strong>Docker Host</strong>:<br>4. <strong>Docker Hub/ Registry</strong>:<br>➢ Docker registry manages and stores the docker image.<br>➢ There are two types of registries in the docker:<br>a. Public Registry: it is also called as docker hub.<br>b. Private Registry: it is used to share image with in the enterprise.<br>5. <strong>Docker Image</strong>:<br>➢ <strong>Single file</strong> with <strong>all the dependencies</strong> and configuration <strong>required to run</strong> a program.<br>or<br>➢ Docker image is a <strong>read-only file</strong> or a template with a set of instructions that is used to create a container. Usually, we used to create a docker image from a file that’s called a Dockerfile.<br><strong>Ways to Create an Image</strong>:<br>a. Take image from the docker hub.<br>b. Create image from docker file.<br>c. Create image from existing docker containers.</p><p>6. <strong>Docker Containers:</strong><br>➢Containers are like small packages that hold everything an application needs to run. To create these containers, developers use something called a Dockerfile.<br>Or<br>➢ In other words, we can say that the image is a template and the container is a copy of that template.<br>➢ Container is like a virtual machine.<br>➢ Images becomes container when they run on docker engine.</p><ol><li>docker d(docker demon)- background process. and manage container.</li><li>docker CLI- you can access everythin using cmd line inref.(CLI)</li></ol><p>Dockers can run multiple applications or multiple instances of a single application. It does this with containers.</p><p><strong>Hypervisor</strong>: A hypervisor is a piece of software or firmware that creates and runs virtual machines on the top of your OS. or A hypervisor allows the users to generate multiple instances of complete operating systems.</p><p><strong>Firmware</strong>: directly run on hardware.</p><p><strong>Software</strong>: install on any <strong>OS</strong>.</p><h3><strong>Dockerfile:</strong></h3><p><strong>Dockerfile</strong> is basically a text file. It contains some set of instructions. Automation of docker image creation.<br><strong>Dockerfile components</strong>:<br><strong>FROM</strong>: for base image, this command must be on the top of the dockerfile. eg: <strong>FROM ubuntu:20.4</strong><br><strong>WORKDIR</strong>: working dir. where all code will be kept. eg: <strong>WORKDIR /app</strong><br><strong>COPY</strong>: copy files from local system (docker vm) we need to provide source, destination (we can’t download file from internet and any remote repo.). eg: <strong>WORKDIR </strong>. .<br><strong>RUN</strong>: to execute commands, it will create a layer in image. eg: <strong>RUN apt-get install Flask</strong><br><strong>ADD</strong>: similar to copy but it provides a feature to download files from internet, also extract file at docker image side.<br><strong>EXPOSE</strong>: to expose out side the container. eg: <strong>EXPOSE 5000</strong><br><strong>CMD</strong>: execute commands but during container creation. eg: <strong>CMD [“python”, “app.py”]. </strong>Whatever command you want to run just keep it inside of this [] bracket as per the example.<br><strong>ENTRYPOINT</strong>: similar to CMD, Sets default parameters that cannot be overridden while executing Docker containers with CLI parameters.<br><strong>ENV</strong>: environment variables. eg: <strong>ENV env_name xyz</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8e904a3766f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Devops interview question]]></title>
            <link>https://medium.com/@jangirhemant53/devops-interview-question-cf5aa6e44f76?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf5aa6e44f76</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 13:13:43 GMT</pubDate>
            <atom:updated>2023-12-18T19:03:14.350Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>What is <strong>Devops</strong>?</li></ol><p>DevOps is a methodology where development and operation team colloborate to deliver the product faster and better. For that we have used many tools and services. like — Git&amp;github, docker, jankins , k8s, terraform, aws etc.</p><p>The <strong>objective</strong> of devops is to shorten the system’s devlopment life cycle.</p><p>2. What is the Difference between an Image, Container and Engine?</p><p>An Image is a pre-configured file system containing all required files, libraries, dependencies to run an application.</p><p>A Container is a running instance of an Image, which runs in an isolated environment with its own file system, networking, and resources.</p><p><strong>Docker Engine</strong> : Is the service (PAAS), which allow you to run any container like- linux, window, mac os etc. on the top of your OS.It is lite waight.Doen’t have own kernal(it’s use OS kernal). intall docker engine command is -</p><pre>sudo apt install docker.io</pre><p>Docker engine two main components -</p><ol><li>docker d(docker demon)- background process. and manage container.</li><li>docker CLI- you can access everythin using cmd line inref.(CLI)</li></ol><p>Dockers can run multiple applications or multiple instances of a single application. It does this with containers.</p><p><strong>Hypervisor</strong>: A hypervisor is a type of computer software, firmware, or hardware that creates and runs virtual machines on the top of your OS.</p><p>A hypervisor allows the users to generate multiple instances of complete operating systems.</p><p>3. What is the Difference between the Docker command COPY vs ADD?</p><p>The COPY and ADD commands in Dockerfiles serve the same purpose, which is to copy files from the host system into a Docker image. The main difference is that ADD has some additional functionality:</p><ul><li>ADD supports automatically unpacking compressed files (such as tar files) from the host into the Docker image.</li><li>ADD can fetch files from a URL and copy them into the Docker image.</li></ul><p>Otherwise, COPY is the preferred command in modern Dockerfiles because it is more transparent and predictable than ADD.</p><p>4. What is the Difference between the Docker command CMD vs RUN?</p><p>The CMD and RUN commands in Dockerfiles serve different purposes:</p><p>RUN command is used to execute a command during the image building process. The command gets executed and the result is committed to the image.</p><p>CMD command specifies the command that should be run when a container is started from the image. It provides default arguments for an executing container. If a user specifies command line arguments when starting a container, the CMD value will be overwritten.</p><p>In summary, RUN is used to build the image and CMD is used to specify the default command that should be run when a container is started from the image.</p><p>4. How Will you reduce the size of the Docker image?</p><p>There are several ways to reduce the size of a Docker image:</p><ul><li>Multi-stage builds: Use multiple Dockerfiles in a multi-stage build process to only include the final required artifacts in the final image, discarding intermediate build artifacts and unused files.</li><li>Use smaller base images: Select base images with the smallest possible size, for example, using Alpine Linux instead of full-featured distributions like Ubuntu.</li><li>Minimize the number of installed packages: Only install the packages required for the application to run, removing unnecessary packages and dependencies.</li><li>Remove unnecessary files: Remove files like test files, debug symbols, and documentation that are not needed in production.</li><li>Use image optimization tools: There are several image optimization tools that can further reduce the image size by removing duplicates, compressing files, and optimizing file systems.</li></ul><p>By following these best practices, you can reduce the size of a Docker image and improve its performance.</p><p>5. Why and when to use Docker?</p><p>Docker is used to containerize applications, providing a consistent and reproducible environment for development, testing, and deployment. Here are some reasons why and when to use Docker:</p><ul><li>Isolation: Docker containers provide isolated environments for each application, ensuring that applications run consistently across different environments.</li><li>Portability: Docker images can be easily moved between environments, allowing developers to quickly spin up new instances of an application on any platform that supports Docker.</li><li>Scalability: Docker containers can be easily scaled horizontally by adding more instances, making it simple to accommodate increased traffic or demand.</li><li>Ease of deployment: Docker containers can be deployed on any platform that supports Docker, making it easy to deploy an application consistently across different environments.</li><li>Environment consistency: Docker containers ensure that an application runs consistently across different environments, making it easier to test and deploy applications.</li></ul><p>In summary, use Docker when you need to run an application consistently across different environments, or when you need to easily scale an application to accommodate increased demand. Docker is also useful for deploying applications quickly and consistently across different environments.</p><p>6. Explain the Docker components and how they interact with each other.</p><p>Docker has several components that interact with each other to provide a complete platform for building, deploying, and running containers. These components are:</p><ul><li>Docker Daemon: The Docker Daemon is the core component of Docker, responsible for building, running, and managing containers. It communicates with other components through the Docker API.</li><li>Docker CLI: The Docker CLI is a command-line interface for interacting with the Docker Daemon. Users can use the CLI to build, run, and manage containers.</li><li>Docker Images: Docker Images are snapshots of a file system that contain all the files and dependencies needed to run an application. They are stored in a registry and can be used to create new containers.</li><li>Docker Registries: Docker Registries are repositories for storing and distributing Docker Images. The most well-known registry is Docker Hub, but users can also set up their own private registries.</li><li>Docker Containers: Docker Containers are instances of Docker Images that run as isolated processes on a host system. They provide a consistent environment for running applications.</li></ul><p>In summary, these components interact with each other to provide a complete platform for building, deploying, and running containers. The Docker CLI communicates with the Docker Daemon to build and manage containers, using images stored in a registry. The Docker Daemon runs containers, providing isolated environments for running applications.</p><p>7. Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container?</p><p>The following are common terms used in Docker:</p><ul><li>Docker File: A Docker File is a script that contains instructions for building a Docker Image. It specifies the base image, files to be copied, and commands to run when building the image.</li><li>Docker Image: A Docker Image is a snapshot of a file system that contains all the files and dependencies needed to run an application. It is created from a Docker File and can be used to create new containers.</li><li>Docker Container: A Docker Container is an instance of a Docker Image that runs as an isolated process on a host system. It provides a consistent environment for running applications.</li><li>Docker Compose: Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to define the services, networks, and volumes for an application, and it can be used to start and stop the application with a single command.</li></ul><p>8. In what real scenarios have you used Docker?</p><p>I have used Docker in a variety of scenarios including microservices architecture, continuous integration and delivery, and development environments.</p><p>9. Docker vs Hypervisor?</p><p>Docker and hypervisors are both technologies for virtualization, but they have different design goals and use cases:</p><ul><li>Docker: Docker is designed for application virtualization, where each application runs in its own container. Containers share the host operating system, making them lightweight and efficient. Docker is ideal for microservices and cloud-based deployments.</li><li>Hypervisor: A hypervisor is a layer of software that allows multiple virtual machines to run on a single physical machine. Each virtual machine runs its own operating system and has its own resources, making it ideal for server virtualization and multi-tenant environments.</li></ul><p>In summary, Docker and hypervisors are both virtualization technologies, but they have different design goals and use cases. Docker is designed for application virtualization, while hypervisors are designed for server virtualization. The choice between the two depends on the specific requirements of the application and the environment in which it runs.</p><p>10. What are the advantages and disadvantages of using docker?</p><p>Advantages of using Docker:</p><ul><li>Portability: Docker containers can run on any host with a Docker engine, making it easy to move applications between development, testing, and production environments.</li><li>Isolation: Docker containers run in isolated environments, ensuring that applications do not interfere with each other and reducing the risk of security vulnerabilities.</li><li>Scalability: Docker containers can be easily scaled up or down to meet changing demands, making it easy to handle spikes in traffic or changing workloads.</li><li>Efficiency: Docker containers are lightweight, using fewer resources than traditional virtual machines.</li><li>Ease of use: Docker provides an easy-to-use platform for building, shipping, and running applications, making it accessible to a wide range of users.</li></ul><p>Disadvantages of using Docker:</p><ul><li>Complexity: Docker can add complexity to an application, especially when deploying multi-container applications.</li><li>Performance overhead: The overhead of running containers can be higher than running applications directly on a host, especially for resource-intensive applications.</li><li>Security concerns: Docker containers share the host operating system, making it important to secure the host and to properly isolate containers from each other to reduce the risk of security vulnerabilities.</li><li>Learning curve: Docker requires a certain level of knowledge and understanding to use effectively, making it a steep learning curve for some users.</li></ul><p>11. What is a Docker namespace?</p><p>A Docker namespace is a feature of the Docker engine that provides isolated environments for running containers. Each namespace provides a separate view of system resources, such as the network, process tree, and file system, allowing multiple containers to run on the same host without interfering with each other.</p><p>Docker provides several types of namespaces, including the following:</p><ul><li>PID namespace: The PID namespace isolates the process tree, allowing each container to have its own process hierarchy.</li><li>Network namespace: The network namespace isolates network resources, such as network interfaces and IP addresses, allowing each container to have its own network configuration.</li><li>Mount namespace: The mount namespace isolates the file system, allowing each container to have its own file system hierarchy.</li><li>User namespace: The user namespace isolates user and group IDs, allowing containers to run with different user and group permissions.</li></ul><p>By using namespaces, Docker provides a secure and isolated environment for running containers, allowing multiple containers to run on the same host without interfering with each other. This makes it easier to run multiple applications on a single host, improving resource utilization and reducing the need for additional hardware.</p><p>12. What is a Docker registry?</p><p>A Docker registry is a repository for storing and distributing Docker images. A Docker registry acts as a central location for storing and sharing Docker images, making it easy to share and distribute images between different environments and teams.</p><p>Docker provides a public registry, Docker Hub, where users can store and share images with the wider Docker community. Docker Hub is free to use, but it has limited storage and bandwidth capabilities. There are also several commercial registry services available, such as AWS Elastic Container Registry (ECR), Google Container Registry (GCR), and Azure Container Registry (ACR), which provide additional storage and bandwidth capabilities, as well as advanced security and management features.</p><p>To use a Docker registry, images can be pushed to the registry from a local machine or build environment, and then pulled from the registry and run on any host with a Docker engine. This makes it easy to share and distribute images, as well as automate the deployment of applications.</p><p>13. What is an entry point?</p><p>An entry point in Docker is a command that is automatically executed when a container is started. The entry point command is specified in the Dockerfile using the CMD or ENTRYPOINT instructions.</p><p>The CMD instruction specifies the default command to be executed when a container is started. If a different command is specified when starting the container, it will override the default command specified in the CMD instruction.</p><p>The ENTRYPOINT instruction, on the other hand, specifies a command that must be executed when a container is started, and any command specified when starting the container will be passed as arguments to the ENTRYPOINT command.</p><p>The entry point is used to specify the default behavior of a container, and it can be used to configure the container to run a specific application or service when it is started. The entry point also provides a convenient way to run multiple commands or start a service in the background when a container is started.</p><p>14. How to implement CI/CD in Docker?</p><p>CI/CD (Continuous Integration and Continuous Deployment) in Docker involves automating the process of building, testing, and deploying Docker applications. Here are the general steps to implement CI/CD in Docker:</p><ul><li>Source control: Store the code and related files in a source control repository such as Git. This allows for version control and collaboration between team members.</li><li>Continuous Integration (CI): Automate the build process using a CI tool such as Jenkins or TravisCI. The CI tool will build the Docker image from the code in the source control repository and run automated tests on the image.</li><li>Automated testing: Automate the testing of the Docker image using a testing framework such as JUnit or TestNG. The tests can be run in parallel on multiple containers to validate the application.</li><li>Docker registry: Store the built Docker images in a Docker registry, such as Docker Hub or a private registry. This makes it easy to distribute the images to other environments for deployment.</li><li>Continuous Deployment (CD): Automate the deployment process using a CD tool such as Jenkins, TravisCI, or AWS CodeDeploy. The CD tool will deploy the Docker images stored in the registry to the production environment.</li><li>Monitoring: Monitor the deployed application and containers to ensure that they are running as expected.</li></ul><p>15. Will data on the container be lost when the docker container exits?</p><p>By default, data in a Docker container is not persisted when the container exits. When a container stops, the file system, network configuration, and other state information are deleted, and all changes made to the container are lost.</p><p>However, there are ways to persist data even after a container has exited. One way to do this is to use Docker volumes, which allow you to store data on the host file system and mount it into the container. When a container is deleted, the volume still exists and can be used by another container.</p><p>Another way to persist data is to use data volumes in the Dockerfile. You can use the VOLUME instruction to specify which directories in the container should be treated as data volumes, and then use the — mount or -v option when starting the container to map the data volume to a directory on the host file system.</p><p>In summary, data in a Docker container is not persisted by default when the container exits, but you can use Docker volumes or data volumes to persist data even after a container has exited.</p><p>16. What is a Docker swarm?</p><p>Docker Swarm is a native orchestration solution for Docker containers, providing the ability to manage and deploy containers at scale. It allows you to turn a group of Docker engines into a single virtual Docker engine, making it easier to manage and orchestrate containers across multiple hosts.</p><p>A Docker Swarm cluster is composed of a set of Docker engines, each running on its own host. The Docker engines work together to form a swarm, and the swarm manager nodes coordinate the deployment and management of containers across the swarm.</p><p>With Docker Swarm, you can:</p><ul><li>Easily scale your applications: You can easily scale your applications by adding or removing nodes to the swarm, and the swarm manager will automatically distribute containers across the available nodes.</li><li>Load balance containers: Docker Swarm automatically load balances traffic between containers, ensuring that your applications are always available and responsive.</li><li>Manage the entire lifecycle of containers: You can use Docker Swarm to manage the entire lifecycle of containers, from deployment to scaling to removal.</li><li>Offer high availability: Docker Swarm ensures high availability by automatically rescheduling containers on healthy nodes in the event of a node failure.</li></ul><p>In summary, Docker Swarm is a native orchestration solution for Docker containers that makes it easier to manage and deploy containers at scale, offering features such as automatic scaling, load balancing, and high availability.</p><p>17. What are the docker commands for the following:</p><ul><li>view running containers:</li></ul><p>- docker ps</p><ul><li>command to run the container under a specific name:</li></ul><p>- docker run –name &lt;name&gt; &lt;image&gt;</p><ul><li>command to export a docker:</li></ul><p>- docker export &lt;container&gt; &lt;filename&gt;</p><ul><li>command to import an already existing docker image:</li></ul><p>- docker import &lt;filename&gt; &lt;repository:tag&gt;</p><ul><li>commands to delete a container:</li></ul><p>- docker rm &lt;container&gt;</p><ul><li>command to remove all stopped containers, unused networks, build caches, and dangling images:</li></ul><p>- Docker system prune</p><p>18. What are the common docker practices to reduce the size of Docker Image?</p><p>Common practices to reduce the size of Docker images include: using multi-stage builds, removing unnecessary files and dependencies, using smaller base images, using a .dockerignore file, squashing multiple layers, using a caching mechanism, version pinning and using image scanning and vulnerability analysis tools. While these practices can help reduce the size of images, it’s important to consider the impact on the functionality of the application.</p><p>Q. What is Automation, Scaling, Infrastructure ?</p><p><strong>Automation</strong> involves automating the entire software delivery process, from code creation to testing, deployment, and monitoring. <strong>Scaling</strong> involves designing and implementing systems that can handle increased load and traffic. <strong>Infrastructure</strong> involves designing and managing the hardware and software required to run applications and services. By leveraging automation, scaling, and infrastructure, teams can deliver software that meets user requirements, at scale and with high quality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf5aa6e44f76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git & github interview question]]></title>
            <link>https://medium.com/@jangirhemant53/git-github-interview-question-4bbe0eaec763?source=rss-31ed259a1fd7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bbe0eaec763</guid>
            <dc:creator><![CDATA[HEMANT JANGIR]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 13:13:20 GMT</pubDate>
            <atom:updated>2023-12-19T07:36:30.258Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Git?</h3><p>Git is an open-source tool that developers install locally. It is a version control system that allows developers to track changes in their code. It was created by Linus Torvalds in 2005 maintained by linux.</p><blockquote><strong>Git</strong>: Git is a <strong>software</strong>, <strong>command-line tool, installed locally</strong> on the system,first released in <strong>2005</strong> and maintained by <strong>linux</strong>.</blockquote><h3>What is Github?</h3><p>Github is a platform or a cloud based service which allows us to host our git repositories. Just like Git, it is distributed version control system that allows you to store data, track it and collaborate on software projects.GitHub was launched in 2008 maintained by Microsoft.</p><blockquote><strong>GitHub</strong>: GitHub is a <strong>service,graphical user interface</strong>, <strong>hosted</strong> on the <strong>web, launched</strong> in <strong>2008</strong>. and maintained by <strong>Microsoft</strong>.</blockquote><h3>What is Version Control? How many types of version controls we have?</h3><p>Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.</p><p>There are two main types of version control systems: centralized version control systems and distributed version control systems.</p><ol><li>A <strong>centralized version control system</strong> (CVCS) uses a central server to store all the versions of a project’s files. Developers “check out” files from the central server, make changes, and then “check in” the updated files. Examples of CVCS include Subversion and Perforce.</li><li>A <strong>distributed version control system </strong>(<strong>DVCS</strong>) allows developers to “clone” an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include GitHub, Mercurial, and Darcs.</li></ol><h3>Why we use distributed version control over centralized version control?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*bM-UWWiHWhw5Ey3kqAe5mg.png" /></figure><ol><li>Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don’t have to constantly communicate with a central server to commit their changes or to see the changes made by others.</li><li>Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don’t have to communicate with a central server.</li><li>Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.</li><li>Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.</li></ol><p>Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.</p><h3>What is the difference Between Main Branch and Master Branch??</h3><p>There is no particular difference between the two. Main or Master is the default branch when you create a repository. In GitHub when you create a branch by default it’s set to <strong>main</strong> but you also can change it to master. Mainly GitHub changed the name from master to main as it sounds like a master-slave concept. Easy to remember as Git &gt; Local &gt; Master &amp; GitHub &gt; GUI &gt; Main.</p><h3>Explain the difference between Git and GitHub?</h3><p>Git is a version control system that allows developers to track changes in their code. GitHub is a cloud-based hosting service that allow developers manage Git repositories.</p><h3>What is difference between local &amp; remote repository?</h3><p>The main difference is that a local repository is accessible only on your local machine, while a remote repository can be accessed by multiple users and can be used for collaboration.</p><p>In Git, a local repository is a copy of the repository that is stored on your local machine <em>(You can access &amp; perform actions using Git Bash installed on your local machine)</em>, while a remote repository is a copy of the repository that is stored on a remote server, such as GitHub or GitLab.</p><h3>GIT Hands-on</h3><h3>Set your user name and email address, which will be associated with your commits.</h3><p>Here you have to put Username and password of your GitHub account</p><pre>git config --global user.name &quot;username&quot;<br>git config --global user.email &quot;username@gmail.com&quot;</pre><pre>git config --global --edit    // using nano editor set username and email</pre><p>Verify your configuration info</p><pre>git config --list</pre><h3>How to connect local to remote? [Git to GitHub Conenction]</h3><h3>Create Repository in GitHub</h3><p>1. Click on the new repository option</p><p>2. Now give a name of your repository as per your choice and a description.</p><p>3. Choose the Visibility to public /private as per your requirement.</p><p>4. Before hitting the create button you can include a README file</p><p>5. Click on Create button and a new repository will be created.’</p><h3>Access Repository from Local Machine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGq-eclO5zGvB0yCxj8jnQ.png" /></figure><ol><li>To initialize a local repo in the machine create a folder and go to that folder <em>(say /GIT_REPO)</em>. Open Git bash terminal and write the command git init. Here .git hidden folder will be created.</li></ol><pre>git init #make GIT_REPO folder as git repository</pre><p>2. Create/Add the files to your new local repository. This stages them for the first commit.</p><pre>touch file1 #create a file <br>git add file1 &amp;&amp; git commit -m &quot;added new file&quot; #perform git add &amp; commit</pre><p>3. Add the URL for the remote repository where your local repository will be pushed.</p><pre>git remote add origin &lt;URL_OF_GitHub_REPO.git&gt;</pre><p>4. Enter your username and Personal access token to push your codes to the central repo (GitHub)</p><pre>git pull           # always pull before push<br>git branch -M main<br>git branch<br><br>git push origin main     #  here you can use master or main<br><br>git push -f origin main   # forcefully push</pre><p>Using Personal access token make a origin and push code on github</p><pre>git remote -v           # show present url of github push/fetch<br>git remote set-url --add origin https://&lt;token_id&gt;&lt;githun_url&gt;<br>git remote -v          # show new git hub url for push<br><br>git remote set-url --delete origin &lt;old_url&gt;// delete the old url<br>git remote -v<br>git push origin main   #push your code on github</pre><p>make git token url and push code on github</p><pre>git push https://&lt;token_id&gt;&lt;githun_url&gt;</pre><h3>Git merge file</h3><pre>git init<br>echo &quot;this is line 1 of file1&quot; &gt; file1<br>git add file1 <br>git commit -m &quot;file1-v1&quot;<br>git checkout -b feature1<br>echo &quot;this is line1 of feature1&quot; &gt; feature1<br>git add feature1 <br>git commit -m &quot;fea1-v1&quot;<br>git log<br>git checkout master<br>ls                   // feature1 file not show in master branch<br>git merge feature1   // feature1 file merge in master branch<br><br>git branch -d feature1  // delete branch</pre><h3><strong>difference between git merge and git rebase?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*cAGZU8CKCyP6_6O85bPYbw.png" /></figure><p><strong>git merge: </strong>creates a new merge commit that combines the changes from both branches.</p><ul><li>Preserves the history in chronological order</li><li>Protects branches</li></ul><p><strong>git rebase:</strong> creates a new set of commits applied on top of the target branch.</p><ul><li>Converts complex history into a single format</li><li>Simplifies DevOps work by reducing multiple comments to a single comment.</li></ul><h3>Git create/resolve conflict</h3><pre>git init<br>echo &quot;file1 is updated 1st time&quot; &gt; file1 <br>git commit -am &quot;v1&quot;<br>git branch <br>git checkout -b feature1 <br>echo &quot;file1 is updated 2nd times&quot; &gt; file1 <br>git commit -am &quot;v2&quot;<br>git checkout master <br>git merge feature1   </pre><p>we’ve set up a merge conflict. Both branches have changes on the same line in the same file but with different content.</p><pre>vim file1 <br> &lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<br>file1 is updated 1st time    // version of the current branch (master)<br>=======<br>file1 is updated 2nd times     // version from the feature1 branch<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; feature1</pre><p>The content between &lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD and ======= is the version of the current branch (master), and the content between ======= and &gt;&gt;&gt;&gt;&gt;&gt;&gt; is the version from the feature1 branch.</p><p>Resolve the conflict: Decide which version to keep, or merge the changes manually. For instance, you can edit the file</p><pre>vim file1<br>file1 is updated 1st and 2nd times both<br>git commit -am &quot;v3&quot;<br>git status</pre><h3>Git Revert &amp; Reset</h3><p><strong>Git Revert: </strong>it is used to create a new commit that undo the changes made in a previous commit. This is different from git reset, which erases commits from the commit history. git revert is considered a safer option for undoing changes because it doesn&#39;t alter the existing commit history; instead, it adds a new commit that undoes the changes.</p><pre>cat file  // in this file 4 line and commit but we delete last line<br>line 1         ---&gt; v1 (commit)<br>line 2         ---&gt; v2 (commit)<br>line 3         ---&gt; v3 (commit)<br>line error     ---&gt; v4 (commit)<br><br>v1 -- v2-- v3-- v4(HEAD)     // commit <br><br>git revert &lt;commit_id(v4)&gt;<br><br>git log --oneline<br>v1 -- v2-- v3 -- v4 -- v5(HEAD)  Revert &quot;v4&quot;   // commit<br><br>cat file <br><br>line 1<br>line 2<br>line 3</pre><p>Remember that git revert is useful for undoing changes in a collaborative environment where you want to preserve the commit history and avoid rewriting the Git history.</p><p><strong>Git Reset: </strong>Remove Commit History</p><p>git reset command is used to reset the current HEAD to a specified state. It&#39;s used to undo changes, unstage files, or move the branch pointer to a different commit. There are three primary options for the git reset command: --soft, --mixed (default), and--hard.</p><ol><li>git reset --soft &lt;commit&gt; keeps the changes made in the commit but moves them to the staging area. It does not modify the working directory. This is useful if you want to recommit the changes with some modifications.</li></ol><pre>git reset --soft &lt;commit&gt;  // commit_id -&gt; delete and file --&gt;stages area<br><br>// if we want to file in local repo. then --&gt; commit this file<br>// if we want changes in the working directory<br>git restore --staged &lt;file&gt;  // unstage area <br>git restore &lt;file&gt;   // unchanged the file (add code is previous)</pre><p>2. <strong>--mixed</strong> (default): It resets the HEAD to the specified commit and unstages the changes. The changes, however, are kept in the working directory. This allows you to make further modifications and choose whether to commit or discard them</p><pre>git reset --mixed &lt;commit&gt;  //commit_id -&gt; delete and file --&gt;unstages area<br><br>// if we want to file in  local repo. then --&gt; add and commit this file<br>// if we want changes in the working directory<br>git restore --staged &lt;file&gt;  // unstage file <br>git restore &lt;file&gt;</pre><p>3. <strong>--hard</strong>: It resets the HEAD to the specified commit, discards the changes in the working directory, and stages area.</p><pre>git reset --hard &lt;commit&gt;   // commit_id -&gt; delete and file -&gt; changed</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bbe0eaec763" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>