Kubernetes Image Builder

repository·main·Indexed 20 days ago

https://github.com/kubernetes-sigs/image-builder

A tool for building Kubernetes virtual machine images across multiple infrastructure providers, optimized for Cluster API and compatible with Kubeadm-based setups. It supports various targets including MaaS, Proxmox, QEMU, and Flatcar, with capabilities for installing GPU drivers (NVIDIA, AMD), configuring security tools like Trivy and Falco, and managing Ignition files for Flatcar builds.

Tokens
36.9K
Snippets
114
Records
164
Agent score
68%

What's inside image-builder

  1. What is Image Builder?

    main

    Image Builder is a tool designed to build Kubernetes virtual machine (VM) images across multiple infrastructure providers.

    Key characteristics:

    • Target Use Case: The resulting images are specifically intended for use with Cluster API, though they are suitable for any setup relying on Kubeadm.
    • Consistency: It aims to build images for Kubernetes-conformant clusters in a consistent manner across different infrastructures and business requirements.
    • Customization: It supports end-user requirements to customize images for specific business needs.
    • Security & Stability: It provides assurances for security auditing and operational stability by allowing introspection of artifacts, software versions, and configurations, and by supporting repeatable build processes.
  2. Glossary of Image Builder terms

    main

    This glossary defines key terms, acronyms, and external technologies used within the Image Builder ecosystem. Key categories include:

    Cloud and Infrastructure Providers

    • AWS / AMI: Amazon Web Services and Amazon Machine Images.
    • CAPI (Cluster API): A Kubernetes project for declarative cluster management.
    • Cluster API Providers: Specific implementations for different environments including CAPA (AWS), CAPG (GCP), CAPIBM (IBM Cloud), CAPV (vSphere), and CAPZ (Azure).
    • VPC (Virtual Private Cloud): A private computing environment on shared public cloud infrastructure.
    • PowerVS: IBM Power Systems Virtual Server.

    Virtualization and Hypervisors

    • VM (Virtual Machine): An abstraction of an operating system from physical hardware.
    • ESXi: A type-1 hypervisor by VMware.
    • vCenter: The management layer for ESXi hosts, providing features like vMotion, vSAN, and HA.
    • vSphere: The VMware SDDC stack consisting of vCenter and ESXi.
    • OVA / OVF: Standards for packaging and distributing virtual appliances.

    Validation and Security

    • Goss: A YAML-based tool used to validate server configurations. In Image Builder, it is used with packer-provisioner-goss to test if images contain the necessary components for Cluster API.
    • gVisor: An application kernel providing isolation between applications and the host OS.
    • Sandboxed container: A container running in an environment isolated from the host kernel.

    Other Tools

    • MaaS (Metal As A Service): A tool by Canonical for automating bare-metal server provisioning.
    • K8s / Kubernetes: The container orchestration system.
  3. Load additional components (images and executables)

    main

    To load extra container images or executables, you must set load_additional_components to "true". You can then specify the types of components to load:

    • additional_url_images: Load images from a tar URL (requires additional_url_images_list).
    • additional_registry_images: Load images from a registry (requires additional_registry_images_list).
    • additional_executables: Load executables from a URL (requires additional_executables_list and additional_executables_destination_path).
    • additional_s3: Load components from an S3-compatible endpoint.
    {
      "additional_executables": "true",
      "additional_executables_destination_path": "/path/to/dest",
      "additional_executables_list": "http://path/to/exec1,http://path/to/exec2",
      "additional_s3": "true",
      "additional_s3_endpoint": "https://path-to-s3-endpoint",
      "additional_s3_access": "S3_ACCESS_KEY",
      "additional_s3_secret": "S3_SECRET_KEY",
      "additional_s3_bucket": "some-bucket",
      "additional_s3_object": "path/to/object",
      "additional_s3_destination_path": "/path/to/dest",
      "additional_s3_ceph": "true",
      "additional_registry_images": "true",
      "additional_registry_images_list": "plndr/kube-vip:0.3.4,plndr/kube-vip:0.3.3",
      "additional_url_images": "true",
      "additional_url_images_list": "http://path/to/image1.tar,http://path/to/image2.tar",
      "load_additional_components": "true"
    }
  4. How the vmware-vmx builder works

    main

    The vmware-vmx builder is optimized for local development. To avoid the time-consuming process of building the base image from an ISO every time, you can use the build-node-ova-local-base-<OS> target to create a base image.

    By setting the source_path variable in vmx.json to the *.vmx file produced by the base build, you can then use the build-node-ova-local-vmx-<OS> target to build subsequent images much faster.

  5. Proxmox Networking Requirements

    main

    For a successful build, the following networking conditions must be met:

    1. DHCP Availability: DHCP must be available to assign the Packer VM an IP, as static IP assignment is not currently supported.
    2. SSH Access: The build VM must be accessible via SSH from the host running the make commands.
    3. Service Access: The build VM requires access to DHCP, DNS, HTTP, HTTPS, and NTP to successfully update OS packages.
  6. How CAPI build targets work

    main

    Image Builder creates Cluster API (CAPI) images using Make targets defined in images/capi/Makefile.

    Each target name determines two things:

    1. The provider recipe (e.g., packer/qemu/packer.json).
    2. The Packer variable file for the specific operating system (e.g., packer/qemu/qemu-ubuntu-2404.json).

    Targets also include common Linux node variables from packer/config/*.json.

    Key distinction:

    • Use a new target name when you need a new provider and OS combination.
    • Use the PACKER_VAR_FILES environment variable to override variables for an existing target without creating a new target.

    Example: make build-qemu-ubuntu-2404 builds the image, while make validate-qemu-ubuntu-2404 validates the configuration without performing a build.

  7. How Goss is used to test CAPI images

    main

    Goss is a YAML-based tool used to validate a server's configuration. In the context of Image Builder, it is used alongside packer-provisioner-goss to ensure that images contain all the necessary components required to work with Cluster API (CAPI).

    Goss runs automatically as part of the image building process via a Packer provisioner. Configuration for this process is managed through packer/config/goss-args.json.

  8. Configure Windows service managers for kubelet

    main

    Image-builder supports two methods for configuring Windows services (specifically for kubelet):

    1. nssm (Default): Uses nssm to configure the service by running {{ kubernetes_install_path }}\StartKubelet.ps1. This allows for easy editing of command arguments within the startup file. Nssm also handles service restarts automatically.
    2. sc.exe (Native): Uses the native Windows sc.exe utility. This requires using the kubelet argument --windows-service to install kubelet as a native service.

    Important Considerations:

    • Restart Logic: If using sc.exe, you must manually configure service restart options on kubelet, as it lacks the automatic restart handling provided by nssm.
    • Cluster API Compatibility: sc.exe does not support kubeadm KUBELET_KUBEADM_ARGS, which is required by Cluster API to pass extra user arguments.
    • Startup Timing: To prevent kubelet from starting too early, image-builder sets the service to manual startup by default. You may want to change this to automatic once the node has successfully joined a cluster.
  9. How the vsphere-clone builder works

    main

    The vsphere-clone builder is designed for rapid iteration. It works in conjunction with the vsphere-base builder:

    1. vsphere-base builder: Builds a one-time base OVA from an ISO using the kickstart process. It leaves the builder intact within the base OVA.
    2. vsphere-clone builder: Builds on top of the base OVA by cloning it and applying configurations via Ansible.

    This approach saves time by using link cloning and the create_snapshot feature, avoiding the need to reinstall the OS from scratch for every build iteration.