如何从fabric8-maven-plugin配置imagePullPolicy

时间:2017-08-18 01:00:17

标签: fabric8

上下文

我使用 fabric8-maven-plugin 生成docker镜像并将其部署到Kubernetes群集。

问题:

可以配置 imagePullPolicy 参数,其默认值为 IfNotPresent

pom.xml

中的当前配置
<build>
    <plugins>
        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>3.5.25</version>
            <configuration>
                <images>
                    <image>
                        <name>my-service</name>
                        <alias>service</alias>
                        <build>
                            <from>java:8</from>
                            <tags>
                                <tag>latest</tag>
                                <tag>${project.version}</tag>
                            </tags>
                            <!--
                            The entry point path used is "maven/" since this is the default folder: https://dmp.fabric8.io/#building-images,
                            "launch.sh" is copied to the container based in the assembly.xml descriptor file.
                            -->
                            <entryPoint>
                                <exec>
                                    <arg>maven/launch.sh</arg>
                                </exec>
                            </entryPoint>
                            <assembly>
                                <descriptor>assembly.xml</descriptor>
                            </assembly>
                        </build>
                    </image>
                </images>
                <generator>
                    <includes>
                        <include>java-exec</include>
                    </includes>
                    <config>
                        <java-exec>
                            <webPort>8080</webPort>
                        </java-exec>
                    </config>
                </generator>
            </configuration>
        </plugin>
    </plugins>
</build>

我得到的是:

spec:
  containers:
  - env:
    - name: KUBERNETES_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
    image: 394148814603.dkr.ecr.us-east-1.amazonaws.com/dkrecr-nafiux-ncp/kcluster-ncp-myservice
    imagePullPolicy: IfNotPresent <---- I want to personalize this value to Always, for instance.
    name: service
    securityContext:
      privileged: false

为什么我要将值更改为始终?主要是因为我正在对群集进行大量测试,而且我不想为我所做的每个测试分配一个新版本到docker镜像。

感谢您的支持。

2 个答案:

答案 0 :(得分:2)

最后我找到了我要找的参数:

1)添加最新的泊坞窗图像:

            <name>myservice:latest</name>

2)在更丰富的配置中添加 pullPolicy

            <enricher>
                <config>
                    <fmp-controller>
                        <pullPolicy>Always</pullPolicy>
                    </fmp-controller>
                </config>
            </enricher>

完整示例:

<build>
    <plugins>
        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>3.5.25</version>
            <configuration>
                <images>
                    <image>
                        <alias>service</alias>
                        <name>myservice:latest</name>
                        <build>
                            <from>java:8</from>
                            <tags>
                                <tag>latest</tag>
                                <tag>${project.version}</tag>
                            </tags>
                            <!--
                            The entry point path used is "maven/" since this is the default folder: https://dmp.fabric8.io/#building-images,
                            "launch.sh" is copied to the container based in the assembly.xml descriptor file.
                            -->
                            <entryPoint>
                                <exec>
                                    <arg>maven/launch.sh</arg>
                                </exec>
                            </entryPoint>
                            <assembly>
                                <descriptor>assembly.xml</descriptor>
                            </assembly>
                        </build>
                    </image>
                </images>
                <generator>
                    <includes>
                        <include>java-exec</include>
                    </includes>
                    <config>
                        <java-exec>
                            <webPort>8080</webPort>
                        </java-exec>
                    </config>
                </generator>
                <enricher>
                    <config>
                        <fmp-controller>
                            <pullPolicy>Always</pullPolicy>
                        </fmp-controller>
                    </config>
                </enricher>
            </configuration>
        </plugin>
    </plugins>
</build>

答案 1 :(得分:2)

将以下richher配置与生成器,图像一起添加到pom.xml。

            <configuration> 
                <enricher>
                    <config>
                        <fmp-controller>
                            <pullPolicy>Always</pullPolicy>
                        </fmp-controller>
                    </config>
                </enricher>
            </configuration>

虽然这不是理想的方式,但暂时可以使用。