K8S + Jenkins 动态增减 slave节点自动部署VUE前端

1,637 views次阅读
没有评论

本文中,自动构建部署过程大概完成了以下项目:

  • 1 代码提交至 git,触发 Jenkins 自动构建
  • 2 Jenkins 动态在 Kubernetes 集群创建 slave Pod
  • 3 slave Pod 拉取项目代码,执行编译,打包为镜像,推送至第三方镜像仓库
  • 4 slave Pod 执行 kubectl,更新项目的 Deployment 中的镜像版本为最新版本,自动部署完成

K8S

基础环境

IP地址 运行程序
172.20.2.10 k8s-master
172.20.2.11 k8s-node1,NFS
172.20.2.12 k8s-node2
172.20.2.13 Gitlab

 

部署Jenkins

1、创建一个kube-ops的 namespace:

kubectl create namespace kube-ops

2、创建pv、pvc:

注:下面使用的是nfs的存储方式

[root@k8s-master jenkins-deployment]# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: opspv
spec:
  capacity:
    storage: 20Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Delete
  nfs:
    server: 172.20.2.11
    path: /data/volumes/v1

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: opspvc
  namespace: kube-ops
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi

3、创建需要用到的 PVC 对象:

kubectl create -f pv.yaml

4、给jenkins绑定权限

