In this example you will use S2I Operator to create a S2iBuilder and S2iRun, that simply creates a ready-to-run image and push to DockerHub.
-
Create a secret of
docker-registry
type to authenticate with container registry to push image.Create a Secret by providing credentials on the command line:
kubectl create secret docker-registry s2i-secret-sample --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
-
Create a new
s2ibuilder
, all configuration information used in building are stored ins2ibuilder
.kubectl apply -f - <<EOF apiVersion: devops.kubesphere.io/v1alpha1 kind: S2iBuilder metadata: name: s2ibuilder-sample spec: config: export: true displayName: "For Test" sourceUrl: "https://github.com/kubesphere/devops-java-sample" builderImage: kubesphere/java-8-centos7:v2.1.0 imageName: <your-registry-username>/hello-world # please replace your registry username tag: v0.0.1 builderPullPolicy: if-not-present pushAuthentication: secretRef: name: s2i-secret-sample # This secret is created by step 1. EOF
-
You can use
kubectl get s2ib
to checks2ibuilder
status.kubectl get s2ib NAME RUNCOUNT LASTRUNSTATE LASTRUNNAME s2ibuilder-sample 2 Successful s2irun-sample1
-
To start a building by
s2irun
,s2irun
define an action about build, and set filedbuilderName
to select whichs2ibuilder
in use.kubectl apply -f - <<EOF apiVersion: devops.kubesphere.io/v1alpha1 kind: S2iRun metadata: name: s2irun-sample spec: builderName: s2ibuilder-sample EOF
-
Observe created
s2ibuilder
ands2irun
:kubectl get s2ib NAME RUNCOUNT LASTRUNSTATE LASTRUNNAME LASTRUNSTARTTIME s2ibuilder-sample 1 Successful s2irun-sample 11m
kubectl get s2ir NAME STATE K8SJOBNAME STARTTIME COMPLETIONTIME IMAGENAME s2irun-sample Successful s2irun-sample-d46fc027083d-job 6m39s 5m15s kubesphere/hello-world
kubectl get po NAME READY STATUS RESTARTS AGE s2irun-sample-d46fc027083d-job-p44rx 0/1 Completed 0 11m
-
Finally, an image named
hello-world:v0.0.1
will be builded automatically and pushed to your registry.