Binary to Image: Publish an Artifact to Kubernetes

    In a B2I workflow, you do not need to write any Dockerfile. This not only reduces learning costs but improves release efficiency, which allows users to focus more on business.

    This tutorial demonstrates two different ways to build an image based on an artifact in a B2I workflow. Ultimately, the image will be released to Docker Hub.

    For demonstration and testing purposes, here are some example artifacts you can use to implement the B2I workflow:

    • You have enabled the KubeSphere DevOps System.
    • You need to create a account. GitLab and Harbor are also supported.
    • Set a CI dedicated node for building images. This is not mandatory but recommended for the development and production environment as it caches dependencies and reduces build time. For more information, see Set a CI Node for Dependency Caching.

    The steps below show how to upload an artifact, build an image and release it to Kubernetes by creating a Service in a B2I workflow.

    You must create a Docker Hub Secret so that the Docker image created through B2I can be push to Docker Hub. Log in to KubeSphere as project-regular, go to your project and create a Secret for Docker Hub. For more information, see .

    Step 2: Create a Service

    1. In the same project, navigate to Services under Application Workloads and click Create.

    2. Scroll down to Create Service from Artifact and select WAR. This tutorial uses the project as a sample and uploads a war artifact to KubeSphere. Set a name, such as b2i-war-java8, and click Next.

    3. On the Build Settings page, provide the following information accordingly and click Next.

      Service Type: Select Stateless Service for this example. For more information about different Services, see Service Type.

      Artifact File: Upload the war artifact ().

      Build Environment: Select kubesphere/tomcat85-java8-centos7:v2.1.0.

      Image Name: Enter or <HARBOR-PROJECT_NAME>/<IMAGE NAME> as the image name.

      Image Tag: The image tag. Enter latest.

      Target Image Registry: Select the Docker Hub Secret as the image is pushed to Docker Hub.

    4. Note

      For more information about how to set other parameters on the Container Settings page, see Pod Settings.

    5. On the Volume Settings page, you can add a volume for the container. For more information, see . Click Next to continue.

    6. On the Advanced Settings page, select External Access and choose NodePort as the access method. Click Create to finish the whole process.

    7. Click Image Builders from the navigation bar and you can see that the example image is being built.

    1. Wait for a while and you can see the status of the image builder has reached Successful.

    2. Click this image to go to its details page. Under Job Records, click Binary to Image: Publish an Artifact to Kubernetes - 图2 on the right of a record to see building logs. You can see Build completed successfully at the end of the log if everything runs normally.

    3. Go back to the Services, Deployments, and Jobs page, and you can see the corresponding Service, Deployment, and Job of the image have been all created successfully.

    Step 4: Access the B2I Service

    1. On the Services page, click the B2I Service to go to its details page, where you can see the port number has been exposed.

    2. Access the Service at http://<Node IP>:<NodePort>/<Binary-Package-Name>/.

      Note

      You may need to open the port in your security groups and configure port forwarding rules depending on your deployment environment.

    The example above implements the entire workflow of B2I by creating a Service. Alternatively, you can use the Image Builder directly to build an image based on an artifact while this method will not publish the image to Kubernetes.

    Make sure you have created a Secret for Docker Hub. For more information, see .

    1. Log in to KubeSphere as project-regular and go to your project.

    2. Select Image Builders from the navigation bar and click Create.

    3. In the displayed dialog box, select Binary and click Next.

    4. On the Build Settings page, provide the following information accordingly and click Create.

      Artifact File: Download b2i-binary and upload it to KubeSphere.

      Build Environment: Select kubesphere/s2i-binary:v2.1.0.

      Image Name: Customize an image name.

      Image Tag: The image tag. Enter .

      Target Image Registry: Select the Docker Hub Secret as the image is pushed to Docker Hub.

    5. On the Image Builder page, you can see that the image is being built.

    Step 2: Check results

    1. Wait for a while and you can see the status of the image builder has reached Successful.

    2. Click this image builder to go to its details page. Under Job Records, click Binary to Image: Publish an Artifact to Kubernetes - 图4 on the right of a record to see building logs. You can see Build completed successfully at the end of the log if everything runs normally.

    3. Go to the Jobs page, and you can see the corresponding Job of the image has been created successfully.

    4. In your Docker Hub repository, you can see that KubeSphere has pushed the image to the repository with the expected tag.