【问题标题】:Kubernetes Pod Template Pre Pod,Service,Deployment yaml fileKubernetes Pod 模板 Pre Pod,Service,Deployment yaml 文件
【发布时间】:2019-12-14 19:52:05
【问题描述】:

为了自己的兴趣,我正在学习 kubernetes,我正在尝试创建 jenkins 工作来部署我们的应用程序。我有一台主机和一台工作机器,两台机器都已启动并正在运行,我可以将两台机器从一台机器ping通到另一台机器。

到目前为止,我的集群没有任何 Pod 和部署服务,它是全新的设置环境。 现在 jenkins 文件包含用于 nodejs 和 docker 的 Pod 模板,单阶段安装 NPM 模块。

def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(
    cloud: 'kubernetes',
    namespace: 'test',
    imagePullSecrets: ['regcred'],
    label: label,
    containers: [
        containerTemplate(name: 'nodejs', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'docker', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'kubectl', image: 'k8spoc1/kubctl:latest', ttyEnabled: true, command: 'cat')
    ],
    volumes: [
        hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
        hostPathVolume(hostPath: '/root/.m2/repository', mountPath: '/root/.m2/repository')
    ]
) {

    node(label) {
      def scmInfo = checkout scm
      def image_tag
      def image_name
      sh 'pwd'
      def gitCommit = scmInfo.GIT_COMMIT
      def gitBranch = scmInfo.GIT_BRANCH
      def commitId
      commitId= scmInfo.GIT_COMMIT[0..7]
      image_tag = "${scmInfo.GIT_BRANCH}-${scmInfo.GIT_COMMIT[0..7]}"

      stage('NPM Install') {
           container ('nodejs') {
              withEnv(["NPM_CONFIG_LOGLEVEL=warn"]) {
                sh 'npm install'
            }
           }
      }
   }
}

现在的问题是,如果使用上面的代码运行 jenkins 作业,上面提到的 docker 和 nodejs 图像将从 docker 注册表下载,这将保存到我的本地机器中吗?这将如何工作,你能请人解释一下吗?

【问题讨论】:

    标签: jenkins kubernetes


    【解决方案1】:

    以上代码用于jenkins插件https://github.com/jenkinsci/kubernetes-plugin

    因此,运行上述 jenkins 将在代理或主机上运行作业。图像将被下载到该代理/主服务器。上面的插件是用来设置jenkins代理的,所以如果没有代理,就会在master上运行。

    【讨论】:

    • 嗨,Sham,非常感谢,根据我从 docker hub 注册表下载图像后的理解,我可以使用此命令在我的主机中查看图像 $ docker images ?我是对的?
    • 是的,您应该能够使用 docker images 命令查看图像。您正在安装路径 hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),因此运行此作业的主机将拥有图像。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2022-01-03
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多