Stránky

Tuesday, April 26, 2016

CoreOS from scratch - Part 1: OS installation

In the "CoreOS from scratch" series I'll try to explain how to install CoreOS three node cluster on VirtualBox using manual process. I believe that understanding installation "the hard way" leads to better understanding of whats going on by using CoreOS with Vagrant as well as helps you to install CoreOS on bare metal.

But first really very fast description of what CoreOS is.

CoreOS is just like any other Linux Distro based on Gentoo.

Gentoo wiki states:

CoreOS is a new Linux distribution that has been rearchitected to provide features needed to run modern infrastructure stacks.

I think this describes CoreOS quite well. CoreOS is Linux operating system that is specially made to run containers (containerized applications) like Docker or Rocket. Meaning it is not operating system you would like to use for desktop, or as typical Linux server where you install any software your corporate IT environment needs. Besides running containerized applications CoreOS comes with full stack of tools needed to form and operate clusters.

cloud-config file


We'll install three instances of CoreOS which will form a cluster. Steps provided are for one node. Other two nodes will be installed the same way with only small modifications. If you have ever installed Linux operating system you may know how long and what steps the OS setup takes. You will find that CoreOS differs from other distributions from the time you will try to install it. 

Most time you'll install CoreOS by using cloud-config file. Cloud-config file contains all configuration of your CoreOS instance or cluster. Configuration of network interfaces, services to be started, services configuration. All stored in one place. Which makes installation of CoreOS a pleasure. You can download your preconfigured file from Internet/Intranet or you can have runtime generated cloud-config file.

For our installation we'll use cloud-config file placed on my site. During the process of individual node installation you will customize copy of this static file. You will quickly realize that the process of customization can be automated by creating on the fly generated cloud-configs.

Now just point browser to http://gabert.github.io/cloud-demo/cloud-config.yaml and inspect content of configuration file.

CoreOS Installation


Assuming you have  already installed VirtualBox follow steps below to prepare virtual machine instance in VirtualBox.

Steps to install CoreOS on virtual machine are easy.

- Download CoreOS ISO image from: https://coreos.com/os/docs/latest/booting-with-iso.html
- Prepare virtual machine (attach iso image, setup interfaces)
- Boot VM
- Download cloud-config file to running VM instance
- Customize downloaded file
- Install CoreOS
- Reboot
- Install other two instances
- Light a cigar and taste some Laphroaig

Steps in more detail.

1. Prepare virtual machine


- create new 64-bit Virtual Machine and name it CoreOS-1


- assign 1024 MB of virtual memory and accept default values
- right click your new fresh virtual hardware and navigate to storage section where you have to mount downloaded ISO.
- navigate to network section. Each new virtual machine has default NAT adapter as the very first adapter. NAT adapter is used to connect your guest OS to Internet. 



Add two more adapters.


Adapter No.2 will be used to ssh to your guest OS from host OS. Set this type to "Host-Only adapter". Adapter simulates public IP.


Adapter No. 3 will be used to interconnect cluster members. Set the type of adapter to internal network. Adapter simulates private network.


- close virtual machine settings but do not start the machine yet. We need one more network configuration setup. Pay attention to described order of adapters. Cloud-config file provided for this setup is based on assumption of preserving described order of network adapters.

Enable Virtual Box DHCP Server


- in VirtualBox setting click 'File > Preferences' and navigate to Network section. Select 'Host-only Networks' tab. Select the one which matches the name of your second adapter and click edit icon. On the 'DHCP Server' tab click 'Enable Server'.


Accept defaults and close all opened windows. You are now prepared to boot virtual machine.

2. Boot VM


CoreOS boots fast to console. You find yourself  logged in to console as user core and prepared to install CoreOS on virtual machine.

3. Download cloud-config file to running VM instance


- in CoreOS console type:

wget http://gabert.github.io/cloud-demo/cloud-config.yaml

4. Customize downloaded file


- determine interface names by typing:

ifconfig | more

Write down interface names. On my computer they are enp0s3, enp0s8, enp0s9 in this order. If your interface names are not the same you will have to replace names in downloaded cloud-config file.

- edit cloud-config file:

vi cloud-config.yaml

Change names of interfaces if they differ from the previous command output. Look for '[Match]' sections. If you are done with interface names scroll to interface

'- name: 30-enp0s9.network'

and change the X in the IP address to number 1.

'Address=10.160.1.11/24'

First member of cluster will have address '10.160.1.11', second one '10.160.1.12' and third one '10.160.1.13'. IP address is first customization point. Save cloud-config file and exit editor. CoreOS is prepared to be installed.

5. Install CoreOS


CoreOS is installed by command:

sudo coreos-install -d /dev/sda -C stable -c cloud-config.yaml

Depending on speed of your internet connection CoreOS is installed under a minute or so.

6. Reboot


After successful installation shutdown CoreOS instance:

sudo shutdown -h now

Remove ISO image and spin up your CoreOS instance. This time you boot to login prompt. Log in by using 'core/core' credentials.

(cloud-config file contains instruction that disables ipv6. However ipv6 is disabled only after second reboot. I do not know the reason.)

Check assigned IP addresses by typing:

ifconfig | more

Look for IP address of second interface. Use this address to connect to CoreOS instance from your host operating system by using ssh client like putty.

Also check Internet connection of installed CoreOS by pinging:

ping google.com

7. Install other two instances


If you can connect with ssh client to first CoreOS and are able to ping Internet server, CoreOS installation was successful. Now by using same procedure install other two instances which will later form a cluster. Name VMs CoreOS-2 and CoreOS-3. And remember to change IP addresses to '10.160.1.12' and '10.160.1.13' respectively.  Do not clone VMs. Just go through manual process to get some practice. Your individual node installation is sucessfull if:

- you are able to connect to each CoreOS instances by ssh client
- you are able to ping google.com from each CoreOS instance
- you are able to ping each CoreOS instance from the other ones by their private network IPs: 10.160.1.11, 10.160.1.12, 10.160.1.13

If all of the above criterias are satisfied then ...

 ... cigars, scotch and  you are done ...

CoreOS from scratch - Part 2: etcd

No comments:

Post a Comment