Skip to content

Latest commit

 

History

History
292 lines (219 loc) · 8.02 KB

File metadata and controls

292 lines (219 loc) · 8.02 KB

Virtualizations, Hypervisors, Virtual Machine for DevOps


Virtualizations:

  • Virtualization is the process of creating virtual (software-based) versions of physical resources like servers, storage, or networks. It allows multiple operating systems (OS) or applications to run on a single physical machine, optimizing resource utilization.

Hypervisors:

  • A hypervisor (or Virtual Machine Monitor) is software/firmware that creates and manages virtual machines (VMs). It allocates physical resources (CPU, RAM, storage) to VMs and ensures isolation between them.

Types of Hypervisors :

Type 1 (Bare Metal)

  • Runs directly on physical hardware. Offers high performance and security.
Examples: VMware ESXi, Microsoft Hyper-V, Xen

Type 2 (Hosted):

  • Runs on top of a host OS. Easier to set up but less efficient.
Examples: VMware Workstation, UTM, VirtualBox, Hyper V, Parallels, KVM QEMU

Advantages of Virtualization for DevOps :

  • Resource Efficiency:

    • Maximizes hardware usage by running multiple VMs on one machine.
  • Isolation:

    • Faults in one VM don’t affect others.
  • Scalability:

    • Quickly spin up/down VMs to match workload demands.
  • Cost Savings:

    • Reduces physical hardware costs.
  • Environment Consistency:

    • Replicate identical dev, test, and production environments.
  • Faster Provisioning:

    • Deploy pre configured VMs in minutes.
  • Disaster Recovery:

    • Snapshots allow easy rollbacks during failures.

Virtual Machine (VM):

  • A VM is a software emulation of a physical computer. It runs an OS and applications as if it were a physical machine, but shares resources managed by the hypervisor.

Install VMware Workstation & Create a VM :

Steps :

  1. Download & Install:

    • Get VMware Workstation
    • Follow the installer prompts (supports Windows/Linux hosts).
  2. Create a VM :

    • Open VMware Workstation → Click Create a New Virtual Machine.
    • Select Typical Configuration (recommended for beginners).
    • Choose an ISO image (e.g., Ubuntu, Windows) for the guest OS.
    • Specify the OS type (e.g., Linux → Ubuntu 64-bit).
    • Name the VM and select a storage location.
    • Set Disk Capacity (e.g., 20 GB for Linux).
    • Customize hardware (optional): Adjust CPU cores, RAM (e.g., 4GB), network settings (NAT/Bridged).
    • Click Finish → Power on the VM to install the OS from the ISO.

Example: Creating Control Node VM for the DevOps course

  • Launch the New VM Wizard
    • Open VMware Workstation
  • Click File → New Virtual Machine
  • Choose Typical Configuration
  • Select Typical (recommended)
  • Click Next
  • Point to the ISO Image
    • I will install OS later
  • Click Next
  • Specify Guest OS Type
  • Select Linux → CentOS 9 or CentOS 10
  • Click Next
  • Name the VM & Location
  • Enter a name (e.g., Control Node Server)
  • Choose a folder for VM files
  • Make a location as a ‘DevOps Class’ in any available drive.
  • Click Next
  • Set Disk Capacity
    • Allocate at least 20 GB (40 GB+ recommended)
    • Select Store virtual disk as a single file
  • Click Next
  • Finish Creation & Tweak Hardware
  • Click Finish
  • Before powering on, click Edit virtual machine settings and adjust:
    • Choose Installer disc image file (ISO)
    • Browse and select your CentOS Stream ISO
      • Memory : ≥ 1 GB (4 GB+ recommended)
      • Processors : 1 or 2 cores
      • Network Adapter : NAT or Bridged
      • CD/DVD (IDE) : Connected to the ISO
  • Power On & Begin Installation
  • Power on the VM
  • Select Install CentOS Stream 10 at the boot menu
  • Follow prompts to choose
    • Language:
    • Keyboard:
    • Installation Destination:
    • Automatic Partitioning: Click on the ‘Done’
    • Manual Partitioning: Not needed for this course
