Kubic:Development

Jump to: navigation, search

Development and contribution

Community

Development environment

To set up virtual machines with Kubic locally, please use the kubic-terraform-kvm project and refer to the README.

Building container images

Kubic provides own RPM packagescontainer images for core Kubernetes components and for infrastructure components which we support, like:

  • CNI plugins - flannel, Cilium, weave
  • ingress controllers - Traefik
  • software which manages the lifecycle and maintenance of the cluster - for example kured

This instruction assumes that you know how openSUSE Build System works and you have the `osc` tool configured. If not, please refer to the Build Service Tutorial.

Branch project of devel:kubic:containers

Let's start from creating a branch project of devel:kubic:containers and fetching it to your local workstation:

mkdir obs
cd obs
for image in $(osc ls devel:kubic:containers); do osc bco devel:kubic:containers $image; done
cd home\:*:branches:devel:kubic:containers

Building an image

If you want to build a container image, go to the one of subdirectories and execute osc build container command. For example:

cd kubic-multus-image
osc build container

Creating a new image

Name of a new image should follow the naming convention: kubic-$name-image.

Let's assume that you want to create an image with name `foobar`. Start from creating the "package" on OBS:

osc mkpac kubic-foobar-image

Every image contains the following files:

  • _service - a file which configures OBS services
  • kubic-$name-image.changes - a changelog file created and updated by osc vc command
  • kubic-$name-image.kiwi - a KIWI file which defines the image - metadata, packages to install etc.

Let's start from creating the kubic-$name-image.kiwi file. Assuming that we want to install a foobar RPM package in that image and we want to execute the /usr/bin/foobar command by default, the content should look like:

<?xml version="1.0" encoding="utf-8"?>

<!-- OBS-ExcludeArch: i586 s390 -->

<image schemaversion="6.5" name="kubic-foobar-image" xmlns:suse_label_helper="com.suse.label_helper">
  <description type="system">
    <author>Thorsten Kukuk</author>
    <contact>kukuk@suse.com</contact>
    <specification>Foobar application</specification>
  </description>
  <preferences>
    <type
      image="docker"
      derived_from="obsrepositories:/opensuse/busybox#latest">
      <containerconfig
        name="kubic/foobar"
        tag="latest"
        additionaltags="%PKG_VERSION%,%PKG_VERSION%-%RELEASE%"
        maintainer="Thorsten Kukuk <kukuk@suse.com>">
        <entrypoint execute="/usr/bin/foobar"/>
        <labels>
          <suse_label_helper:add_prefix prefix="org.opensuse.kubic.foobar">
            <label name="org.opencontainers.image.title" value="openSUSE Kubic foobar container"/>
            <label name="org.opencontainers.image.description" value="Image containing foobar for openSUSE Kubic."/>
            <label name="org.opencontainers.image.version" value="%PKG_VERSION%-%RELEASE%"/>
            <label name="org.opencontainers.image.created" value="%BUILDTIME%"/>
            <label name="org.opensuse.reference" value="registry.opensuse.org/kubic/foobar:%PKG_VERSION%-%RELEASE%"/>
            <label name="org.openbuildservice.disturl" value="%DISTURL%"/>
          </suse_label_helper:add_prefix>
        </labels>
        <history author="Thorsten Kukuk <kukuk@suse.com>">openSUSE Kubic foobar container</history>
      </containerconfig>
    </type>
    <version>3.0.0</version>
    <packagemanager>zypper</packagemanager>
    <rpm-check-signatures>false</rpm-check-signatures>
    <rpm-excludedocs>true</rpm-excludedocs>
    <locale>en_US</locale>
    <keytable>us.map.gz</keytable>
    <hwclock>utc</hwclock>
  </preferences>
  <repository>
    <source path="obsrepositories:/"/>
  </repository>
  <packages type="bootstrap">
    <package name="foobar"/>
  </packages>
</image>

The usual convention to for versioning container images is to use the version of containerized software as the image tag and version. In our case it means, that the foobar image should have container version and tag which comes from the foobar package version.

To automate that process, create a _service with the following content:

<services>
    <service mode="buildtime" name="kiwi_metainfo_helper"/>
    <service name="replace_using_package_version" mode="buildtime">
        <param name="file">kubic-foobar-image.kiwi</param>
        <param name="regex">%PKG_VERSION%</param>
        <param name="parse-version">patch</param>
        <param name="package">foobar</param>
    </service>
    <service mode="buildtime" name="kiwi_label_helper"/>
</services>

And at the end, let's add a changelog file entry with the command:

osc vc

Usually the first changelog entry is - Initial release.

After that, check whether the image builds:

osc build container

It it does, commit your changes and submit to devel:kubic:containers:

osc submitrequest home:$user:branched:devel:kubic:containers kubic-foobar-image devel:kubic:containers kubic-foobar-image