基于Deployment部署jenkins单体服务

架构逻辑图

一、准备jenkins镜像

docker pull jenkins/jenkins:2.374
docker tag jenkins/jenkins:2.374 harbor.magedu.net/magedu/jenkins:2.374
docker push harbor.magedu.net/magedu/jenkins:2.374

二、在nfs共享存储暴露nfs共享目录

[root@easzlab-k8s-nfs-01 ~]# mkdir -p /data/k8sdata/magedu/jenkins-data
[root@easzlab-k8s-nfs-01 ~]# mkdir -p /data/k8sdata/magedu/jenkins-root-data
[root@easzlab-k8s-nfs-01 ~]# cat /etc/exports 
# /etc/exports: the access control list for filesystems which may be exported
#        to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/data 172.16.88.0/24(rw,sync,no_root_squash,no_subtree_check)
/data/k8sdata/magedu/jenkins-root-data 172.16.88.0/24(rw,sync,no_root_squash,no_subtree_check)
/data/k8sdata/magedu/jenkins-data 172.16.88.0/24(rw,sync,no_root_squash,no_subtree_check)
[root@easzlab-k8s-nfs-01 ~]#
[root@easzlab-k8s-nfs-01 ~]# exportfs -r
root@easzlab-deploy:~# showmount -e 172.16.88.169
Export list for 172.16.88.169:
/data/k8sdata/magedu/jenkins-data      172.16.88.0/24
/data/k8sdata/magedu/jenkins-root-data 172.16.88.0/24
/data                                  172.16.88.0/24
root@easzlab-deploy:~# 

三、部署jenkins服务

root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins/pv# cat jenkins-persistentvolumeclaim.yaml 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-datadir-pvc
  namespace: magedu
spec:
  volumeName: jenkins-datadir-pv
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 80Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: namespace: magedu
spec:
  volumeName: jenkins-root-datadir-pv 
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 80Gi
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins/pv# cat jenkins-persistentvolume.yaml 
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-datadir-pv
  namespace: magedu
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    server: 172.16.88.169
    path: /data/k8sdata/magedu/jenkins-data 
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-root-datadir-pv
  namespace: magedu
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    server: 172.16.88.169
    path: /data/k8sdata/magedu/jenkins-root-data
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins/pv# 
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins/pv# cd ../
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins# cat jenkins.yaml 
kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1
metadata:
  labels:
    app: magedu-jenkins
  name: magedu-jenkins-deployment
  namespace: magedu
spec:
  replicas: 1
  selector:
    matchLabels:
      app: magedu-jenkins
  template:
    metadata:
      labels:
        app: magedu-jenkins
    spec:
      containers:
      - name: magedu-jenkins-container
        image: harbor.magedu.net/magedu/jenkins:2.374
        #imagePullPolicy: IfNotPresent
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          protocol: TCP
          name: http
        volumeMounts:
        - mountPath: "/apps/jenkins/jenkins-data/"
          name: jenkins-datadir-magedu
        - mountPath: "/root/.jenkins"
          name: jenkins-root-datadir
      volumes:
        - name: jenkins-datadir-magedu
          persistentVolumeClaim:
            claimName: jenkins-datadir-pvc
        - name: jenkins-root-datadir
          persistentVolumeClaim:
            claimName: jenkins-root-data-pvc
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: magedu-jenkins
  name: magedu-jenkins-service
  namespace: magedu
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
    nodePort: 38080
  selector:
    app: magedu-jenkins
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins#
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins# kubectl create ns magedu #创建所需命名空间 namespace/magedu created root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins#
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins# kubectl apply -f jenkins.yaml -f pv/ #安装部署jenkins服务
deployment.apps/magedu-jenkins-deployment created
service/magedu-jenkins-service created
persistentvolume/jenkins-datadir-pv created
persistentvolume/jenkins-root-datadir-pv created
persistentvolumeclaim/jenkins-datadir-pvc created
persistentvolumeclaim/jenkins-root-data-pvc created
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins#

四、验证jenkins服务

初始密码查看

root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins# kubectl logs -n magedu  magedu-jenkins-deployment-79bbd88cb7-84999
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-10-23 06:38:41.696+0000 [id=1]    INFO    winstone.Logger#logInternal: Beginning extraction from war file
2022-10-23 06:38:43.667+0000 [id=1]    WARNING    o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2022-10-23 06:38:43.753+0000 [id=1]    INFO    org.eclipse.jetty.server.Server#doStart: jetty-10.0.12; built: 2022-09-14T01:54:40.076Z; git: 408d0139887e27a57b54ed52e2d92a36731a7e88; jvm 11.0.16.1+1
2022-10-23 06:38:44.277+0000 [id=1]    INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2022-10-23 06:38:44.395+0000 [id=1]    INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: Session workerName=node0
2022-10-23 06:38:45.019+0000 [id=1]    INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-10-23 06:38:45.226+0000 [id=1]    INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@481e91b6{Jenkins v2.374,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2022-10-23 06:38:45.248+0000 [id=1]    INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@5e8ac0e1{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-10-23 06:38:45.264+0000 [id=1]    INFO    org.eclipse.jetty.server.Server#doStart: Started Server@765f05af{STARTING}[10.0.12,sto=0] @5602ms
2022-10-23 06:38:45.272+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2022-10-23 06:38:45.618+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2022-10-23 06:38:45.644+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2022-10-23 06:38:46.889+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2022-10-23 06:38:46.895+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2022-10-23 06:38:46.929+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2022-10-23 06:38:47.251+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2022-10-23 06:38:47.256+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2022-10-23 06:38:47.257+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2022-10-23 06:38:47.260+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2022-10-23 06:38:47.317+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2022-10-23 06:38:47.359+0000 [id=42]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2022-10-23 06:38:48.708+0000 [id=28]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

58379546795f405eb891ea87a42b0421

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2022-10-23 06:39:40.483+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2022-10-23 06:39:40.516+0000 [id=22]    INFO    hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2022-10-23 06:39:41.743+0000 [id=42]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2022-10-23 06:39:41.744+0000 [id=42]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2022-10-23 06:39:41.753+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 54,426 ms
2022-10-23 06:45:55.611+0000 [id=63]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2022-10-23 06:45:55.617+0000 [id=63]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 2 ms
root@easzlab-deploy:~/jiege-k8s/20220807/k8s-data-n70-20220807/yaml/magedu/jenkins# 

 admin  admin

 

posted @ 2022-10-23 14:51  cyh00001  阅读(162)  评论(0编辑  收藏  举报