<?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 Rohitkarki on Medium]]></title>
        <description><![CDATA[Stories by Rohitkarki on Medium]]></description>
        <link>https://medium.com/@rohitkarki804?source=rss-204fdbf6dc9a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Z-CisTETo8ZXc1n4</url>
            <title>Stories by Rohitkarki on Medium</title>
            <link>https://medium.com/@rohitkarki804?source=rss-204fdbf6dc9a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:05:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohitkarki804/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[Everything I know about Kubernetes (Part 2)]]></title>
            <link>https://medium.com/@rohitkarki804/everything-i-know-about-kubernetes-part-2-dea35bca1130?source=rss-204fdbf6dc9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/dea35bca1130</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Rohitkarki]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 10:23:15 GMT</pubDate>
            <atom:updated>2025-03-03T10:23:15.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1oaq_HbQGLOOysx-.png" /></figure><p>Now that we understand the limitations of managing multiple containers with just Docker, the next question is: <strong>How do we orchestrate containers efficiently at scale?</strong> This is where <strong>Kubernetes (K8s)</strong> comes in. Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications — essentially acting as the <strong>“brain” of containerized workloads.</strong></p><p>Just like a <strong>music conductor</strong> ensures that every musician plays in harmony, Kubernetes (K8s) acts as the <strong>orchestrator</strong> for containerized applications — making sure that containers are deployed, scaled, and managed efficiently.</p><p><em>To truly understand Kubernetes, let’s step into the shoes of a company managing a </em><strong><em>large fleet of servers in the cloud</em></strong><em>. Imagine the challenge of manually starting and restarting containers as demand fluctuates — it would be </em><strong><em>tedious, error-prone, and unsustainable</em></strong><em> for a system administrator.</em></p><p>1️⃣ <strong>Traffic suddenly spikes</strong> — you need to manually start more containers.<br>2️⃣ <strong>Some containers crash</strong> — you have to detect failures and restart them.<br>3️⃣ <strong>A new version of the app needs to be deployed</strong> — you have to stop old containers and start new ones without downtime.<br>4️⃣ <strong>Load balancing is required</strong> — you must manually distribute requests to prevent overload on a few containers.</p><p>Managing all of this manually is <strong>time-consuming, error-prone, and doesn’t scale well</strong>.</p><p><em>Kubernetes solves this by introducing a </em><strong><em>declarative approach</em></strong><em> to container management. Instead of manually scaling containers up and down, you simply </em><strong><em>define how many containers should be running at any given time</em></strong><em> — and Kubernetes takes care of the rest. If a container crashes or stops responding, Kubernetes detects the failure through </em><strong><em>health checks (heartbeat signals)</em></strong><em> and automatically spins up a replacement. This is possible because Kubernetes manages containers using </em><strong><em>YAML configuration files</em></strong><em>, which act as a blueprint for deployment.</em></p><h3>How Kubernetes Fixes This</h3><p>Kubernetes acts as an <strong>orchestrator</strong> that <strong>automates</strong> container management. Instead of manually controlling each container, you simply <strong>define the desired state</strong> (how many containers should run, how to update them, and how they should communicate). Kubernetes takes care of the rest!</p><p><strong>1️⃣ Auto-Scaling</strong> — Kubernetes can automatically add or remove containers based on demand.<br><strong>2️⃣ Self-Healing</strong> — If a container crashes, Kubernetes detects it and restarts a new one<br><strong>3️⃣ Rolling Updates</strong> — Deploy a new version <strong>without downtime</strong> — old containers are gradually replaced with new ones using techniques like rolling update and blue green deployment.<br><strong>4️⃣ Load Balancing</strong> — Traffic is distributed across pods to ensure no single instance is overwhelmed.<br><strong>5️⃣ Declarative Configuration</strong> — Instead of manually managing containers, you write a simple <strong>YAML file</strong> describing how your app should run, and Kubernetes <strong>enforces it automatically</strong>.</p><p>Now, we can start studying k8s by understanding the architecture of k8s. Kubernetes components can be divided into two parts: <a href="https://kubernetes.io/docs/concepts/overview/components/#control-plane-components">control plane components</a> and <a href="https://kubernetes.io/docs/concepts/overview/components/#node-components">data plane components</a>.</p><ol><li>Control Plane<br>Kubernetes Control Plane is like the “brain” of Kubernetes. It manages and controls everything happening in the cluster. It ensures that the applications (containers) run properly by scheduling them on available machines, keeping an eye on them, and making changes when needed.</li></ol><h3>Main Components of the Control Plane</h3><ol><li>API Server <strong>(</strong><strong>kube-apiserver)</strong><br>Think of it as the “front desk” of Kubernetes. It takes requests (like adding/removing apps) and makes sure they get processed. Every other component communicates through this.</li><li>Scheduler <strong>(</strong><strong>kube-scheduler)</strong><br>Decides where to run new applications. It checks which machine (node) has enough space and resources to run the app. Think of it like a traffic controller deciding which road (node) a car (app) should take.</li><li>Controller Manager (<strong>kube-controller-manager)<br></strong>A set of mini-managers that ensure everything runs smoothly. It makes sure new apps start if something crashes, updates apps, and manages user accounts. Think of it as a group of supervisors checking different aspects of the system.</li><li>Etcd (Database) <br>Stores all the cluster data (like node locations and settings). If Kubernetes were a library, etcd would be its catalog. Every decision made by Kubernetes is based on data stored in etcd.</li><li>Cloud controller manager <strong>(</strong><strong>cloud-controller-manager)</strong> <em>(only in cloud-based setups)<br></em>Helps Kubernetes work with cloud providers like AWS, Google Cloud, or Azure. It manages things like load balancers and storage that are specific to the cloud provider.</li></ol><h3>In Simple Terms:</h3><p>Imagine Kubernetes as a factory:</p><ul><li>The <strong>API Server</strong> is the receptionist who receives and directs requests.</li><li>The <strong>Scheduler</strong> assigns workers (nodes) to new tasks (apps).</li><li>The <strong>Controller Manager</strong> ensures everything is running as expected.</li><li>The <strong>Etcd database</strong> keeps track of all the work and settings.</li><li>The <strong>Cloud Controller Manager</strong> is like an external supplier handling cloud-specific needs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gzdTNeNsVe1PBN-F.png" /><figcaption>K8s Architecture</figcaption></figure><h3><strong>Data plane Components of K8s</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*BkhdsOWPAwYMm04Q.png" /><figcaption>Data plane in k8s</figcaption></figure><p>If the control plane is the brain of the k8s then the data plane is the body of k8s. It manages things like (nodes) virtual machine for containers to be placed. Inside the worker nodes are the pods, which share compute, networking and storage resources within each isolated pod. Containers are deployed within pods, and pods can scale across nodes as their application requirements change.</p><p>So you may be wondering why is pod needed when containers can be run in node which will be easy to understand and use. But we need to understand a critical component in software deployment which is a software is never deployed alone. It needs to be monitored and state of it must be propagated to other parts as well.</p><p>So here comes the concept of sidecar pattern in k8s landscape. The pod generally only contains the single container but using sidecar pattern a pod can also have another container like logging Prometheus and many more.</p><blockquote>Sidecar containers are the secondary containers that run along with the main application container within the same <a href="https://kubernetes.io/docs/concepts/workloads/pods/">Pod</a>. These containers are used to enhance or to extend the functionality of the primary <em>app container</em> by providing additional services, or functionality such as logging, monitoring, security, or data synchronization, without directly altering the primary application code.</blockquote><p>Typically, you only have one app container in a Pod. For example, if you have a web application that requires a local webserver, the local webserver is a sidecar and the web application itself is the app container.</p><p>Every node has an agent called a kubelet, who is in charge of communicating the desired state to the container engine that ultimately manages the containers. The kubelet gets its specs and configurations from the API server (control plane). Each node also has a kube-proxy, which manages network communication among pods and from other nodes. Nodes, along with all of their inherent components, carry out the configuration established by the control plane.</p><p>In next part, we will talk about how to deploy the application using different techniques like deployment, replicaset and pods.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dea35bca1130" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Essential Linux commands for interviews]]></title>
            <link>https://medium.com/@rohitkarki804/most-essential-linux-commands-for-interviews-02173d71d0c5?source=rss-204fdbf6dc9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/02173d71d0c5</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rohitkarki]]></dc:creator>
            <pubDate>Tue, 11 Feb 2025 17:27:28 GMT</pubDate>
            <atom:updated>2025-02-15T12:53:39.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rWS-jcALJfh2mA7j" /><figcaption>Photo by <a href="https://unsplash.com/@linkedinsalesnavigator?utm_source=medium&amp;utm_medium=referral">LinkedIn Sales Solutions</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Process Management</h3><h3>ps (process status)</h3><p>The ps command is used to know the information of a process or list of processes</p><pre>ps with aux</pre><p>The ps aux command is used to display information about <strong>all running processes</strong> in the system.</p><h4>Breakdown of ps aux:</h4><ul><li><strong>ps</strong> → Process status command.</li><li><strong>a</strong> → Show processes for all users, not just the current user.</li><li><strong>u</strong> → Display process information in user-oriented format.</li><li><strong>x</strong> → Include processes that are not attached to a terminal (background processes).</li></ul><p>awk is the pattern matching library in linux which allows us to pass some pattern and match that pattern.</p><p>Suppose you want to know the column 3 of the current running process then you use the command</p><pre><br># $3 means third column<br>ps aux | awk &#39;{print $3}&#39;<br><br># show 19 pid process <br>ps -19</pre><p><a href="https://unix.stackexchange.com/questions/106847/what-does-aux-mean-in-ps-aux">https://unix.stackexchange.com/questions/106847/what-does-aux-mean-in-ps-aux</a></p><h3>top</h3><p>The top command is used to show information about Linux processes running on the system in real time. It also shows a summary of the system information.</p><p>For each process, top lists down the process ID, owner, priority, state, CPU utilization, memory utilization and much more information. It also lists down the memory utilization and CPU utilization of the system as a whole along with system uptime and CPU load average.</p><h3>Memory Management</h3><p>In this section, we will study about some useful commands that can be used to view information about the system memory.</p><h3>free</h3><p>The free command is used to display the memory usage of the system. The command displays the total free and used space available in the RAM along with space occupied by the caches/buffers.</p><p>free command by default shows the memory usage in kilobytes. We can use an additional argument to get the data in human-readable format.</p><pre>free -h</pre><h3>vmstat</h3><p>The vmstat command can be used to display the memory usage along with additional information about IO and CPU usage</p><h3>df (disk free)</h3><p>The df command is used to display the free and available space for each mounted file system.</p><h3>du (disk usage)</h3><p>The du command is used to display disk usage of files and directories on the system.</p><p>The below command can be used to display the top 5 largest directories in the root directory</p><pre>sudo du -h / | sort -n -r | head -n 5</pre><h3>Explanation of Each Part:</h3><p><strong>sudo du -h /</strong></p><ul><li>sudo → Runs as root (needed to access all directories).</li><li>du (Disk Usage) → Shows disk usage of files/directories.</li><li>-h (Human-readable) → Displays sizes in KB, MB, GB instead of bytes.</li><li>/ → Starts checking from the <strong>root directory</strong>.</li></ul><p><strong>sort -n -r</strong></p><ul><li>sort → Sorts the output.</li><li>-n (Numeric sort) → Sorts by file size instead of alphabetically.</li><li>-r (Reverse order) → Shows largest directories first.</li></ul><p><strong>head -n 5</strong></p><ul><li>head -n 5 → Displays the <strong>top 5</strong> results.</li></ul><h3>File Permissions</h3><p>On a Linux operating system, each file and directory is assigned access permissions for the owner of the file, the members of a group of related users and everybody else. This is to make sure that one user is not allowed to access the files and resources of another user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Fr2XSZau6Gs6USAW.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*pBFmdqQW-SkPRLL5.png" /></figure><p>The chmod command is used to modify files and directories permissions in Linux. The chmod command accepts permissions in as a numerical argument. We can think of permission as a series of bits with 1 representing True or allowed and 0 representing False or not allowed.</p><p>The group owner doesn’t have the permission to write to this file. Let’s give the group owner or root the permission to write to it using chmod command.</p><pre># change the permission to the group <br>chmod 664 test_file<br>ls -l test_file</pre><h3>Chown command</h3><p>The chown command is used to change the owner of files or directories in Linux.</p><p>Command syntax: chown \&lt;new_owner\&gt; \&lt;file_name\&gt;</p><h3>User Management</h3><p>Root is the super user in the linux. It is like the god user in linux. It can read write and do anything on the linux machine.</p><p>Doing tasks in linux mostly requires root user. The command to perform the task as a root user is</p><pre>sudo apt-get update<br>sudo apt-get upgrade<br><br># list all data about softwares<br>cat /etc/apt/sourcelist</pre><p>Root user must be used sparingly only since it can lead to misuse of root user. Another user is created in linux by using user group.</p><h3><strong>What is the difference between root user and user with sudo access?</strong></h3><p>The <strong>root user</strong> and a <strong>user with sudo access</strong> both have administrative privileges, but there are key differences in how they operate.</p><h3>1. Root User</h3><ul><li>The <strong>root</strong> user is the <strong>superuser</strong> in Linux with <strong>unlimited</strong> control over the system.</li><li>It can execute <strong>any</strong> command without restrictions.</li><li>Logging in as root (su - root) gives <strong>full</strong> system access, which is risky.</li><li>If misused, a mistake (like rm -rf /) can <strong>permanently break</strong> the system.</li></ul><h3>2. User with Sudo Access</h3><ul><li>A <strong>regular user</strong> can be granted <strong>temporary</strong> root privileges using sudo.</li><li>The user must be in the <strong>sudoers file</strong> (checked via sudo -l).</li><li>Instead of logging in as root, they use sudo before commands:</li></ul><h3>What does Home Directory mean?</h3><h3>1. Location of Home Directory</h3><ul><li>The home directories for all users are stored under /home/.</li><li>Each user gets a <strong>separate</strong> home directory named after their username.</li><li>The <strong>root user</strong> has a different home directory: /root/.</li></ul><h3>2. Finding Your Home Directory</h3><ul><li>Run:</li></ul><pre>echo $HOME</pre><h3>3. Purpose of Home Directory</h3><ul><li>Stores <strong>personal files</strong> (Documents, Downloads, etc.).</li><li>Contains <strong>hidden configuration files</strong> (.bashrc, .ssh/, .profile, etc.).</li><li>Users <strong>don’t</strong> have access to other users’ home directories unless given permission.</li></ul><h3>4. Example: Home Directories</h3><p>As a server administrator, we are mostly concerned with the Linux servers which are physically present at a very large distance from us. We can connect to these servers with the help of remote login methods like SSH</p><p>Users in Linux has an associated user ID called UID attached to them.</p><p>Users also has a home directory and a login shell associated with them.</p><p>A group is a collection of one or more users. A group makes it easier to share permissions among a group of users.</p><p>Each group has a group ID called GID associated with it.</p><p>good way to find out the current user in Linux is to use the whoami command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*w52KbJ-TfMPthtbo.png" /></figure><p><strong>root user or superuser is the most privileged user with</strong> <strong>unrestricted access to all the resources on the system. It has UID 0</strong></p><h3>Important files associated with users/groups</h3><p>/etc/passwd -&gt; Stores the user name, the uid, the gid, the home directory, the login shell etc</p><p>/etc/shadow -&gt; Stores the password associated with the users</p><p>/etc/group -&gt; Stores information about different groups on the system</p><h3>Important commands for managing users</h3><p>Some of the commands which are used frequently to manage users/groups on Linux are following:</p><ul><li>useradd - Creates a new user</li><li>passwd - Adds or modifies passwords for a user</li><li>usermod - Modifies attributes of an user</li><li>userdel - Deletes an user</li></ul><h3>useradd</h3><p>The useradd command adds a new user in Linux.</p><p>We will create a new user shivam. We will also verify that the user has been created by tailing the /etc/passwd file. The uid and gid are 1000 for the newly created user. The home directory assigned to the user is /home/shivam and the login shell assigned is /bin/bash. Do note that the user home directory and login shell can be modified later on.</p><p>If we do not specify any value for attributes like home directory or login shell, default values will be assigned to the user. We can also override these default values when creating a new user.</p><pre>RUN addgroup -S appgroup &amp;&amp; adduser -S appuser -G appgroup<br>USER appuser</pre><h3>passwd</h3><p>The passwd command is used to create or modify passwords for a user.</p><p>In the above examples, we have not assigned any password for users shivam or amit while creating them.</p><p>!! in an account entry in shadow means the account of an user has been created, but not yet given a password.</p><p>Let’s now try to create a password for user shivam.</p><p>Do remember the password as we will be later using examples where it will be useful.</p><p>Also, let’s change the password for the root user now. When we switch from a normal user to root user, it will request you for a password. Also, when you login using root user, the password will be asked.</p><h3>usermod</h3><p>The usermod command is used to modify the attributes of an user like the home directory or the shell.</p><p>Let’s try to modify the login shell of user amit to /bin/bash.</p><p>In a similar way, you can also modify many other attributes for a user. Try usermod -h for a list of attributes you can modify.</p><h3>Why Use usermod Instead of Editing /etc/passwd Directly?</h3><p>In Linux, user account details (like username, UID, home directory, and shell) are stored in the /etc/passwd file. You <strong>could</strong> manually edit this file using nano or vim, but using usermod is <strong>safer and more reliable</strong>.</p><h3>userdel</h3><p>The userdel command is used to remove a user on Linux. Once we remove a user, all the information related to that user will be removed.</p><p>Let’s try to delete the user amit. After deleting the user, you will not find the entry for that user in /etc/passwd or /etc/shadow file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*ZCz3Wn9uNiv93BGQVEhzKg.png" /></figure><p>Suppose you want to make another user a superuser then</p><p>The operating system didn’t allow the user rohit to read the content of the /etc/shadow file. This is an important file in Linux which stores the passwords of users. This file can only be accessed by root or users who have the superuser privileges.</p><p><strong>The </strong><strong>sudo command allows a</strong> <strong>user to run commands with the security privileges of the root user.</strong> Do remember that the root user has all the privileges on a system. We can also use su command to switch to the root user and open the above file but doing that will require the password of the root user. An alternative way which is preferred on most modern operating systems is to use sudo command for becoming a superuser. Using this way, a user has to enter his/her password and they need to be a part of the sudo group.</p><p><strong>How to provide superpriveleges to other users ?</strong></p><p>Let’s first switch to the root user using su command. Do note that using the below command will need you to enter the password for the root user.</p><p>In case, you forgot to set a password for the root user, type exit and you will be back as the root user. Now, set up a password using the passwd command.</p><p><strong>The file </strong><strong>/etc/sudoers holds the names of users permitted to invoke </strong><strong>sudo</strong>. In Red Hat operating systems, this file is not present by default. We will need to install sudo</p><p>Try to open the /etc/sudoers file on the system. The file has a lot of information. This file stores the rules that users must follow when running the sudo command. For example, root is allowed to run any commands from anywhere.</p><p>One easy way of providing root access to users is to add them to a group which has permissions to run all the commands. wheel is a group in Red Hat Linux with such privileges</p><h3>Package Management with apt-get</h3><p>Sometimes, the repository are somewhat not updated. Then the source code is pulled from the ppa. <strong>PPAs</strong> are <strong>for non standard software/updates</strong>. sThey are generally used by people who want the latest and greatest codes (software).</p><pre>sudo add-apt-repository ppa:cassou/emacs<br>sudo apt-get update</pre><h3>Daemons</h3><p>A computer program that runs as a background process is called a <em>daemon</em>. Traditionally, the name of daemon processes ends with d - sshd, httpd, etc. We cannot interact with a daemon process as they run in the background.</p><p>Services and daemons are used interchangeably most of the time</p><h3>Systemd</h3><p>systemd is a system and service manager for Linux operating systems. systemd units are the building blocks of systemd. These units are represented by unit configuration files.</p><p>The below examples shows the unit configuration files available at /usr/lib/systemd/system</p><pre>[Unit]<br>Description=My Custom Script<br>After=network.target  # Starts after network is available<br><br>[Service]<br>ExecStart=/usr/local/bin/myscript.sh  # Command to run<br>Restart=always  # Restart on failure<br>User=root  # Run as root<br><br>[Install]<br>WantedBy=multi-user.target  # Start in multi-user mode</pre><pre>systemctl enable myscript.service  # Enable at boot<br>systemctl start myscript.service   # Start manually<br><br>systemctl status myscript.service<br><br>systemctl stop myscript.service<br>systemctl disable myscript.service<br><br>systemctl daemon-reload</pre><h3>Managing System Services</h3><p>Service units end with .service file extension. systemctl command can be used to start/stop/restart the services managed by systemd.</p><h3>Key Features of systemd</h3><p>✔ <strong>Service Management</strong> — Starts, stops, and restarts services.<br>✔ <strong>Parallel Booting</strong> — Speeds up system startup.<br>✔ <strong>Logging &amp; Monitoring</strong> — Integrated with journald for logs.<br>✔ <strong>Dependency Management</strong> – Ensures services start in the correct order.<br>✔ <strong>Socket &amp; Timer Services</strong> – Replaces cron jobs with systemd-timers.</p><h3>Systemd Timer Example (Alternative to Cron Jobs)</h3><p>A systemd timer is a <strong>better alternative to cron jobs</strong> for scheduling tasks in Linux. It provides <strong>better logging, dependency management, and more precise scheduling</strong> than cron.</p><h3>1. Create a Service File</h3><p>First, create a systemd service file that defines the task to be executed.</p><pre>sudo nano /etc/systemd/system/backup.service<br><br><br>[Unit]<br>Description=Backup Documents Directory<br>After=network.target<br><br>[Service]<br>ExecStart=/usr/bin/rsync -av /home/user/Documents/ /home/user/Backup/<br>User=user</pre><ul><li>Runs rsync to back up the Documents folder.</li><li>Replace user with your actual username.</li></ul><h3>Create a Timer File</h3><p>Now, create a systemd timer file:</p><pre>[Unit]<br>Description=Run backup service daily<br><br>[Timer]<br>OnCalendar=*-*-* 00:00:00  # Runs daily at midnight<br>Persistent=true  # Runs missed jobs at next boot if system was off<br><br>[Install]<br>WantedBy=timers.target</pre><ul><li>OnCalendar=*-*-* 00:00:00 → Runs every day at <strong>midnight</strong></li><li>Persistent=true → Ensures missed jobs run on the next boot</li></ul><h3>Enable and Start the Timer</h3><p>Enable and start the timer with:</p><pre>sudo systemctl enable backup.timer<br>sudo systemctl start backup.timer<br><br>systemctl list-timers --all<br><br># Since systemd provides better logging than cron, you can check the execution logs<br>journalctl -u backup.service --since &quot;1 day ago&quot;</pre><h3>What is rsync?</h3><p>rsync (Remote Synchronization) is a <strong>fast, efficient, and powerful file-copying tool</strong> in Linux. It is used for <strong>synchronizing files and directories</strong> locally or remotely while <strong>minimizing data transfer</strong> using <strong>delta encoding</strong> (only transferring changed parts of files).</p><p>📌 <strong>Why use </strong><strong>rsync?</strong><br>✔ <strong>Fast</strong> – Transfers only modified parts of files<br>✔ <strong>Secure</strong> – Can use SSH for encrypted transfers<br>✔ <strong>Resumable</strong> – If interrupted, it can resume transfers<br>✔ <strong>Versatile</strong> – Works for local and remote copies</p><pre># Copy Files Locally<br>rsync -av /home/user/Documents/ /home/user/Backup/<br><br># Copy Files to a Remote Server<br># Copies Documents to /backup/ on remote_host<br># Uses SSH by default<br>rsync -av /home/user/Documents/ user@remote_host:/backup/<br><br># Copy Files from a Remote Server<br># Downloads /backup/ from remote_host to Documents/<br>rsync -av user@remote_host:/backup/ /home/user/Documents<br><br><br># Delete Files in Destination that No Longer Exist in Source<br>rsync -av --delete /home/user/Documents/ /home/user/Backup/<br># Ensures Backup is an exact copy of Documents<br># Deletes files in /home/user/Backup/ that are not in /home/user/Documents/<br><br><br># Exclude Specific Files or Directories<br>rsync -av --exclude=&quot;*.log&quot; /home/user/Documents/ /home/user/Backup/<br><br># Excludes the cache/ directory<br>rsync -av --exclude=&quot;cache/&quot; /home/user/Documents/ /home/user/Backup/<br><br></pre><p>In a <strong>real-world development environment</strong>, Linux administrators manage users using a combination of <strong>commands, automation tools, and access control policies</strong> to ensure security, efficiency, and smooth collaboration.</p><h3>1. Creating &amp; Managing Users</h3><p>🔹 <strong>Creating Users</strong><br>Admins create users with:</p><pre>sudo useradd -m -s /bin/bash developer1<br>sudo passwd developer1   # Set password</pre><p>🔹 <strong>Modifying Users</strong><br>Change user details like home directory or shell:</p><pre>sudo usermod -d /new/home/path developer1<br>sudo usermod -s /bin/zsh developer1</pre><p>🔹 <strong>Deleting Users</strong><br>Remove a user and their home directory:</p><pre>sudo userdel -r developer1</pre><h3>2. Managing User Groups</h3><p>In development teams, users are grouped based on roles (e.g., developers, admins).</p><p>🔹 <strong>Create a Group:</strong></p><pre>sudo groupadd developers</pre><p>🔹 <strong>Add User to a Group:</strong></p><pre>sudo usermod -aG developers developer1</pre><p>🔹 <strong>Check User’s Groups:</strong></p><pre>groups developer1</pre><p>🔹 <strong>Remove User from a Group:</strong></p><pre>sudo gpasswd -d developer1 developers</pre><h3>3. Managing Permissions &amp; Access Control</h3><p>🔹 <strong>File Permissions:</strong><br>Set proper file access rights to prevent unauthorized changes</p><pre>chmod 750 script.sh   # Owner full access, group read/execute, others no access<br>chown alice:developers script.sh   # Set owner and group</pre><p>🔹 <strong>Sudo Access (Privilege Control):</strong><br>Admins allow only specific users to run sudo commands by modifying the <strong>sudoers</strong> file:</p><pre>sudo visudo</pre><p>Example rule to give developer1 permission to restart services without a password:</p><pre>developer1 ALL=(ALL) NOPASSWD: /bin/systemctl restart apache2</pre><h3>4. SSH Access Management</h3><p>Developers typically access servers using <strong>SSH</strong>.</p><p>🔹 <strong>Create SSH Keys (No Password Login):</strong></p><pre>ssh-keygen -t rsa -b 4096<br><br># is used to copy your SSH public key to the remote server (server) under the developer1 user account. This allows passwordless SSH login for better security and convenience.<br># Copies Your Public Key (~/.ssh/id_rsa.pub) to the remote server.<br># Appends It to ~/.ssh/authorized_keys on the server.<br># Enables SSH Key-Based Authentication, so you don’t need to enter a password every time you log in.<br>ssh-copy-id developer1@server</pre><p>🔹 <strong>Restrict SSH Access (Only Allow Certain Users):</strong><br>Edit /etc/ssh/sshd_config:</p><pre>AllowUsers developer1 developer2</pre><p>Restart SSH service:</p><pre>sudo systemctl restart sshd</pre><h3>5. Automation &amp; Monitoring</h3><p>🔹 <strong>Automating User Management with Scripts:</strong><br>Example script to add multiple users:</p><pre>#!/bin/bash<br>for user in dev1 dev2 dev3; do<br>    sudo useradd -m -s /bin/bash $user<br>    echo &quot;User $user created&quot;<br>done</pre><p>🔹 <strong>Using Configuration Management Tools:</strong><br>Admins use tools like:</p><ul><li><strong>Ansible</strong> (ansible-playbook user-management.yml)</li><li><strong>Puppet</strong></li><li><strong>Chef</strong><br>to manage users at scale.</li></ul><p>🔹 <strong>Monitoring User Activity:</strong><br>Check login history:</p><p>Track f</p><pre>sudo cat /var/log/auth.log | grep &quot;FAILED&quot;</pre><h3>6. Disabling or Locking Inactive Users</h3><p>To <strong>lock</strong> a user account (e.g., when an employee leaves):</p><pre>sudo passwd -l developer1</pre><p>To <strong>unlock</strong>:</p><pre>sudo passwd -u developer1</pre><p>To <strong>disable a user’s SSH access</strong>:ash</p><pre>sudo usermod -s /sbin/nologin developer1</pre><h3>7. Best Practices for User Management</h3><p>✅ <strong>Follow the Principle of Least Privilege (PoLP)</strong> — Give users only the permissions they need.<br>✅ <strong>Use Groups for Access Control</strong> instead of assigning individual permissions.<br>✅ <strong>Automate with Ansible/Puppet</strong> for consistency and efficiency.<br>✅ <strong>Regularly Audit Users</strong> (cat /etc/passwd and cat /etc/group).<br>✅ <strong>Monitor Logs</strong> (/var/log/auth.log) to detect unauthorized access attempts.</p><h3>Package Manager</h3><p>A <strong>package manager</strong> in Linux is a tool that automates the process of installing, updating, configuring, and removing software packages. It manages software dependencies and retrieves packages from online repositories.</p><h3>Types of Package Managers in Linux</h3><h4>1. RPM-Based Package Managers (Used in RHEL, CentOS, Fedora)</h4><ul><li><strong>rpm (Red Hat Package Manager)</strong> – Low-level package management.</li><li>Example: rpm -ivh package.rpm (install an RPM package)</li><li><strong>yum (Yellowdog Updater, Modified)</strong> – Higher-level package manager for dependency resolution.</li><li>Example: yum install package-name</li><li><strong>dnf (Dandified YUM)</strong> – A faster, improved version of yum (default in CentOS 8+ and RHEL 8+).</li><li>Example: dnf install package-name</li></ul><p><strong>YUM (Yellowdog Updater, Modified)</strong> is a package manager used in <strong>Linux</strong> systems, primarily for <strong>RPM-based distributions</strong> like <strong>CentOS, RHEL (Red Hat Enterprise Linux), and Fedora</strong>. It helps users install, update, and manage software packages easily by automatically handling dependencies</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02173d71d0c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything I know about Kubernetes (Part 1)]]></title>
            <link>https://medium.com/@rohitkarki804/everything-i-know-about-kubernetes-part-1-11a643ed04b2?source=rss-204fdbf6dc9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/11a643ed04b2</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Rohitkarki]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 08:32:59 GMT</pubDate>
            <atom:updated>2025-02-10T19:22:03.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lVI5NcjTJsLwTH26.png" /></figure><p>Recently, I came across a fascinating blog post about how major research labs deploy massive language models like <a href="https://openai.com/index/scaling-kubernetes-to-7500-nodes/">GPT on Kubernetes clusters spanning over <strong>7,500 nodes</strong></a>. This got me curious — how do they manage and scale such complex deployments? That curiosity led me down the rabbit hole of <strong>Kubernetes (K8s)</strong>, exploring its core concepts and how it orchestrates applications at scale</p><blockquote><em>Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management</em></blockquote><p>Just like a <strong>real-world musical orchestra</strong>, where a <strong>conductor</strong> ensures that all musicians (performers) play in sync, <strong>Kubernetes (K8s)</strong> acts as the <strong>orchestrator</strong> to manage and coordinate <strong>pods</strong> (performers).</p><p><strong><em>Before we jump into Kubernetes, it’s essential to understand containers and Docker first. Kubernetes is an orchestrator for containers, and without understanding what containers are, why they exist, and how they work, learning Kubernetes can be confusing. This post is the first part of a series where we will start from Docker and then move towards Kubernetes.</em></strong></p><p>So, in the 2000s when cloud computing were a rise. We would rent a virtual machine in the server and run our applications. How easy and cool Right? Nope, managing hundreds of VMs turned out to be real pain in the ass. The VMs would crash without any noticeable errors and system administrator or cloud engineer would need to restart the server manually.</p><p>In the 2010s, containers became widely adopted with the release of <strong>Docker</strong>. It revolutionized cloud deployment by simplifying how applications are packaged and managed. With Docker, developers could define everything in a simple <strong>Dockerfile</strong>, which handled application startup, dependencies, and configuration in a compact format.</p><p>So how are containers any different from the VMs. How are they totally different and how they work on the inside!</p><p>Virtual Machine is working under the hood. They are run through a hypervisor where virtual machine will get virtualized CPU, memory, the file system, and all the other required system. Every virtual machine will get their own kernel and operating system. As VM has their own operating system and kernel there is a high isolation between every VMs. This isolation by using separate kernels in VMs which increases the size of deployment in VMs are one of the reason why containers are popular.</p><p>Similar to how multiple containers can be run in a single host machine, multiple VMs can be run on a single host and in this way, it’s possible to run applications (or each microservice) in a separate VM and achieve separation of concerns.</p><p>The main focus here is on the size of the VMs and containers. VMs come along with a copy of the guest operating system and therefore are heavy-weight compared to containers. VMs are heavy and consume very high resources and they take large amount of time booting up. But that problem of slow startup is being changed by the introduction of <a href="https://firecracker-microvm.github.io/"><strong>Firecracker</strong></a>.</p><p>But how are different virtual machine virtualized and uses the systems components virtually? That came into my mind and I searched about how hypervisor gives its virtualized access to every VMs.</p><ol><li>CPU Virtualization:<br>The hypervisor <strong>intercepts and manages privileged CPU instructions</strong> that VMs cannot execute directly. It uses <strong>CPU scheduling(Round robin) </strong>to distribute physical processor time across multiple VMs.</li><li>Memory Virtualization: <br>Each VM is given its own <strong>virtual memory space</strong>, separate from others. The hypervisor maintains a <strong>mapping table (shadow page tables or Extended Page Tables — EPT in Intel)</strong> to translate VM memory addresses to physical memory addresses</li><li>Storage Virtualization:<br>The hypervisor creates virtual disks (VMDK, VHD, QCOW2, etc.) that act as separate storage devices for VMs. It manages disk I/O requests and maps them to physical disk storage</li><li>Network Virtualization:<br>Virtual Network Interface Cards (vNICs) are assigned to VMs, allowing them to communicate as if they had physical NICs. The hypervisor creates virtual switches (vSwitches) that handle VM-to-VM and VM-to-physical network traffic.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YLyuP2Gmt0oQwtAt" /><figcaption>Virtual Machine vs Container</figcaption></figure><p>On the other hand,</p><p><strong>Containers</strong> are lightweight software packages that contain all the dependencies required to execute the contained software application. They don’t contain their own kernel as opposed to Virtual Machines. Containers share the <strong>host OS kernel</strong> but have their own user-space environments.</p><p>We can run several containers on a single host. Due to how containers are implemented, each container has its own isolated environment within the same host. This means that a monolithic application can be broken down into micro-services and packaged into containers. Each microservice runs in the host machine in isolated environments. This is another reason why containers are used: <em>separation of concerns</em>.</p><p>Providing isolated environments does not let the failure of one application in one container affect the other. This is called <em>fault isolation</em>. Isolation also gives the added benefit of increased security due to restricted visibility of processes in a container.</p><p>Due to how most of the containerization solutions are implemented, we also have the option to cap the amount of resources consumed by applications running within a container. This is called <em>resource limiting</em>. Will will discuss this feature in more detail in the section on <strong>cgroups</strong>.</p><p>We’ve talked about how <strong>containers</strong>, unlike virtual machines, share the same kernel as the host operating system and provide isolated environments for applications to run. This is achieved without the overhead of running a guest operating system on the host OS, thanks to two features of <strong>linux</strong> kernel called <strong>cgroups</strong> and kernel namespaces.</p><p>A <strong>container</strong> is simply a process or group of processes in <strong>linux</strong> which has no visibility of other process(containers) outside of itself with the help of namespaces for and restricted access to the <strong>quantity of resources</strong> it can use (implemented using <strong>cgroups</strong>) and — <strong>system calls</strong> that can be made from the container. <a href="https://docs.docker.com/engine/security/seccomp/">Refer</a> to this learn more.</p><p>So what are these terms:</p><ol><li>Namespaces<br>Namespaces in Linux are a <strong>lightweight virtualization feature</strong> that allow isolation of system resources for processes. They are a key building block for <strong>containers</strong> (e.g., Docker, LXC, Kubernetes) and ensure that processes in one namespace <strong>cannot see or interact with</strong> processes or resources in another. <br><strong>PID namespace</strong> → A processes in a pid namespace have process ids which are unique only within the namespace(container). A process can be a root process (pid 1) in its own pid namespace(container) and have an entire tree of processes under it. <br><strong>Network namespace</strong> → Each network namespace will have its own network device instances that can be configured with individual network addresses. Processes in the same network namespace can have their own ports and route tables.<br><strong>Mount namespace</strong> → Process groups sharing a mount namespace share a separate, private set of mount points and file system view. Any modifications made to these namespaced(same container) mount points are not visible outside the namespace(different containers). For example it is possible to have a /var within the a mount namespace which is different from /var in the host.<br>U<strong>ser namespace</strong> → Allows non-root users to act as root inside the container<br>As complex as it seems, it is really easy to make a namespace in linux.<br>Let’s create a PID namespace with the unshare command and create a bash process in the namespace.<br>sudo unshare ps — fork -pid — mount-proc bash</li><li>Control groups<br>By giving the different namespace to different containers, containers can stay in isolation but there is no way of restricting the use of memory pages, disk i/o, CPU etc. in containers. There the use of cgroups in linux come into play where, cgroups (Control Groups) in Linux allow resource management and allocation for processes. They enable you to limit, prioritize, monitor, and isolate CPU, memory, disk I/O, and network usage for groups of processes. <br>cgroups are widely used in containers (Docker, Kubernetes, LXC) to ensure fair resource distribution and prevent any single process from consuming excessive system resources.</li></ol><p>So, how to start a container in my machine. I am showing how to start and run the docker container(as it is popular container software). Other container software are containerd.</p><p>Then, the docker engine will be required</p><p>First of all we need to write Dockerfile which describes the contents inside the container. We will be using a python container which allows to run python applications inside the container which will in turn use host operating system for all the hardware level requirements.</p><h4>Simple Dockerfile for a Python App</h4><pre># Uses the official Python 3.9 image as the base<br>FROM python:3.9<br><br># Set the working directory inside the container<br>WORKDIR /app<br><br># Copies all files from the current directory in your computer<br># to /app in the container.<br>COPY . .<br><br># Install dependencies from requirements.txt<br>RUN pip install --no-cache-dir -r requirements.txt<br><br># Define the command to run the application<br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><h4>Build &amp; Run the Docker Image</h4><pre># Build the image (tagged as myapp)<br>docker build -t myapp .<br><br># Run the container<br>docker run -it myapp</pre><p>We now need to understand the concepts of docker image and containers.</p><h3>Docker image vs container</h3><blockquote>An image is a snapshot of an environment, while a container runs the software.</blockquote><p>So, taking the understanding of object oriented programming concept to the docker.</p><ul><li>A <strong>Docker image is like a class</strong> → it defines the structure but <strong>cannot run by itself</strong>.</li><li>A <strong>Docker container is like an object</strong> → a running instance of an image.</li><li>Just like you can create <strong>multiple objects from a class</strong>, you can create <strong>multiple containers from a single image</strong>.</li><li>Modifying a <strong>class</strong> (Docker image) requires <strong>rebuilding</strong> before creating new instances.</li></ul><p>So, how does all these docker components communicate with eachother. There is a docker daemon running inside the docker engine which will talk to the docker client (which may be docker desktop application or docker cli app) through a rest api. So, when we are running <strong>docker build, docker run, docker pull </strong>commands. It will communicate with the docker daemon and it will build a container image, run a container or pull the predefined docker images from the internet which are premade docker template/images.</p><p>Example: Running docker run ubuntu<br>1️⃣ <strong>Docker CLI</strong> → Sends docker run ubuntu request to the <strong>Docker Daemon</strong>.<br>2️⃣ <strong>Docker Daemon</strong> → Checks if ubuntu image exists <strong>locally</strong>.<br>3️⃣ <strong>Docker Daemon</strong> → If not found, it <strong>pulls the image from Docker Hub</strong>.<br>4️⃣ <strong>Docker Daemon</strong> → <strong>Creates and starts the container</strong>.<br>5️⃣ <strong>Container Runs</strong> → Executes <strong>bash shell inside the container</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NQ0W5_FMBc1S6dFA.png" /><figcaption>Docker Client Daemon Architecture</figcaption></figure><p>So, in this first part we learnt about containers and how they work on the inside. Docker makes it easy to <strong>run and manage individual containers</strong>, but in a <strong>real-world production environment</strong>, applications aren’t just made up of a <strong>single container</strong> — they consist of <strong>multiple interconnected containers</strong> running across multiple servers. So, Kubernetes is used to manage large containers in real world applications.</p><h4>Some of the problems we run over while deploying in real world applications.</h4><p>Suppose we have a a ecommerce MERN stack applications where frontend runs on React js and backend runs on Nodejs and data are stored in MongoDB database. In the simple applications where we have three components we can manage running the three containers.</p><ul><li>But if your site goes viral and traffic spikes during a festival, we might need to <strong>add more backend API containers</strong> to handle requests.</li><li>With <strong>Docker alone</strong>, we have to <strong>manually start more containers</strong> and load balance traffic. This is <strong>not scalable</strong> in large systems Then the problem of container orchestration comes which is managed and made simple using k8s.</li><li>But what if any one container crashes, docker provides a <strong>restart </strong>command, but it doesn’t perform<strong> </strong>automatically check <strong>health status</strong> or replace failing containers intelligently.</li></ul><h3>Why Kubernetes Is Required? (How K8s Solves These Problems)</h3><p>Kubernetes (K8s) is designed to <strong>solve all these challenges</strong> and make deploying containerized applications <strong>easier, scalable, and reliable</strong>.</p><p>✅ <strong>Automated Scaling</strong> → Kubernetes can <strong>automatically scale containers</strong> based on CPU/memory usage or incoming requests.<br>✅ <strong>Self-Healing</strong> → If a container crashes, Kubernetes will <strong>automatically restart or replace</strong> it.<br>✅ <strong>Load Balancing</strong> → Kubernetes <strong>distributes traffic</strong> across multiple instances of a service.</p><p>To explain more about k8s wait for <strong>part 2</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11a643ed04b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>