Categories
Continuous Integration Docker Jenkins Uncategorized

Dockerizing Jenkins Pipeline – Simplilearn project

This document is an explanation of the project done for simplilearn-devops-certification. It creates a Docker image using Dockerfile and publishes it to docker hub using Jenkins pipeline. The code can be found on the github.

STEP 1 Set up a VS code workspace and the Github repository.

  • Open VS Code.
  • Create a directory “simplilearn-devops-certification” in the terminal and change directory.
  • Run “git init” to initialize repository.
  • Create a repository “simplilearn-devops-certification “ in the github.com
  • Create a file name “README.md” add details of the project in the file.
  • Execute the steps to do initial commit, This will add the project in the GitHub master branch.
      1. git remote add origin https://github.com/aktechthoughts/simplilearn-devops-certification.git
      2. git add  .
      3. git commit –m “ Initial Commit”
      4. git push –set-upstream origin master

STEP 2 Set up a Jenkin Server and a docker-machine.

“java -jar D:\Softwares\jenkins.war –httpPort=8080”

  • The previous command will run the Jenkin server at localhost:8080 port and it can be accessed in the browser using http://localhost:8080/
  • Select “Install Selected packages” and wait for installation to finish.
  • Create a new user after installation is finished.
  • Install a docker on the same machine where Jenkin is installed

STEP 3  Setup Jenkinsfile in the repository

  1. Create Jenkinsfile in the project root directory.
  2. Add below content in the file.

JENKINS

  • The script has four stages in the Jenkins.
    1. Building Image
    2. Deploying the image in the dockerhub repository
    3. Removing the Image from Jenkin node.
    4. Executing Image from dockerhub.

STEP 4 Register and open https://hub.docker.com/ with your own login.

  • Create a new docker reposiory named ‘simplilearn-devops-certification’
  • Create a file ‘Dockerfile’ in the project created in STEP1
  • Add following conent in the file.

Dockerfile

 

Create a pipeline in jenkins and execute the pipeline to publish the image to the docker hub.

 

Categories
Networking Uncategorized

Booting PC over the Network

Basics of Network Booting

Network Boot is industry standard method to load Operating System from network. It was designed to boot disk -less devices when when the cost of disk was high. It is still useful for data centers where servers are made available on demand.

The core concept behind this is same as BIOS (Basic I/O System). The system loads a small piece of software which in turn loads other OS from disk and finally makes the computer live.

PXE (Preboot eXecution Environment) is widely used Network boot software. It was developed by Intel corporation. There are other open source version of Network boot software called iPXE which has more features.

BIOS is hardwired into the mother board, while PXE is encoded into a chip in the network card. All the computers are configured to load BIOS first – BIOS subsequently selects a device to transfer its control. BIOS maintains a list of items ( Hard disk, USB, CD-ROM, Network) which is called boot order. The devices on the lists are selected one by one, whichever is  available first, that device receives control from BIOS.

To boot from Network, we need to configure the BIOS “boot order” and make the Network as first boot device – This can be done in the Boot menu of the BIOS setting. You can go in BIOS setting by pressing DEL or F2 key multiple times when the PC is booting. Some new motherboards may have different setting.

When a network boot program (NBP) receives a call from BIOS, it is loaded into memory and control is passed to this program. This program has driver software for the network card and a DHCP client.  As the intention is to load system over the network, NBP configures a network connection – It sends DHCP request over the wired network and receives a set of IP address a from DHCP  (Dynamic Host Configuration Protocol) server. DHCP server is a program which handles request from a client for IP address. Every network has a DHCP server which serves IP address to the clients.

Configure DHCP server

Below is typical DHCP service call from a client for IP address. The DHCP server can assign IP address as well as a next-server to clients. ‘next-server’ is the address or dnsname for the TFTP server.

DHCP server has a configuration file called “dhcpd.conf” at /etc/dhcp/ directory. It has configuration related to IP addresses, leasing time and other parameters related to dhcp configuration.

subnet 192.168.3.0 netmask 255.255.255.0 {
          range 192.168.3.10 192.168.3.45;
          range 192.168.3.55 192.168.3.60;
          option routers 192.168.3.1;
          option broadcast-address 192.168.3.255;
          default-lease-time 3600;
          max-lease-time 7200;
          next-server TFTP_server_address; 
          filename “/tftpboot/pxelinux.0”;
}

The two parameters ‘next-server’ and ‘filename’ are important for network booting. TFTP server is Trivial FTP server which runs on the port 66, any client can request for the files hosted, and the files are served without authentication.

‘filename’ is the NBP binary hosted on the home directory for the TFTP server.  There are many opensource version of TFTP servers available – You can follow this to install TFTP server on Ubuntu machines.