Automatic Partitioning:
  - /boot → 1 GB
  - /swap → 2 GB
  - / → Remaining all space
  - Software Selection: Server with GUI
  - Time & Date: Asia(Kathmandu)
  - Network & Host Name:
  Network: Confirm it’s enabled
  Host Name: localhost
  • Set the Root Password:
  • User Creation:
  • Begin Installation
  • Reboot & Post-Install Setup
  • Reboot once installation completes
  • Log in and update:
  sudo dnf update -y
  • (Optional) Enable SSH:
  sudo systemctl enable sshd
  sudo systemctl start sshd
  • (Optional) Install VMware Tools:
  sudo dnf install open-vm-tools -y
  sudo systemctl enable vmtoolsd
  sudo systemctl start vmtoolsd
  • (Optional) Open SSH in the firewall:
  sudo firewall-cmd --permanent --add-service=ssh
  sudo firewall-cmd --reload

Creating VMs for a Lab Environment :

  1. Clone VMs :

    • Use VMware’s Clone feature to replicate VMs (e.g., create identical web/database servers).
  2. Snapshots :

    • Save VM states before risky changes (e.g., updates). Revert easily if issues arise.
  3. Network Configuration :

    • Use NAT for internet access or Host-Only for internal lab networks.
  4. Templates :

    • Create a base VM template (pre-configured OS/tools) for rapid deployment.
  5. Resource Management:

    • Allocate resources based on workload (e.g., 2 CPUs/8GB RAM for a Jenkins server).

Example Lab Setup:

1. Developer VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

2. Web Server VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

3. Tomcat Server VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

4. Jenkins Server – Master VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

5. Jenkins Server – Slave VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

6. Ansible Server – Master VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

7. Container Host VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

8. Kubernetes Master VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

9. Kubernetes Worker Node1 VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

10. Kubernetes Worker Node2 VM

  • RAM: 1GB
  • CPU: 1 vCPU
  • Disk Space: 20 GB

Creating a Clone of a Virtual Machine: Cloning VM for Creating Multiple VMs for Lab Environment

Prerequisite :

  • Ensure the source VM is powered off.
  • Always make a clone of a fresh VM. (Nothing is configured, just installed)

Clone Process :

  • Open VMware Workstation → Right click the source VM → ManageClone.
  • In the Clone Wizard:
    • Select the current state of the VM.
  • Choose Clone Type :
    • Full Clone (independent copy, recommended for labs).
  • Assign a unique name and storage path → Click Finish.

Post-Clone Configuration :

  • Change Hostname (to avoid conflicts):
    sudo hostnamectl set-hostname <new-name>

Update Network Settings :

  • Assign a new IP address.
  • Generate a new MAC address (VM Settings → Network Adapter → Generate).

Reset Machine Identifiers (if needed):

  • Linux: Regenerate /etc/machine-id.

Tips for Lab Environments

  • Use Full Clones for isolated, independent VMs.
  • Create a base VM template for rapid cloning.
  • Automate post clone tasks (e.g., scripts for hostname/IP changes).
  • Use snapshots before cloning to preserve the base VM state.
  • Isolate lab VMs with Host-Only or Custom NAT networks.

Delete a Virtual Machine:

Power Off the VM:

  • Right-click the VM → PowerShut Down Guest or Power Off.

Delete the VM :

  • Right-click the VM → ManageDelete from Disk (or press Delete key).
  • Confirm by checking "Delete files from disk" → Click Yes.

Important Notes:

Permanent Deletion :

  • All VM files (disks, snapshots, configs) are irreversibly removed. Partial Removal :
  • Use Remove (not "Delete from Disk") to keep files on disk.

File Location :

  • VM files are stored in the folder specified during creation (manually delete if needed).