[root@k8s-master jenkins-deployment]# cat sa.yaml 
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
  namespace: kube-ops

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: jenkins
rules:
  - apiGroups: ["extensions", "apps"]
    resources: ["deployments"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
  - apiGroups: [""]
    resources: ["services"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["create","delete","get","list","patch","update","watch"]
  - apiGroups: [""]
    resources: ["pods/exec"]
    verbs: ["create","delete","get","list","patch","update","watch"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get","list","watch"]
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get"]

---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins
  namespace: kube-ops
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: jenkins
subjects:
  - kind: ServiceAccount
    name: jenkins
    namespace: kube-ops

5、创建 rbac 相关的资源对象:

$ kubectl create -f sa.yaml
serviceaccount "jenkins" created
role.rbac.authorization.k8s.io "jenkins" created
rolebinding.rbac.authorization.k8s.io "jenkins" created

6、新建一个 Deployment:(jenkins.yaml)

[root@k8s-master jenkins-deployment]# cat jenkins.yaml 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  namespace: kube-ops
spec:
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      terminationGracePeriodSeconds: 10
      serviceAccount: jenkins
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        resources:
          limits:
            cpu: 1000m
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 512Mi
        livenessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        volumeMounts:
        - name: jenkinshome
          subPath: jenkins
          mountPath: /var/jenkins_home
        env:
        - name: LIMITS_MEMORY
          valueFrom:
            resourceFieldRef:
              resource: limits.memory
              divisor: 1Mi
        - name: JAVA_OPTS
          value: -Xmx$(LIMITS_MEMORY)m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai
      securityContext:
        fsGroup: 1000
      volumes:
      - name: jenkinshome
        persistentVolumeClaim:
          claimName: opspvc

---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: kube-ops
  labels:
    app: jenkins
spec:
  selector:
    app: jenkins
  type: NodePort
  ports:
  - name: web
    port: 8080
    targetPort: web
    nodePort: 30002
  - name: agent
    port: 50000
    targetPort: agent

通过 NodePort 的形式来暴露 Jenkins 的 web 服务,固定为30002端口

另外还需要暴露一个 agent 的端口,这个端口主要是用于 Jenkins 的 master 和 slave 之间通信使用的

7、创建 Jenkins 服务:

kubectl create -f jenkins.yaml
deployment.extensions "jenkins" created
service "jenkins" created

完成

[root@k8s-master jenkins-deployment]# kubectl get pods -n kube-ops
NAME                      READY   STATUS    RESTARTS   AGE
jenkins-6b874b8d7-cwp5q   1/1     Running   0          5d

K8S

配置 Jenkins 动态 slave

1、安装 Kubernetes 插件(Jenkins 插件管理中搜索安装即可)

2、安装完毕后,点击 Manage Jenkins —> Configure System —> (拖到最下方)Add a new cloud —> 选择 Kubernetes,然后填写 Kubernetes 和 Jenkins 配置信息。

K8S

注意 namespace,这里填 kube-ops,然后点击Test Connection,如果出现 Connection test successful 的提示信息证明 Jenkins 已经可以和 Kubernetes 系统正常通信了,然后下方的 Jenkins URL 地址:http://jenkins.kube-ops.svc.cluster.local:8080,这里的格式为:服务名.namespace.svc.cluster.local:8080,根据上面创建的jenkins 的服务名填写

3、配置 Pod Template

即配置动态生成的 slave 运行的模板

模板镜像可自定义制作,具体步骤见 jenkins-slave镜像制作

其中,运行的命令和命令参数为空!

K8S

K8S

需要在下面挂载两个主机目录,一个是/var/run/docker.sock,该文件是用于 Pod 中的容器能够共享宿主机的 Docker,使用 docker in docker 的方式,Docker 二进制文件已经打包到上面的镜像中了,另外一个目录下/root/.kube目录,将这个目录挂载到容器的/root/.kube目录下面这是为了能够在 Pod 的容器中能够使用 kubectl 工具来访问 Kubernetes 集群,方便后面在 Slave Pod 部署 Kubernetes 应用。

K8S

动态 slave 测试

添加一个 Job 任务,看是否能够在 Slave Pod 中执行,任务执行完成后看 Pod 是否会被销毁.

注意在下面的 Label Expression 这里要填入 jnlp-slave,就是前面配置的 Slave Pod 中的 Label,这两个地方必须保持一致

K8S

echo "测试 Kubernetes 动态生成 jenkins slave"
echo "==============docker in docker==========="
docker info

echo "=============kubectl============="
kubectl get pods -n kube-ops

K8S

在页面点击“构建”

K8S

[root@k8s-master ~]# kubectl get pods -n kube-ops -o wide -w
NAME                      READY   STATUS    RESTARTS   AGE    IP            NODE        NOMINATED NODE   READINESS GATES
jenkins-6b874b8d7-cwp5q   1/1     Running   0          5d1h   10.244.1.65   k8s-node1   <none>           <none>
jnlp-slave-g4m3g          0/1     Pending   0          0s     <none>        <none>      <none>           <none>
jnlp-slave-g4m3g          0/1     Pending   0          0s     <none>        k8s-node2   <none>           <none>
jnlp-slave-g4m3g          0/1     ContainerCreating   0          0s     <none>        k8s-node2   <none>           <none>
jnlp-slave-g4m3g          1/1     Running             0          67s    10.244.2.107   k8s-node2   <none>           <none>
jnlp-slave-g4m3g          1/1     Terminating         0          89s    10.244.2.107   k8s-node2   <none>           <none>
jnlp-slave-g4m3g          0/1     Terminating         0          90s    10.244.2.107   k8s-node2   <none>           <none>
jnlp-slave-g4m3g          0/1     Terminating         0          96s    10.244.2.107   k8s-node2   <none>           <none>
jnlp-slave-g4m3g          0/1     Terminating         0          96s    10.244.2.107   k8s-node2   <none>           <none>

 

Jenkins Pipeline 配置

1、Gitlab 配置 webhook 略,代码提交到 Gitlab 时,会自动触发 Jenkins 构建即可。

2、新建 Jenkins 流水线任务,添加 Jenkins 参数化构建

K8S

3、配置构建触发器

K8S

4、添加流水线,并指定 Jenkinsfile 文件

K8S

[root@k8s-master vue-demo]# cat Jenkinsfile 
node ('jnlp-slave'){
    stage('Git Clone'){
        checkout([$class: 'GitSCM', branches: [[name: '${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab_user', url:'http://172.20.2.13/root/vue-demo.git']]])
        //git credentialsId: 'gitlab_user', url: 'http://172.20.2.13/root/vue-demo.git'
    }
    stage('Install Dependence'){
        echo "Install Dependence And Build"
        sh '''
        yum install libtool-ltdl -y
        npm install -g cnpm --registry=https://registry.npm.taobao.org
	cnpm i
        npm run build
        '''
    }
    stage("Docker Build Stage"){
        echo "Docker Build Stage"
        sh '''
        docker build -t registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v${BUILD_NUMBER} .
        docker login --username=353488552@qq.com registry.cn-shanghai.aliyuncs.com --password "password"
        docker push registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v${BUILD_NUMBER}
        '''
    }
    stage("Deploy"){
        echo "K8s Deploy"
        sh '''
        kubectl set image -n kube-ops deploy/smartms smartms=registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v${BUILD_NUMBER}
        '''
    }
}

5、保存任务,进行测试

6、创建demo的Deployment 和 SVC

[root@k8s-master vue-pod]# cat vue-pod.yaml 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2019-11-28T10:01:11Z"
  generation: 1
  labels:
    app: smartms
  name: smartms
  namespace: kube-ops
spec:
  replicas: 1
  selector:
    matchLabels:
      app: smartms
  template:
    metadata:
      labels:
        app: smartms
    spec:
      containers:
      - name: smartms
        image: smartms 
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          name: web
          protocol: TCP
[root@k8s-master vue-pod]# cat vue-svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: smartms-svc
  namespace: kube-ops
  labels:
    app: smartms
spec:
  type: NodePort
  ports:
   - port: 80
     nodePort: 30004
  selector:
    app: smartms

K8S

当代码提交后的过程:

  • 1、当代码 push 到 Gitlab上,触发 Jenkins 自动构建
  • 2、Jenkins 动态创建 slave Pod ,拉起后,在该 Pod 上进行 Jenkinsfile部署
  • 3、在 slave Pod 上执行 pipeline 流水线
  • 4、拉取 VUE 代码,Webpack 打包,并根据 Dockerfile 生成镜像
  • 5、将镜像推送至第三方镜像仓库
  • 6、调用 kubectl ,修改 Deployment 的镜像版本为最新版本
  • 7、发布完成

构建日志查看[s][p]

Started by user admin
Obtained Jenkinsfile from git http://172.20.2.13/root/vue-demo.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Still waiting to schedule task
‘Jenkins’ doesn’t have label ‘jnlp-slave’
Agent jnlp-slave-p12mm is provisioned from template Kubernetes Pod Template
---
apiVersion: "v1"
kind: "Pod"
metadata:
  annotations: {}
  labels:
    jenkins: "slave"
    jenkins/jnlp-slave: "true"
  name: "jnlp-slave-p12mm"
spec:
  containers:
  - env:
    - name: "JENKINS_SECRET"
      value: "********"
    - name: "JENKINS_AGENT_NAME"
      value: "jnlp-slave-p12mm"
    - name: "JENKINS_NAME"
      value: "jnlp-slave-p12mm"
    - name: "JENKINS_AGENT_WORKDIR"
      value: "/home/jenkins/agent"
    - name: "JENKINS_URL"
      value: "http://jenkins.kube-ops.svc.cluster.local:8080/"
    image: "registry.cn-shanghai.aliyuncs.com/cloudcared/jenkins-slave:1.0.1"
    imagePullPolicy: "IfNotPresent"
    name: "jnlp"
    resources:
      limits: {}
      requests: {}
    securityContext:
      privileged: false
    tty: true
    volumeMounts:
    - mountPath: "/home/jenkins/.kube"
      name: "volume-2"
      readOnly: false
    - mountPath: "/usr/bin/kubectl"
      name: "volume-3"
      readOnly: false
    - mountPath: "/var/run/docker.sock"
      name: "volume-1"
      readOnly: false
    - mountPath: "/usr/bin/docker"
      name: "volume-0"
      readOnly: false
    - mountPath: "/home/jenkins/agent"
      name: "workspace-volume"
      readOnly: false
    workingDir: "/home/jenkins/agent"
  hostNetwork: false
  nodeSelector:
    beta.kubernetes.io/os: "linux"
  restartPolicy: "Never"
  securityContext: {}
  serviceAccount: "jenkins"
  volumes:
  - hostPath:
      path: "/usr/bin/docker"
    name: "volume-0"
  - hostPath:
      path: "/root/.kube"
    name: "volume-2"
  - hostPath:
      path: "/var/run/docker.sock"
    name: "volume-1"
  - emptyDir:
      medium: ""
    name: "workspace-volume"
  - hostPath:
      path: "/usr/bin/kubectl"
    name: "volume-3"

Running on jnlp-slave-p12mm in /home/jenkins/agent/workspace/pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Git Clone)
[Pipeline] checkout
using credential gitlab_user
Cloning the remote Git repository
Cloning repository http://172.20.2.13/root/vue-demo.git
 > git init /home/jenkins/agent/workspace/pipeline # timeout=10
Fetching upstream changes from http://172.20.2.13/root/vue-demo.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials gitlab_user
 > git fetch --tags --progress http://172.20.2.13/root/vue-demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url http://172.20.2.13/root/vue-demo.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url http://172.20.2.13/root/vue-demo.git # timeout=10
Fetching upstream changes from http://172.20.2.13/root/vue-demo.git
using GIT_ASKPASS to set credentials gitlab_user
 > git fetch --tags --progress http://172.20.2.13/root/vue-demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 03bbe680d827f86f4ca239267e77c65d605be45f (refs/remotes/origin/master)
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 03bbe680d827f86f4ca239267e77c65d605be45f # timeout=10
Commit message: "Update Jenkinsfile"
 > git rev-list --no-walk 03bbe680d827f86f4ca239267e77c65d605be45f # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Install Dependence)
[Pipeline] echo
Install Dependence And Build
[Pipeline] sh
+ yum install libtool-ltdl -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * epel: mirrors.yun-idc.com
Package libtool-ltdl-2.4.2-22.el7_3.x86_64 already installed and latest version
Nothing to do
+ npm install -g cnpm --registry=https://registry.npm.taobao.org
/usr/bin/cnpm -> /usr/lib/node_modules/cnpm/bin/cnpm
+ cnpm@6.1.0
updated 1 package in 28.419s
+ cnpm i
[npminstall:get] retry GET https://registry.npm.taobao.org/@vue/cli-service/download/@vue/cli-service-4.1.1.tgz?cache=0&sync_timestamp=1574870097848&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fcli-service%2Fdownload%2F%40vue%2Fcli-service-4.1.1.tgz after 100ms, retry left 4, error: Error: getaddrinfo ENOTFOUND cdn.npm.taobao.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'cdn.npm.taobao.org',
  name: 'RequestError',
  data: undefined,
  path: '/%40vue/cli-service/-/%40vue/cli-service-4.1.1.tgz',
  status: -1,
  headers: {},
  res: [Object]
}, status: -1, headers: {}, 
stack: Error: getaddrinfo ENOTFOUND cdn.npm.taobao.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
platform unsupported @vue/cli-plugin-eslint@4.1.1 ��� webpack@4.41.2 ��� watchpack@1.6.0 ��� chokidar@2.1.8 ��� fsevents@^1.2.7 Package require os(darwin) not compatible with your platform(linux)
[fsevents@^1.2.7] optional install error: Package require os(darwin) not compatible with your platform(linux)
[npminstall:get] retry GET https://registry.npm.taobao.org/hpack.js/download/hpack.js-2.1.6.tgz after 100ms, retry left 4, error: Error: getaddrinfo ENOTFOUND cdn.npm.taobao.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'cdn.npm.taobao.org',
  name: 'RequestError',
  data: undefined,
  path: '/hpack.js/-/hpack.js-2.1.6.tgz',
  status: -1,
  headers: {},
  res: [Object]
}, status: -1, headers: {}, 
stack: Error: getaddrinfo ENOTFOUND cdn.npm.taobao.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
��� Installed 9 packages
��� Linked 929 latest versions
[1/3] scripts.install @vue/cli-plugin-eslint@4.1.1 ��� yorkie@^2.0.0 run "node bin/install.js", root: "/home/jenkins/agent/workspace/pipeline/node_modules/_yorkie@2.0.0@yorkie"
CI detected, skipping Git hooks installation
[1/3] scripts.install @vue/cli-plugin-eslint@4.1.1 ��� yorkie@^2.0.0 finished in 3s
[2/3] scripts.postinstall core-js@^3.4.3 run "node -e \"try{require('./postinstall')}catch(e){}\"", root: "/home/jenkins/agent/workspace/pipeline/node_modules/_core-js@3.4.7@core-js"
[2/3] scripts.postinstall core-js@^3.4.3 finished in 339ms
[3/3] scripts.postinstall @vue/cli-service@4.1.1 ��� webpack-bundle-analyzer@3.6.0 ��� ejs@^2.6.1 run "node ./postinstall.js", root: "/home/jenkins/agent/workspace/pipeline/node_modules/_ejs@2.7.4@ejs"
Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

