eclipse-jkube / jkube

Build and Deploy java applications on Kubernetes
https://www.eclipse.dev/jkube/
Eclipse Public License 2.0
775 stars 521 forks source link

Container image does not contain registry #1368

Open rechandler12 opened 2 years ago

rechandler12 commented 2 years ago

Description

When I run k8s:resource image in container spec does not contain registry. And Kubernetes cannot download image from docker.

Plugin config:

<plugin>
    <groupId>org.eclipse.jkube</groupId>
    <artifactId>kubernetes-maven-plugin</artifactId>
    <version>${kubernetes-maven-plugin.version}</version>
    <executions>
        <execution>
            <phase>deploy</phase>
            <goals>
                <goal>resource</goal>
                <goal>helm</goal>
                <goal>build</goal>
                <goal>push</goal>
                <goal>helm-push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <registry>nexus.xxx.pl</registry>
        <helm>
            <parameters>
                <parameter>
                    <name>namespace</name>
                    <value>{{ .Release.Namespace }}</value>
                </parameter>
                <parameter>
                    <name>replicaCount</name>
                    <value>1</value>
                </parameter>
            </parameters>
            <stableRepository>
                <name>helm-xxx-nexus-releases</name>
                <url>xxx</url>
                <type>NEXUS</type>
            </stableRepository>
            <snapshotRepository>
                <name>helm-xxx-nexus-snapshots</name>
                <url>xxx</url>
                <type>NEXUS</type>
            </snapshotRepository>
        </helm>
    </configuration>
</plugin>

I run command:

mvn clean verify k8s:resource k8s:helm k8s:build -DskipTests "-Djkube.docker.verbose=true"

Logs in console:

[INFO] --- kubernetes-maven-plugin:1.7.0:resource (default-cli) @ gus-api ---
[INFO] k8s: Running generator spring-boot
[INFO] k8s: spring-boot: Using Docker image quay.io/jkube/jkube-java:0.0.13 as base / builder
[INFO] k8s: Using resource templates from C:\dev\xxx\gus\src\main\jkube
[INFO] k8s: jkube-controller: Adding a default Deployment
[INFO] k8s: jkube-service: Adding a default service 'gus-api' with ports [8585]
[INFO] k8s: jkube-healthcheck-spring-boot: Adding readiness probe on port 8585, path='/actuator/health', scheme='HTTP', with initial delay 10 seconds
[INFO] k8s: jkube-healthcheck-spring-boot: Adding liveness probe on port 8585, path='/actuator/health', scheme='HTTP', with initial delay 180 seconds
[INFO] k8s: jkube-service-discovery: Using first mentioned service port '8585' 
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.7.0:helm (default-cli) @ gus-api ---
[INFO] k8s: Creating Helm Chart "gus-api" for Kubernetes
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.7.0:build (default-cli) @ gus-api ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s: Running generator spring-boot
[INFO] k8s: spring-boot: Using Docker image quay.io/jkube/jkube-java:0.0.13 as base / builder
[INFO] k8s: spring-boot: Using fat jar packaging as the spring boot plugin is using `repackage` goal execution
[INFO] k8s: spring-boot: Using fat jar packaging as the spring boot plugin is using `repackage` goal execution
[INFO] k8s: spring-boot: Using fat jar packaging as the spring boot plugin is using `repackage` goal execution
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - wildfly-jar
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - micronaut
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[INFO] k8s: [xxx/gus-api:latest] "spring-boot": Created docker-build.tar in 746 milliseconds
[INFO] k8s: Step 1/5 : FROM quay.io/jkube/jkube-java:0.0.13
[INFO] k8s: 
[INFO] k8s: ---> 8dda6abd56da
[INFO] k8s: Step 2/5 : ENV JAVA_APP_DIR=/deployments
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> 012807ba7cf3
[INFO] k8s: Step 3/5 : LABEL org.label-schema.description="App for searching company from GUS" org.label-schema.version=1.0.0-SNAPSHOT org.label-schema.schema-version=1.0 org.label-schema.build-date=2022-03-21T14:39:37.49640
6500 org.label-schema.name="GUS Api" org.label-schema.vcs-ref=544c6714dea07703c94de91a8aeb0106ad3bbab8 org.label-schema.url=https://www.xxx.com org.label-schema.vendor="xxx Sp. z o.o." org.label-schema.vcs-url=ssh://
xxx@10.0.0.0:29418/xxx/gus
[INFO] k8s: 
[INFO] k8s: ---> Running in 76d4d75c2e8e
[INFO] k8s: Removing intermediate container 76d4d75c2e8e
[INFO] k8s: ---> 47f75e702b35
[INFO] k8s: Step 4/5 : EXPOSE 8585 8778 9779
[INFO] k8s: 
[INFO] k8s: ---> Running in c836ee679fa1
[INFO] k8s: Removing intermediate container c836ee679fa1
[INFO] k8s: ---> 8f6c2442ff16
[INFO] k8s: Step 5/5 : COPY /jkube-generated-layer-original/deployments /deployments/
[INFO] k8s: ---> 8e04fe015f27
[INFO] k8s: Successfully built 8e04fe015f27
[INFO] k8s: Successfully tagged xxx/gus-api:latest
[INFO] k8s: [xxx/gus-api:latest] "spring-boot": Built image sha256:8e04f
[INFO] k8s: [xxx/gus-api:latest] "spring-boot": Removed old image sha256:21f18
[INFO] k8s: [xxx/gus-api:latest] "spring-boot": Tag with latest

And my final file contain:

      labels:
        app: gus-api
        provider: jkube
        version: 1.0.0-SNAPSHOT
        group: pl.xxx
    spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        image: xxx/gus-api:latest
        imagePullPolicy: IfNotPresent

It should be:

        image: nexus.xxx.pl/xxx/gus-api:latest

I think jkube-image enricher should do the job. But it just doesn't work. It also should set imagePullPolicy to Always as it it version latest.

Enricher has already code for those tasks: https://github.com/eclipse/jkube/blob/master/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/ImageEnricher.java methods: mergeImage mergeImagePullPolicy

Info

manusa commented 2 years ago

I think jkube-image enricher should do the job. But it just doesn't work. It also should set imagePullPolicy to Always as it it version latest.

Duplicate of https://github.com/eclipse/jkube/issues/1138

rechandler12 commented 2 years ago

I think jkube-image enricher should do the job. But it just doesn't work. It also should set imagePullPolicy to Always as it it version latest.

Duplicate of #1138

agree but only this part, lack of registry is new issue

manusa commented 2 years ago

Regarding the registry, I'm unsure if the global registry configuration is supposed to alter the resulting image name.

In your case, I assume that what's happening is: Performing a k8s:push should push the image to the configured registry. Resource YAML files don't contain registry information (i.e. your cluster should be configured to pull the images from the private registry).

In your case, the easiest workaround should be to configure the complete image name including the registry (as this is supposed to be part of the image name, since you want to force the pull from that registry)

<properties>
  <jkube.generator.name>nexus.xxx.pl/%g/%a:%l</jkube.generator.name>
</properties>

As I said, I'm unsure if we want to change this behavior, since users might be performing pushes to different registries just by switching a command line argument. (e.g. you might want to push the same image to quay.io and docker.io).

rechandler12 commented 2 years ago

Okey, thanks. This workaround should be enough. If you don't want to change this behavior, maybe consider new config param: registry, or addGlobalRegistry. Something like this.