DevTech101

DevTech101
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Kubernetes CoreOS Ignition Configuration Generator Written in Python.

In the previous post I went through how to Configuring Kubernetes Træfik Ingress Controller, DNS, Dashboard. below are examples to use a small Python script I have written to automate most of the Kubernetes deployment process.

Note: Get going in minutes with a full Kubernetes cluster by using the free Kubernetes generator on my GitHub repository. Version 0.7 just became available of the Kubernetes generator, supporting kubernetes version v.1.13.x+, RBAC, Auto Bootstraping, and more. You can generate your own configuration in minutes by using the generator, available on my GitHub repository by going here, you can also just use the ready examples files available here

https://github.com/elik1001/coreos-kubernetes-generator/tree/master/examples

I divided the configuration into parts outlined below. Note: An up-to-date example is available on my GitHub project page, or generate your own Kubernetes configuration with the Kubernetes generator available here on my GitHub page.

This is part 6 – Automate the Kubernetes deployment.

This document provides instructions on how to install and use the Python Kubernetes Generator Script. the script helps automate a Kubernetes deployment on CoreOS. See the deployment notes for additional details. The code I am referencing is hosted on GitHub and can be accessed here. The repository includes the Python Kubernetes generator script, as well as pre configured samples.
  1. The script helps automate a Kubernetes Multi-Master deployment on CoreOS.
  2. The script generates a CoreOS Ignition file that can be used, either as part of a 3 node Master cluster or just as a worker node.
  3. The generated Ignition file includes all required properties for, Etcd, Flannel(with CNI), Kubelet using (Rkt), etc.. all protocols are configured to use SSL.
The script uses a wizard-like approach with a minimum set of questions, just to be able to generate a configuration.

Getting Started

Installation

Dependencies / Prerequisites

The following libraries are required: Note: The script will (try to) download and install the required libraries (if needed).
sys,
os,
pip,
re,   
ast,   
pwd,   
uuid,   
crypt,   
shutil,   
pprint,
getpass,   
requests,   
subprocess,   
inquirer,
from contextlib import contextmanager
Crypto.PublicKey.RSA
Note: You can also manually install the required libraries by running pip install [library]

Usage examples

To use the application just run the ./generate_template.py. You can leave most of the default values by just hitting enter – (replace the IP Address, Hostnames, etc.. if you like..). The default pre-set Hostname and IP Adress are below
CoreOS Cluster IP Address
 Name  IP Addrss
 coreos1  10.0.2.11/20
 coreos2  10.0.2.12/20
 coreos3  10.0.2.13/20
Tip: Re-run the script for every Master, worker, etc.. each run will generate a new configuration file that you can use. Example
./generate_template.py
[..] snip
[?] What kubernetes system type are you building ?: Master
 > Master
   Worker

[..] snip
Ignition Template created successfully.
-----------------------------------------------------------
  SSH private key is             : keys/id_rsa
  SSH public key is              : keys/id_rsa.pub
  SSL certificates are in        : ./ssl/
  Build Template file is         : configs/coreos1_template.yaml 
  Ignition Template file is      : configs/coreos1_template.ign 
  Ignition Template ISO file is  : configs/coreos1_template.iso

Details

The script generates the below list of files and Directories.
  1. ssl: Contains all SSL certificates used in the configuration including the CA certificate
  2. manifests: Contains all the manifests used to generate the Ignition
  3. keys: Contains the SSH Private and Public keys in the configuration
  4. configs: Contains the final configuration files, like. Ignition (mastr[n].ign), ISO with Ignition data on it(master[n].iso) and the YAML config(master[n].yaml).
  5. tmp: Contains all temporary configuration files.
  6. src: Contains the default Kubernetes properties, these files get updated at run time, based on your selections set as the default properties(for the next run).
  7. template: Contains all templates or ready sample templates used in the configuration.

Additional Usage Details

You can use the ign (or ISO with ign file) in a verity of ways. If you are using bear-metal or virtual box, an example is explained below. Boot from a CoreOS ISO/CD/USB which already contains the coreos-install script, or use any bootable CD, then download the CoreOS coreos-install script from here. Next, use the generated Ignition file, you can use the IGN file, or use the ISO which contains the IGN file, the process is the same (like the below). Now, run the coreos-install with the below parameters. Note: the coreos-install script comes pre-installed on CoreOS.
coreos-install -d /dev/[sda] -C [stable|alpha] -i master1_template.ign
Replace sda with your disk. Use alpha or stable channel. Once completed just reboot the server (or virtual) and you should be good to go.

To Do’s

  1. Convert SSL subprocess to pure Python code.
  2. Convert configuration files (in src directory) to a DB layer.
  3. Add include matchbox, PXE, DHCP, as an option for full automation.
  4. Add a Web-UI interface to manipulate properties.
You can download all necessary files from the GitHub project page available here.. You might also like – Other articles related to Docker Kubernetes / micro-service.
Like what you’re reading? please provide feedback, any feedback is appreciated.
0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jeroen
Jeroen
March 31, 2018 11:10 am

Hi Eli,

I can not get this ignition file to work with the latest version of coreos 1729.0.0 Rhyolite.
Network is ok, but flannel is not working.
Using the traspiler yaml to json i got this error:
warning at line 1136, column 19
flannel minor version too new. Only options available in the previous minor version will be supported
this line contained:
version: 0.9.0

2
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: