gpt4 book ai didi

kubernetes - Jenkinsfile模板来安装卷

转载 作者:行者123 更新时间:2023-12-02 12:15:28 25 4
gpt4 key购买 nike

这是我来自Jenkinsfile的containerTemplate代码段,该代码段在Kubernetes上创建了一个pod和一个名为mvn-c1的容器。

containerTemplate(
name: 'mvn-c1',
image: 'mycompany.lab/build_images/mvn_c1_k8s:0.3',
privileged: true,
ttyEnabled: true,
command: 'cat',
imagePullSecrets: ['docker-repo'],

volumeMounts: [ name: 'maven-repo1' , mountPath: '/root/.m2' ],
volumes: [
nfsVolume( mountPath: '/root/.m2', serverAddress: 'nfs-server-ip',
serverPath: '/jenkins_data', readOnly: false ),
]
)

问题在于该卷无法安装到容器,也不会在控制台上显示任何解析错误。

我已经引用 this documentation来构造 containerTemplate
有人尝试过这种方法吗?

最佳答案

欢迎使用StackOverflow @Vamshi

我认为您当前的管道定义存在两个问题:

  • volumes是podTemplate的一部分,而不是containerTemplate

  • WARNING: Unknown parameter(s) found for class type 'org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate': volumes


  • 通常,您的Kubernetes插件会在NFS服务器所在的另一个命名空间中生成Jenkins slave Pods,因此将NFS卷指定为“serverAddress”作为NFS服务器的IP地址而不是其Kubernetes服务名称更为安全。

  • 这是一个完整的示例:
    podTemplate(containers: [
    containerTemplate(name: 'maven',
    image: 'maven:3.3.9-jdk-8-alpine',
    ttyEnabled: true,
    command: 'cat')
    ],
    volumes: [
    nfsVolume( mountPath: '/root/.m2', serverAddress: '10.0.174.57',
    serverPath: '/', readOnly: false ),
    ]
    ) {

    node(POD_LABEL) {
    stage('Get a Maven project') {
    container('maven') {
    stage('Build a Maven project') {
    sh 'while true; do date > /root/.m2/index.html; hostname >> /root/.m2/index.html; sleep $(($RANDOM % 5 + 5)); done'
    }
    }
    }

    }
    }

    验证安装在POD内基于nfs的持久卷的正确性:
    kubectl exec container-template-with-nfs-pv-10-cl42l-042tq-z3n7b -c maven -- cat /root/.m2/index.html

    Output: Mon Aug 26 14:47:28 UTC 2019 nfs-busybox-9t7wx

    关于kubernetes - Jenkinsfile模板来安装卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57257545/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com