【问题标题】:How to configure imagePullPolicy from fabric8-maven-plugin如何从 fabric8-maven-plugin 配置 imagePullPolicy
【发布时间】:2017-08-18 16:34:21
【问题描述】:

上下文:

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

问题:

是否可以配置默认值为IfNotPresentimagePullPolicy参数?

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 映像。

感谢您的支持。

【问题讨论】:

    标签: fabric8


    【解决方案1】:

    终于找到了我要找的参数:

    1) 向 docker 镜像添加最新的:

                <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>
    

    【讨论】:

    • 感谢您为找出答案所做的努力。哈哈..比赛条件:)
    【解决方案2】:

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

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

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

    【讨论】:

    • 谢谢@Hrishikesh!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    相关资源
    最近更新 更多