Infrastructure as Code

Vom Kunsthandwerk zum Wegwerf-Server

Zur Person

Mathias Münch

  • UNIX (und Lookalikes) seit 1984
  • C/C++ genau so lange
  • RZ-Betrieb seit 1991
  • SW-Entwicklung genau so lange
  • RZ-Leiter
  • IaC-Projekt

<mathias.muench@tngtech.com>

Programmable. Testable. Deployable.

"Infrastructure as code". I love the phrase. Where devops is a word that is sadly open to so much (mis)interpretation, "Infrastructure as code" is pretty clear. Treat your infrastructure as code. Programmable. Testable. Deployable. (John E. Vincent)

Softwareentwicklung

  • Programmable
    • von griechisch pró = vor und -gramm: grámma in der Bedeutung »Geschriebenes; Schrift(zeichen)«
    • versionierbar
  • Testable
    • automatisch
    • kontinuierlich
  • Deployable
    • aus der Militärsprache: Einsetzen
    • geplant, vorhersehbar, mit bekanntem Ergebnis

Entwicklungs-Workflow

Patchen in Binaries

"'Real Programmers' are reluctant to actually edit a program that is close to working. They find it much easier to just patch the binary object code directly" (Ed Post, Real Programmers Don't Use PASCAL)

Änderungen außerhalb des Codes

  • Patchen außerhalb des Codes macht die Code-Versionierung wertlos.
  • Patchen außerhalb des Codes macht automatische Tests, CI, Delivery-Pipeline etc. unmöglich.

Änderungen an Servern

  • Nach der Installation werden manuelle Konfigurationen über Wochen/Monate/Jahre vorgenommen.
  • Nach der Installation werden Änderungen in den Regeln des Configuration-Managements vorgenommen.

WTF

Wir installieren unsere perfekt versionierte, automatisch getestete, kontinuierlich integrierte Software auf Servern mit einem unbekannten Status.

Immutable Server

Immutable Server

Jede Konfigurationsänderung bedeutet eine Neuinstallation.

Virtualisierung ermöglicht "Server as Code"

  • Zusätzliche Maschinen lassen sich ohne Hardwarekauf erstellen.
  • Das VM-Deployment wird programmiert.
  • Die Virtualisierungsplatform abstrahiert von Spezialhardware, VMs sehen nur einfache "Standard" Hardware.

IaC-Entwicklung

IaC-Entwicklung

VM aus Images

VM-Images

Hosted Hypervisor

VM aus ISO

VM-Images

Manuelle Netzwerkinstallation

  • neue Mac Addresse in /etc/dhcpd.conf eintragen
  • PXE Boot Datei auf TFTP Server anlegen
  • Copy & Paste Kickstart Datei von einem Template
  • DHCPD neustarten
  • neuen Server einschalten
  • warten
  • über Fehler in obiger Prozedur ärgern
Angry Bird
https://flic.kr/p/9Erhzb

Cobbler

Giant Knife
„Giant Knife 1“ von Slartibartfass - Eigenes Werk. Lizenziert unter Creative Commons Attribution-Share Alike 3.0 über Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Giant_Knife_1.jpg#mediaviewer/File:Giant_Knife_1.jpg

Cobbler Features

  • zentraler Installationsserver
  • Open Source
  • automatisiert OS Installation
    • RHEL, SuSE, Debian
  • vereinfacht Handhabung von
    • PXE Boot, TFTP Server, DHCP, DNS, ...
  • Flexible Kickstarts mit Snippets und Templating
  • Web Interface
  • Orchestrierung
    • Distribution, Profil, System, YUM Repos
  • Python, XML-RPC Schnittstelle

Cobbler Beispiel


# import mounted dvd 
cobbler import --path=/mnt --name=CentOS-6 --kickstart=/var/lib/cobbler/kickstarts/default.ks
cobbler distro report --name CentOS-6

cobbler profile add --name latest --comment "profile for development hosts"
cobbler repo    add --name latest --mirror /var/www/yum/latest --comment "yum repo for development" ...

cobbler profile add --name int --comment "profile for integration hosts"
cobbler repo    add --name int --mirror /var/www/yum/int --comment "yum repo for integration"
cobbler system  add --name int1 --profile int --interface eth0 --mac ... --ip ...


cobbler profile add --name prod --comment "profile for prod1 hosts"
cobbler repo    add --name prod --mirror /var/www/yum/prod --comment "yum repo for prod"
cobbler system add  --name prod1 --profile prod

# dhcp, tftp... synchronisieren
cobbler sync
				

Koan

Koan ist ein Cobbler-Client, der Konfigurationen von Cobbler abrufen und Systeme installieren kann.

	
koan --server=cobbler.example.org --virt --profile=name
				

Koan erfordert konzeptionell einen Hosted-Hypervisor.

VM mit cobbler/koan

VM/cobbler/koan

Hosted Hypervisor

[API]

Bei einem Bare-Metal-Hypervisor muss der Hypervisor direkt gesteuert werden - per Code!

"The vSphere API is exposed as a Web service"

vSphere Perl-SDK


#!/usr/bin/perl
use strict;
use warnings;

# Step 1: Import the vSphere SDK for Perl Modules.
use VMware::VIRuntime;

# Step 2: (Optional) Define Script-Specific Command-Line Options.
my %opts = (
		entity => {
		type => "=s",
		help => "ManagedEntity type: VirtualMachine, etc",
		required => 1,
		},
);

Opts::add_options(%opts);
Opts::parse();
Opts::validate();

# Step 3: Connect to the Server.
Util::connect();

# Step 4: Obtain View Objects of Server-Side Managed Objects.
# Obtain all inventory objects of the specified type

my $entity_type = Opts::get_option('entity');
my $entity_views = Vim::find_entity_views(view_type => $entity_type);

# Step 5: Process Views and Report Results.
# Process the findings and output to the console 
foreach my $entity_view (@$entity_views) {
	my $entity_name = $entity_view->name;
	Util::trace(0, "Found $entity_type:    $entity_name\n");
}

# Step 6: Close the Server Connection.
# Disconnect from the server
Util::disconnect();
				

Bare-Metal Hypervisor

Continuous Integration

  • CI Server bauen Softwareprojekte
    ... und jetzt auch virtuelle Maschinen
  • Jenkins Jobs reinstallieren virtuelle Maschinen und testen, ob die Infrastruktur Maschinen noch baubar sind
  • führen funktionale Tests für fachlichen Anwendungen durch

Blue Green Deployment

Software Eigenschaften

  • Applikation ist statuslos (nach Möglichkeit)
  • Feature-Flags statt Feature Branches
  • Datenbank
    • App-Version N+1 kann mit DB-Modell N umgehen
    • App-Version N kann mit DB-Modell N+1 umgehen
    • Gemeinsames Umschalten auf DB-Modell N+1 und Feature-Satz N+1

Vielen Dank