Source to Image: Publish your app without Dockerfile
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.
Prerequisites
- The example below takes the GitHub codes repository and DockerHub repositories for example. Make sure you have created and DockerHub accounts.
- Build workspace, projects and accounts for common users at first. If not, please refer to .
- Use
project-admin
to inviteproject-regular
, regular users, to join in the project. Refer to Quick Start Guide of Multi-tenant Management-inviting members to grant theoperator
role.
20-30 minutes (The time varies according to the Internet speed and other factors.)
Hands-on Lab
Create the secrets for DockerHub repository and GitHub codes repository as dockerhub-id and github-id. Please refer to Creating Common Secrets
Fork Project
Login GitHub. Fork the GitHub repository devops-java-sample to your personal GitHUb.
Step 1: Fill in basic information
1.1 Click Deployment and enter.
1.2 Click Create.
- Name: (Necessary) Name the deployment as
s2i-test
; - Description: Simply decirbe the deployment information. This is customizable.
Step 2: Container Group Template Settings
2.1. Click Next and then click Add Container.
2.2. Then choose Build a new container image from code
.
2.3. Fork the to your personal GItHUb. Then copy your personal repository’s git address.
2.4. Refer to the following information and fill in.
- Code URL: Paste the git address fromt he last step (Git, HTTP and HTTPS are fine. You can also specify the related path in the source code terminal);
- Secret: Inject the secret
github-id
into the S2I Pod; - Mirroring Template: Choose as the Builder image.
- Code relative path: Use
/
by default. - Image Name: It can be customized. The user names here are
dockerhub_username>/hello
anddockerhub_username
. - Tag: The mirroring tag can be
latest
by default. - Target image repository: Choose
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 . 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.
Complete the creation
The green check below indicates that the mirroring had been created by s2i.
Check the container group. Function well.
Verify The Operation Results
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.
Step 1: Create a Service
Choose Network & Services → Services on the left menu, then click on the Create button.
Step 2: Fill in the basic information
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.
- Port name: s2i-port
- TCP defaulted, Port Number:
8080
and the target port is8080
. - Finish the settings then click Next.
Step 5: Tag setting
Setting by default then click Next.
Step 6: Setting External Network Access
Select the access method as .
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:
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.