As similar as Source to Image (S2I), Binary to Image (B2I) is a toolkit and workflow for building reproducible container images from binary executables like Jar, War, binary package, etc. All you need to do is to upload your artifact, and specify the image repository such as DockerHub or Harbor to where you want to push. After you run a B2I process, your image will be pushed to the target repository and your application will be automatically deployed to Kubernetes as well.
From the introduction above we can see B2I bridges your binary executables to cloud native services with no complicated configurations or coding which is extremely useful for legacy applications and the users who are not familiar with Docker and Kubernetes. Moreover, with B2I tool, as said, you do not need to write Dockerfile, it not only reduces learning costs but improves publishing efficiency, which enables developers to focus on business itself. In a word, B2I can greatly empower enterprises for continuous delivery that is one of the keys to digital transformation.
The following figure describes the step-by-step process of B2I. B2I has instrumented and streamlined the steps, so it takes few clicks to complete in KubeSphere console.
- ① Create B2I in KubeSphere console and upload artifact or binary package
- ② B2I will create K8s Job, Deployment and Service based on the uploaded binary
- ③ Automatically package the artifact into Docker image
- ④ Push image to DockerHub or Harbor
- ⑤ B2I Job will pull the image from registry for Deployment created in the second step
- ⑥ Automatically publish the service to Kubernetes
Note: In the process, the B2I Job also reports status in the backend.
In this document, we will walk you through how to use B2I in KubeSphere. For more testing purposes on your own, we provide five artifact packages that you can download from the sites in the following tables.
|Artifact Package (Click to download)||GitHub Repository|
project-regularaccount. Please see Get Started with Multi-tenant Management.
In this lab, we will learn how to use B2I by creating service in KubeSphere, and how to automatically complete six steps described in the workflow graph above.
We need to create a secret since B2I Job will push the image to DockerHub. If you have finished S2I lab, you already have the secret created. Otherwise, log in KubeSphere with the account
project-regular. Go to your project and create the secret for DockerHub. Please reference Creating Common-used Secrets.
2.1. Select Application Workloads → Services, then click Create to create a new service through the artifact.
2.2. Scroll down to Build a new service through the artifact and choose war. We will use the Spring-MVC-Showcase project as a sample by uploading the WAR artifact (b2i-war-java8) to KubeSphere.
2.3. Enter service name
b2i-war-java8, click Next.
2.4. Refer to the following instructions to fill in Build Settings.
tomcat85-java8-centos7:latestas the build environment.
<HARBOR-PROJECT_NAME>/<IMAGE NAME>as image name.
dockerhub-secretthat we created in previous step as target image repository: .
2.5. Click Next to the Container Settings and configure the basic info as shown in the figure below.
2.6. Click Next and continue to click Next to skip Mount Volumes.
2.7. Check Internet Access and choose NodePort, then click Create.
3.1. Choose Image Builder and click into b2i-war-java8-xxx to inspect B2I building status.
3.2. Now it is ready to verify the status. You can expand the Job records to inspect the rolling logs. Normally, it will execute successfully in 2~4 minutes.
Alternatively, if you want to use command line to inspect those resources, you can use web kubectl from the Toolbox at the bottom right of console. Note it requires cluster admin account to open the tool.
Click into service b2i-war-java8. We can get the NodePort and Endpoints. Thereby we can access the Spring-MVC-Showcase service via Endpoints within cluster, or browse the web service externally using
For the example above, enter http://188.8.131.52:30182/b2i-war-java8/ to access Spring-MVC-Showcase. Make sure the traffic can pass through the NodePort.
Sign in DockerHub with your account, you can find the image was successfully pushed to DockerHub with tag
Congratulation! Now you know how to use B2I to package your artifacts into Docker image, however, without learning Docker.