DHCP

Configure PXE/iPXE Boot Menu

The structure of the tftp root directory (tftpboot) is shown below. It hosts the file pxelinux.0. This file is  lightweight master boot record boot loaders from syslinux. There are some other files vesamenu.c32, ldlinux.c32, libcom32.c32 and libutil.c32 required by pxelinux.0.

All these files can be extracted  from syslinux website here.

pi@raspberrypi:~/d_drive/tftpboot $ ls -lrt
total 477
drwxrwxr-x 1 pi pi      0 Oct 27 20:02 syslinux
-rwxrwxr-x 1 pi pi  42143 Oct 27 20:33 pxelinux.0
-rwxrwxr-x 1 pi pi  26692 Oct 27 20:33 vesamenu.c32
-rwxrwxr-x 1 pi pi 116556 Oct 27 20:33 ldlinux.c32
-rwxrwxr-x 1 pi pi 181952 Oct 27 20:33 libcom32.c32
-rwxrwxr-x 1 pi pi  23636 Oct 27 20:33 libutil.c32
drwxrwxr-x 1 pi pi      0 Oct 27 21:11 img
-rwxrwxr-x 1 pi pi    216 Oct 27 21:29 HTTPServer.py
drwxrwxr-x 1 pi pi    4096 Nov 5 21:53 pxelinux.cfg
-rwxrwxr-x 1 pi pi   67227 Nov 6 19:30 undionly.kpxe
drwxrwxr-x 1 pi pi   4096 Nov 15 13:49 iso
drwxrwxr-x 1 pi pi   4096 Nov 18 12:08 scripts
drwxrwxr-x 1 pi pi   4096 Jan 20 14:05 cgi-bin
pi@raspberrypi:~/d_drive/tftpboot $ cd pxelinux.cfg/
pi@raspberrypi:~/d_drive/tftpboot/pxelinux.cfg $ cat default
default vesamenu.c32
MENU TITLE Boot Menu
prompt 0
timeout 100
ONTIMEOUT Minimal_Linux_Live


LABEL Minimal_Linux_Live
MENU LABEL Minimal_Linux_Live (7M)
KERNEL syslinux/memdisk/memdisk
INITRD iso/minimal_linux_live_20-Jan-2017_32-bit.iso iso


LABEL lubuntu-14.10
MENU LABEL Lubuntu-14.10 Over HTTP (705M)
dhcp
kernel http://192.168.173.2:8000/syslinux/memdisk/memdisk iso raw
initrd http://192.168.173.2:8000/iso/lubuntu-14.10-desktop-i386.iso 

pi@raspberrypi:~/d_drive/tftpboot/pxelinux.cfg $

The tftproot also hosts another directory called  ‘pxelinux.cfg’. This contains a ‘default’ configuration file, which has boot menu configuration along with KERNEL and INITRD commands.

Boot Menu provides a list of OSs hosted on the tftp server in iso and img directory. KERNEL command loads memdisk which is the core of operating system, then INITRD load the actual OS.

Python SimpleHTTPServer module can be used as http server.

Laptop booting over LAN

An example of working PXE boot is available at below location.

https://drive.google.com/file/d/0BzYjW-ujx4yhcTNERlJZMmlObUd5QkhONUktRXZoNWNOX1Jj/view?usp=sharing

The project is also available on github here.

Categories
Networking Uncategorized

Route – How the IP packets are sent?

A computer system or any SOC (System on chip) device with network interfaces uses routing tables to connect to other networks.  A routing table is system wide (tabular) configuration which take cares how the IP packets would be send to another system.

Usually, every network device (laptops, routers, switches) has routing table configured manually or automatically.

At a ubuntu machine, routing table looks something like below. Every entry says which Interface (Iface) would be used to send an network packet with certain IP. The machine in the snapshot has two network interface (eth0 & tun0).

ubuntu_route

The default route (0.0.0.0 in windows) is used for all the non-matching IP , i.e, All the internet traffic goes via default interface. A windows routing table looks like below.

windows_route.jpg

You can add a new route (static routing) to windows machine using route ADD command. (You need admin privilege ).

route ADD 192.167.173.0 MASK 255.255.255.0 192.168.0.191

Now, if you ping 192.168.173.1, it would be routed to interface having IP address 192.168.0.191).  The interface would further transfer the packet to its default gateway.

You reach internet server via multiple gateways, switches and routers. All of them have a routing table configured. Windows trace route command can tell which systems have been used to reach the internet server.

 

Categories
Uncategorized

First blog post

This is your very first post. Click the Edit link to modify or delete it, or start a new post. If you like, use this post to tell readers why you started this blog and what you plan to do with it.