Source to Image (S2I) is a tool that allows a programmer to input source codes and transfer the codes into runnable program to Docker image. This tool enables programers to build images even when they don't know about Dockerfile. By inputing source codes into the source code compiler, Builder image, Source to Image can transfer the codes into Docker images.
The example below is an official Java demonstration for Hello World. It will show you how to use Source to Image on KubeSphere to build image, push the images to mirroring repositories and finally deploy them to clusters.
project-regular
accounts for common users at first. If not, please refer to Quick Start Guide of Multi-tenant Management.project-admin
to invite project-regular
, regular users, to join in the project. Refer to Quick Start Guide of Multi-tenant Management-inviting members to grant the operator
role.20-30 minutes (The time varies according to the Internet speed and other factors.)
Create the secrets for DockerHub repository and GitHub codes repository as dockerhub-id and github-id. Please refer to Creating Common Secrets
Login GitHub. Fork the GitHub repository devops-java-sample to your personal GitHUb.
1.1 Click Deployment and enter.
1.2 Click Create.
s2i-test
;2.1. Click Next and then click Add Container.
2.2. Then choose Build a new container image from code
.
2.3. Fork the Repository Sample to your personal GItHUb. Then copy your personal repository's git address.
2.4. Refer to the following information and fill in.
Note: KubeSphere has built in common s2i templates for Java, Node.js and Python. If you need to customize other languages or use the s2i template, please refer to Customized s2i template.
github-id
into the S2I Pod;kubespheredev/java-8-centos7
as the Builder image./
by default.dockerhub_username>/hello
and dockerhub_username
.latest
by default.dockerhub-id
created in the previous step.2.4. Scroll down to Container Specification
. It is suggested to set CPU and RAM's biggest storages as 500M and 1000Mi.
2.5. Scroll down to Service Settings
. The port number is 8080:
2.6. Then click Save.
The duplicate number is 1. The click Next.
No need to set storage volume. Click Next. Save the tag by default. Then choose Create. Complete the s2i deployment.
The green check below indicates that the mirroring had been created by s2i.
Check the container group. Function well.
If the deployment was successful through s2i, you will see the setted image in Dockerhub. The name and tage have been setted in the Container Group Template Setting. If you want to check the deployment results, you can configerate as follows.
Choose Network & Services → Services on the left menu, then click on the Create button.
This step is similar to deployment creation, e.g. Name : s2i-test-service
. The rest are customized as below.
3.1. Choose the first item Virtual IP: Access the service through the internal IP of the cluster
.
3.2. Then click on the Specify Workload
and choose springboot-s2i
deployment as below.
3.3. Click save. Refer to the port information as follows.
8080
and the target port is 8080
.Setting by default then click Next.
Select the access method as NodePort
.
For now, the service check has been created. As below, the Virtual IP is 10.233.40.2, the service port is 8080 and the Nodeport is 30454.
If you visit the HelloWorld service from the internal network, you can login cluster nodes through SSH or use Cluster admin to login KubeSphere. Then putin the following command in web kubectl:
# curl {$Virtual IP}:{$Port} or curl {$Node IP}:{$NodePort}
$ curl 10.233.60.196:8080
Hello,World!
Tip: If you need to access to this service from external network, you may need to bind to the public network EIP and set port forwarding and firewall rules. Forward the Internal Network Port 30454 to the source port 30454 in the forwarding rule. Then open this port in the firewall to ensure the external network traffic can pass this port. For operations on the QingCloud platform, you can refer to Cloud Platform Setting Port Forward and Firewall.
Since we set the target mirroring repository as DockerHub, you can login your personal DockerHub to check the image pushed by Source to Image. If you find hello:latest
, the image has been successfully pushed to DockerHub