44
loading...
This website collects cookies to deliver better user experience
application.properties
contains the location of the backend application:example.app.backend.server.protocol=http
example.app.backend.server.host=localhost
example.app.backend.server.port=8081
example.app.backend.server.messages-context=/messages
spring-boot-maven-plugin
recently added support for building OCI images through the new build-image
goal. This relies on buildpacks behind the scenes, which unfortunately does not support arm
, so the build-image
goal won’t succeed from one of the Raspberry Pis./var/run/docker.sock
from the host into the container, so the container is actually using the host’s Docker daemon. Since K3s uses containerd
as the runtime, there isn’t a Docker daemon on the host anyway.docker login
first-Djib.registry.username
and -Djib.registry.password
mvn clean package -Pjib-docker-daemon
docker images
should show the following:REPOSITORY TAG IMAGE ID CREATED SIZE
example-backend 0.0.1-SNAPSHOT ea3241a5cfd6 25 seconds ago 261MB
example-backend latest ea3241a5cfd6 25 seconds ago 261MB
example-frontend 0.0.1-SNAPSHOT 1cf33e4a9207 37 seconds ago 265MB
example-frontend latest 1cf33e4a9207 37 seconds ago 265MB
jib-k3s-private
profile to build and publish the images to private registry.docker-registry-private
. The id can be anything, we just need to reference it later.cloud-native-examples
. Under the Pipeline Definition, select Pipeline Script
and enter the following script:pipeline {
environment {
GIT_REPO_URL = 'https://github.com/bbende/cloud-native-examples.git'
GIT_REPO_BRANCH = 'main'
REGISTRY_URL = 'docker-registry-service.docker-registry.svc.cluster.local:5000'
REGISTRY_CREDENTIAL = credentials('docker-registry-private')
}
agent {
kubernetes {
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.8.1-openjdk-11
command: ["tail", "-f", "/dev/null"]
imagePullPolicy: IfNotPresent
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "1Gi"
volumeMounts:
- name: jenkins-maven
mountPath: /root/.m2
volumes:
- name: jenkins-maven
persistentVolumeClaim:
claimName: jenkins-maven-pvc
"""
}
}
stages {
stage('Git Clone') {
steps {
git(url: "${GIT_REPO_URL}", branch: "${GIT_REPO_BRANCH}")
}
}
stage('Build') {
steps {
container('maven') {
sh 'mvn package -Pjib-k3s-private -Djib.registry.username=$REGISTRY_CREDENTIAL_USR -Djib.registry.password=$REGISTRY_CREDENTIAL_PSW -DsendCredentialsOverHttp=true'
}
}
}
}
}
credentials('docker-registry-private')
maven:3.8.1-openjdk-11
jib-k3s-private
profile and overrides variables to specify the username/password for the registry using the credential environment variables/root/.m2
which comes from a Longhorn PVC. This allows the local Maven repository to be persisted across builds, instead of downloading every dependency on every build.REGISTRY_URL
is defined as docker-registry-service.docker-registry.svc.cluster.local
. This is because we have a service named docker-registry-service
in the docker-registry
namespace, but we are accessing it from Jenkins in the jenkins
namespace, so we need the fully qualified hostname.docker-registry-service
is not TLS-enabled, so we have to add -DsendCredentialsOverHttp=true
to allow Jib to authenticate over http. This is acceptable for internal communication on our example cluster, but is not recommended for a real environment.Created Pod: k3s jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Scheduled] Successfully assigned jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3 to rpi-3
Still waiting to schedule task
‘cloud-native-examples-26-k493m-qzrwp-3xpv3’ is offline
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][SuccessfulAttachVolume] AttachVolume.Attach succeeded for volume "pvc-af0ab285-fe51-48a8-be4c-f106bea22566"
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Pulled] Container image "maven:3.8.1-openjdk-11" already present on machine
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Created] Created container maven
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Started] Started container maven
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Pulled] Container image "pi4k8s/inbound-agent:4.3" already present on machine
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Created] Created container jnlp
[Normal][jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3][Started] Started container jnlp
jenkins/cloud-native-examples-26-k493m-qzrwp-3xpv3
was launched to execute the build. The persistent volume for the Maven repo was then attached and the containers were created and started.maven:3.8.1-openjdk-11
, pi4k8s/inbound-agent:4.3
, and jnlp
.[INFO Built and pushed image as docker-registry-service.docker-registry.svc.cluster.local:5000/example-frontend, docker-registry-service.docker-registry.svc.cluster.local:5000/example-frontend:0.0.1-SNAPSHOT-k3s
...
[INFO Built and pushed image as docker-registry-service.docker-registry.svc.cluster.local:5000/example-backend, docker-registry-service.docker-registry.svc.cluster.local:5000/example-backend:0.0.1-SNAPSHOT-k3s
curl -k -X GET --basic -u registry https://docker.registry.private/v2/_catalog | python -m json.tool
{
"repositories": [
"arm32v7/nginx",
"example-backend",
"example-frontend"
]
}
kubectl create namespace example-app
kubectl run example-backend --image docker.registry.private/example-backend --namespace example-app
kubectl run example-frontend --image docker.registry.private/example-frontend --namespace example-app
docker.registry.private
, which must line up with the configuration in /etc/rancher/k3s/registries.yaml
.example-app
namespace, we should see two pods come up running:kubectl get pods --namespace example-app
NAME READY STATUS RESTARTS AGE
example-backend 1/1 Running 0 102s
example-frontend 1/1 Running 0 59s
arm64
.44