[3/3] scripts.postinstall @vue/cli-service@4.1.1 ��� webpack-bundle-analyzer@3.6.0 ��� ejs@^2.6.1 finished in 208ms
��� Run 3 scripts
deprecate @vue/cli-plugin-eslint@4.1.1 ��� webpack@4.41.2 ��� watchpack@1.6.0 ��� chokidar@2.1.8 ��� fsevents@^1.2.7 One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size
Recently updated (since 2019-11-27): 21 packages (detail see file /home/jenkins/agent/workspace/pipeline/node_modules/.recently_updates.txt)
��� All packages installed (1080 packages installed from npm registry, used 38s(network 33s), speed 657.21kB/s, json 938(2.06MB), tarball 19.29MB)
+ npm run build

> vue-demo@0.1.0 build /home/jenkins/agent/workspace/pipeline
> vue-cli-service build


-  Building for production...
 DONE  Compiled successfully in 17557ms3:40:28 AM

  File                                 Size               Gzipped

  dist/js/chunk-vendors.40f56205.js    88.84 KiB          32.01 KiB
  dist/js/app.58d818dc.js              4.62 KiB           1.65 KiB
  dist/css/app.e2713bb0.css            0.33 KiB           0.23 KiB

  Images and other types of assets omitted.

 DONE  Build complete. The dist directory is ready to be deployed.
 INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
      
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Docker Build Stage)
[Pipeline] echo
Docker Build Stage
[Pipeline] sh
+ docker build -t registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v28 .
Sending build context to Docker daemon  102.8MB

