# Konvoy Image Builder
## KIB
Konvoy Image Builder is the tool used to prepare a machine with the necessary components a Cluster-API-capable machine uses.
### Installed
### Cloud
For Azure, AWS, vSphere, GCP, etc, KIB will use an existing template. This image is usually pre-approved with the necessary components to run in a customer environment.
KIB will install the container runtime, kubelet, and kubeadm on the template. Then, when CAPI launches a node, it will use the providers' method of configuring on launch to configure the machine for the cluster it will be part of as a node.
That step is where CAPI takes over and inserts the configurations from the `cluster.yaml` to the node at start-up, such as the cluster name, the location of the control plane, pod IP ranges, etc.
### Preprovisioned
Pre-provisioned works a little differently. KIB is run as part of the CAPPP process itself and does the installation and configuration in the same step.
## Lab
For this lab, you will perform the KIB process to build a centos image like it was an airgap install. It will not be an actual airgap, but all the steps will be like if it were an airgap install.
### Download the DKP 2.4.0
Download the Airgap bundle to get all the images that are part of
On your bootstrap machine, download the airgap bundle with the below command.
```bash
wget https://downloads.d2iq.com/dkp/v2.4.0/dkp-air-gapped-bundle_v2.4.0_linux_amd64.tar.gz
```
This will take a while
Untar the download
```bash
tar -xvf dkp-air-gapped-bundle_v2.4.0_linux_amd64.tar.gz
```
### Examine the KIB directory and understand its structure
Enter the kib directory and ignore the rest of the download that will be covered in other labs.
```bash
cd dkp-v2.4.0/kib/
```
```bash
ls -al
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 25 03:41 .
drwxrwxr-x 6 ubuntu ubuntu 4096 Aug 25 03:40 ..
-rw-r--r-- 1 ubuntu ubuntu 11357 Nov 15 2022 LICENSE
-rw-r--r-- 1 ubuntu ubuntu 3144 Nov 15 2022 README.md
drwxr-xr-x 6 ubuntu ubuntu 4096 Aug 25 03:41 Ansible
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 25 03:41 artifacts
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 25 03:41 goss
drwxr-xr-x 7 ubuntu ubuntu 4096 Aug 25 03:41 images
-rwxr-xr-x 1 ubuntu ubuntu 190906368 Nov 15 2022 konvoy-image
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 overrides
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 25 03:41 packer
```
*artifacts*
```bash
ls -al artifacts/
total 2124300
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 25 03:41 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 25 03:41 ..
-rw-r--r-- 1 ubuntu ubuntu 252606392 Nov 21 2022 1.24.6_centos_7_x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 258370471 Nov 21 2022 1.24.6_centos_7_x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 251385527 Nov 21 2022 1.24.6_redhat_7_x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 257149919 Nov 21 2022 1.24.6_redhat_7_x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 358443862 Nov 21 2022 1.24.6_redhat_8_x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 364215476 Nov 21 2022 1.24.6_redhat_8_x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 50027539 Nov 21 2022 containerd-1.4.13-d2iq.1-centos-7.9-x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 54357021 Nov 21 2022 containerd-1.4.13-d2iq.1-centos-7.9-x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 50027557 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-7.9-x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 54357666 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-7.9-x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 50033356 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-8.4-x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 54364242 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-8.4-x86_64_fips.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 50058793 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-8.6-x86_64.tar.gz
-rw-r--r-- 1 ubuntu ubuntu 54867387 Nov 21 2022 containerd-1.4.13-d2iq.1-rhel-8.6-x86_64_fips.tar.gz
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 images
-rw-r--r-- 1 ubuntu ubuntu 14957643 Nov 21 2022 pip-packages.tar.gz
```
The artifacts directory contains all the packages needed for an airgap install for a supported operating system.
The images directory in the artifacts contains all the images that run the base Kubernetes components. This allows an airgap install to start up without needing an external repo. An external repo is still needed, but this allows the cluster to bootstrap and become debuggable without an external repo
You can examine the included image layers.
```bash
tar -tf artifacts/images/kubernetes-images-1.24.6-d2iq.1.tar
```
*images*
The images folder in the kib directory contains the needed packer configs for launching a VM, configuring it, and republishing it for use by CAPI and DKP.
```bash
ls -al images/
total 32
drwxr-xr-x 7 ubuntu ubuntu 4096 Aug 25 03:41 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 25 03:41 ..
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 ami
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 azure
-rw-r--r-- 1 ubuntu ubuntu 481 Nov 15 2022 common.yaml
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 gcp
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 generic
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 ova
```
For this lab, we will be using AWS, so examine the ami directory.
```bash
ls -al images/ami
total 48
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 25 03:41 .
drwxr-xr-x 7 ubuntu ubuntu 4096 Aug 25 03:41 ..
-rw-r--r-- 1 ubuntu ubuntu 303 Nov 15 2022 centos-79.yaml
-rw-r--r-- 1 ubuntu ubuntu 428 Nov 15 2022 flatcar.yaml
-rw-r--r-- 1 ubuntu ubuntu 337 Nov 15 2022 oracle-79.yaml
-rw-r--r-- 1 ubuntu ubuntu 335 Nov 15 2022 oracle-84.yaml
-rw-r--r-- 1 ubuntu ubuntu 324 Nov 15 2022 rhel-79.yaml
-rw-r--r-- 1 ubuntu ubuntu 324 Nov 15 2022 rhel-84.yaml
-rw-r--r-- 1 ubuntu ubuntu 324 Nov 15 2022 rhel-86.yaml
-rw-r--r-- 1 ubuntu ubuntu 319 Nov 15 2022 sles-15.yaml
-rw-r--r-- 1 ubuntu ubuntu 369 Nov 15 2022 ubuntu-18.yaml
-rw-r--r-- 1 ubuntu ubuntu 364 Nov 15 2022 ubuntu-20.yaml
```
These will give clues to the air-gapped versions supported by an airgap install.
Examine the Centos 7.9 yaml file.
```bash
cat images/ami/centos-79.yaml
download_images: true
packer:
ami_filter_name: "CentOS Linux 7*"
ami_filter_owners: "125523088429"
distribution: "CentOS"
distribution_version: "7.9"
source_ami: ""
ssh_username: "centos"
root_device_name: "/dev/sda1"
build_name: "centos-7"
packer_builder_type: "amazon"
python_path: ""
```
Here is where we can specify a base image to start with.
For more complicated installs, more environment variables may be needed.
*ansible*
The Ansible directory contains all the code that is used to configure the VM after start-up to make it ready for CAPI. This allows customers to also add specific custom Ansible as well for additional configuration.
```bash
ls -al ansible/
total 56
drwxr-xr-x 6 ubuntu ubuntu 4096 Aug 25 03:41 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 25 03:41 ..
-rw-r--r-- 1 ubuntu ubuntu 13 Nov 15 2022 .tool-versions
-rw-r--r-- 1 ubuntu ubuntu 598 Nov 15 2022 .yamllint
-rw-r--r-- 1 ubuntu ubuntu 212 Nov 15 2022 Makefile
-rw-r--r-- 1 ubuntu ubuntu 3850 Nov 15 2022 README.md
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 25 03:41 group_vars
drwxr-xr-x 6 ubuntu ubuntu 4096 Aug 25 03:41 molecule
-rw-r--r-- 1 ubuntu ubuntu 1180 Nov 15 2022 provision.yaml
-rw-r--r-- 1 ubuntu ubuntu 87 Nov 15 2022 requirements.txt
drwxr-xr-x 18 ubuntu ubuntu 4096 Aug 25 03:41 roles
-rw-r--r-- 1 ubuntu ubuntu 726 Nov 15 2022 upload-artifacts.yaml
-rw-r--r-- 1 ubuntu ubuntu 154 Nov 15 2022 valid
```
Do not change anything in this folder for this lab.
### Build an image
We need an image that is available to use as a base template.
`ami-0686851c4e7b1a8e1`
Run the command to build an image.
```bash
./konvoy-image build aws --source-ami ami-0686851c4e7b1a8e1 --region us-west-2 images/ami/centos-79.yaml --overrides overrides/offline.yaml
```
You will see the state of the packer output and then a lot of Ansible, then some goss checks, and then more packer to repos the image.
### Examine image
Your instructor will have to start the image so you can look at it.