Kubernetes Pod Template的Pod,服务,部署yaml文件问题?

狼行天下 发表于: 2019-12-15   最后更新时间: 2019-12-15 23:27:01   2,494 游览

为了自己的兴趣,我正在研究kubernetes,我正在尝试创建jenkins jobs来部署我们的应用程序。 我有一台master和work计算机,并且都已启动并且正在运行,我可以将两台计算机从一台ping到另一台。

到目前为止,我的集群是全新的安装环境,因此没有任何pods和deployment服务。现在,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 jobs,上述docker和nodejs镜像将从docker注册表中下载,并将其保存到我的本地计算机中?这将如何工作,请您给我解释一下吗?

发表于 2019-12-15
添加评论

上面的代码是针对jenkins插件的:https://github.com/jenkinsci/kubernetes-plugin。

因此,运行上述jenkins将在master或node服务器上运行job。镜像将下载到master/node上。上面的插件用于设置jenkins代理,因此,如果没有代理,就会在master上运行。

你的答案

查看kubernetes相关的其他问题或提一个您自己的问题