Step 1/3 : FROM nginx
 ---> 231d40e811cd
Step 2/3 : COPY dist/ /usr/share/nginx/html/
 ---> Using cache
 ---> 83f713641973
Step 3/3 : COPY nginx/default.conf /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> d6672aa4d246
Successfully built d6672aa4d246
Successfully tagged registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v28
+ docker login --username=353488552@qq.com registry.cn-shanghai.aliyuncs.com --password xxzx@789
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
+ docker push registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v28
The push refers to repository [registry.cn-shanghai.aliyuncs.com/cloudcared/smartms]
aa9ea90a02f7: Preparing
e29c72ba96f0: Preparing
4fc1aa8003a3: Preparing
5fb987d2e54d: Preparing
831c5620387f: Preparing
e29c72ba96f0: Layer already exists
aa9ea90a02f7: Layer already exists
831c5620387f: Layer already exists
4fc1aa8003a3: Layer already exists
5fb987d2e54d: Layer already exists
v28: digest: sha256:aeab9dd0b1d293929f25368ccecc8d91c17994c2872e40d4a61672e8dd6a1d2a size: 1365
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] echo
K8s Deploy
[Pipeline] sh
+ kubectl set image -n kube-ops deploy/smartms smartms=registry.cn-shanghai.aliyuncs.com/cloudcared/smartms:v28
deployment.extensions/smartms image updated
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

