I have a multi-module maven project (Spring Boot), I generate the docker images in using the JIB Maven Plugin but how should I name the images in scaffold? Im pushing to local docker repo and Skaffold afaik does not support templating. What is the recommended was to reference these images in Skaffold?
Keep in mind that for separate images per module I need to name them as:
${image.registry.host}:${image.registry.port}/${project.artifact}
So no choice really but to parametrize them in the pom.
Do I now need to put in host and port names into the skaffold file? Whats the best way to handle this atm? And how about the name in Kubernetes deployment descriptor?
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
<configuration>
<!--If you want custom base image and push registry, use below configuration replace above-->
<from>
<image>openjdk:8-jdk-alpine</image>
</from>
<to>
**<image>${image.registry.host}:${image.registry.port}/${project.artifactId}**:${project.version}</image>
</to>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Duser.timezone=GMT+08</jvmFlag>
</jvmFlags>
<mainClass>com.example.jib.JibApplication</mainClass>
<ports>
<port>8080</port>
</ports>
</container>
<allowInsecureRegistries>true</allowInsecureRegistries>
</configuration>
</plugin>
What goes in the Scaffold.yml for image name?
apiVersion: skaffold/v1beta4
kind: Config
# Enforce SKaffold to use Jib
build:
local:
push: false
# Generated artifact
artifacts:
**- image: lvthillo/my-app. ??????????? HOW SHOULD I NAME THIS?
image: module2/ ???????**
# Use jibMaven
jibMaven: {}
# Execute deployment.yml
deploy:
kubectl:
manifests:
- kubernetes/deployment.yml
Here is Kubernetes deployment descriptor.
What name should image have here???
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-deployment
spec:
replicas: 1
selector:
matchLabels:
app: spring-boot-jib
template:
metadata:
labels:
app: spring-boot-jib
spec:
containers:
- name: spring-boot-jib-pod
**image: lvthillo/my-app. ????????? What name here???**
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
apiVersion: v1
kind: Service
metadata:
name: spring-boot-jib-service
spec:
type: NodePort
ports:
- protocol: TCP
port: 8080
nodePort: 32321
selector:
app: spring-boot-jib
When using Jib with Skaffold, Skaffold is the master and overrides the image refs used by Jib. Skaffold will decide what image names should be used and will rewrite the image references in the Kubernetes manifests to match prior to deploying.
If you're developing against a local cluster such as Minikube, then Skaffold causes the images to be loaded directly into the Minikube's Docker daemon; they're never pushed to the actual registry. (In jib terms, Skaffold will invoke jib:dockerBuild
rather than jib:build
to a registry.). So you can keep your production image refs in your skaffold.yaml
.
If you're pushing to registries, then you have three options depending on your setup:
If you have a local or per-developer setups, then keep the production image refs and have developers use Skaffold's --default-repo
option: it transforms and replaces the repository portion of the image refs as specified in the skaffold.yaml
to point to this new repository.
If it's ok for developers to intermingle within the same registry and repository, then the Skaffold taggers should ensure your developers' pushed images won't conflict. You could use the [envTemplate
tagger] to generate different image tags based on environmental information like $USER
.
You can use Skaffold's profiles and patches to override images. Creating the right JSON patches can feel a bit hit or miss, but it's pretty powerful.
I personally use the --default-repo
approach.