Source to Image: Publish an App without a Dockerfile
This tutorial demonstrates how to use S2I to import source code of a Java sample project into KubeSphere by creating a Service. Based on the source code, the KubeSphere Image Builder will create a Docker image, push it to a target repository and publish it to Kubernetes.
- You need to create a GitHub account and a account. GitLab and Harbor are also supported. This tutorial uses a GitHub repository to provide the source code for building and pushes an image to Docker Hub.
- You need to create a workspace, a project and a user (). The user must be invited to the project with the role of
operator
. For more information, see Create Workspaces, Projects, Users and Roles. - 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 .
Use Source-to-Image (S2I)
Log in to GitHub and fork the GitHub repository to your personal GitHub account.
Log in to KubeSphere as project-regular
. Go to your project and create a Secret for Docker Hub and GitHub respectively. For more information, see Create the Most Common Secrets.
Note
You do not need to create the GitHub Secret if your forked repository is open to the public.
In the same project, navigate to Services under Application Workloads and click Create.
Choose Java under Create Service from Source Code, name it
s2i-demo
and click Next.Note
KubeSphere has integrated common S2I templates such as Java, Node.js and Python. If you want to use other languages or customize your S2I templates, see .
On the Build Settings page, provide the following information accordingly and click Next.
Build Environment: Select kubesphere/java-8-centos7:v2.1.0.
Code Repository URL: The source code repository address (currently support Git). You can specify the code branch and the relative path in the source code terminal. The URL supports HTTP and HTTPS. Paste the forked repository URL (your own repository address) into this field.
Code Repository Branch: The branch that is used for image building. Enter
master
for this tutorial. You can enterdependency
for a cache test.Code Repository Key: You do not need to provide any Secret for a public repository. Select the GitHub Secret if you want to use a private repository.
Image Name: Customize an image name. As this tutorial will push an image to Docker Hub, enter .
dockerhub_username
is your Docker ID and make sure it has the permission to push and pull images.Image Tag: The image tag. Enter
latest
.Target Image Registry: Select the Docker Hub Secret as the image is pushed to Docker Hub.
Advanced Settings: You can define the code relative path. Use the default
/
for this field.On the Pod Settings page, scroll down to Port Settings to set the access policy for the container. Select HTTP for Protocol, customize the name (for example,
http-1
), and enter8080
for both Container Port and Service Port.On the Volume Settings page, you can add a volume for the container. For more information, see Volumes. Click Next to continue.
On the Advanced Settings page, select External Access and select NodePort as the access method. Click Create to finish the whole process.
Click Image Builders from the navigation bar and you can see that the example image is being built.
Wait for a while and you can see the status of the image builder has reached Successful.
Click this image builder to go to its details page. Under Job Records, click 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.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.
In your Docker Hub repository, you can see that KubeSphere has pushed the image to the repository with the expected tag.
To access the Service, you can either use the endpoint with the
curl
command or visit . For example:If you want to access the Service outside the cluster, you may need to open the port in your security groups and configure port forwarding rules depending on your deployment environment.