[/p]

 

jenkins-slave镜像制作

1、编辑 Dockerfile

[root@k8s-master jenkins-slave]# cat Dockerfile 
FROM centos:7
ARG AGENT_WORKDIR=/root/agent
RUN curl --create-dirs -sSLo /usr/share/jenkins/slave.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/3.16/remoting-3.16.jar \
  && chmod 755 /usr/share/jenkins
RUN curl --create-dirs -sSLo /usr/local/bin/jenkins-slave https://raw.githubusercontent.com/jenkinsci/docker-jnlp-slave/3.27-1/jenkins-slave \
        && chmod a+x /usr/local/bin/jenkins-slave
# 处理yum源地址
COPY CentOS-Base.repo /etc/yum.repos.d/
# 安装nodejs源
RUN curl --silent --location https://rpm.nodesource.com/setup_12.x | bash
# 安装nodejs
RUN yum install epel-release nodejs -y 
# 配置淘宝NPM源加速
RUN npm install -g cnpm --registry=https://registry.npm.taobao.org
# 安装依赖
RUN yum -y install openssl openssl-devel wget sudo java-1.8.0-openjdk git ca-certificates curl mercurial procps
ENV AGENT_WORKDIR=${AGENT_WORKDIR}
RUN mkdir /root/.jenkins && mkdir -p ${AGENT_WORKDIR}
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
WORKDIR /root
ENTRYPOINT ["jenkins-slave"]
[root@k8s-master jenkins-slave]#

2、生成本地镜像

docker build -t jenkins-slave-npm .

K8S

3、将镜像推送到第三方仓库

K8S

K8S

 

Honest1y
版权声明:本站原创文章,由Honest1y于2019年12月03日发表,共计28349字。
转载提示:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)