dockerfile 创建jenkins
下载链接 :Docker Hub
jenkins_for_Centos版本
##这里用的是jenkinsforCentos版本
[root@hy-202 ~]# docker pull jenkins/jenkins:2.316-centos7
##push 到本地仓库
[root@hy-202 ~]# docker tag 55b7502f8749 harbor.hy.com/infra/jenkins:2.316-centos7
[root@hy-202 ~]# docker push harbor.hy.com/infra/jenkins:2.316-centos7
push 到本地仓库
##push 到本地仓库
[root@hy-202 ~]# docker tag 55b7502f8749 harbor.hy.com/infra/jenkins:2.316-centos7
[root@hy-202 ~]# docker push harbor.hy.com/infra/jenkins:2.316-centos7
set dockerfile文件
##创建目录
/data/k8s_data/dockerfile/jenkins
##下载get-docker.sh
[root@hy-205 jenkins]# curl -fsSL get.docker.com -o get-docker.sh
[root@hy-205 jenkins]# chmod a+x get-docker.sh
##dockerfile 文件如下
[root@hy-205 jenkins]# cat Dockerfile
FROM harbor.hy.com/infra/jenkins:2.316-centos7
USER root
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
echo 'Asia/Shanghai' >/etc/timezone
ADD id_rsa /root/.ssh/id_rsa
ADD config.json /root/.docker/config.json
ADD get-docker.sh /get-docker.sh
RUN echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\
/get-docker.sh
##执行dockerfile
[root@hy-205 jenkins]# docker build . -t harbor.hy.com/infra/jenkins:2.316-centos7-latest
执行docker build
##执行dockerfile
[root@hy-205 jenkins]# docker build . -t harbor.hy.com/infra/jenkins:2.316-centos7-latest
##执行成功
Removing intermediate container 6b1edc33acd6
---> 17a76f4f8404
Successfully built 17a76f4f8404
Successfully tagged harbor.hy.com/infra/jenkins:2.316-centos7-latest
测试docker ssh 到代码仓库
##测试是否可以链接git@gitee.com
[root@hy-205 jenkins]# docker run --rm harbor.hy.com/infra/jenkins:2.316-centos7-latest ssh -T git@gitee.com
Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
Hi 左丿仔! You've successfully authenticated, but GITEE.COM does not provide shell access.
dockerfile后的push 到本地仓库
[root@hy-205 jenkins]# docker push harbor.hy.com/infra/jenkins:2.316-centos7-latest
测试 kubernetes 上测试
deployment.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: infra
labels:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
name: jenkins
template:
metadata:
labels:
app: jenkins
name: jenkins
spec:
volumes:
- name: data
nfs:
server: hy-205.host.com
path: /data/k8s_data/jenkins-volumes/jenkins_home
- name: docker
hostPath:
path: /run/docker.sock
type: ''
containers:
- name: jenkins
# image:
image: harbor.hy.com/infra/jenkins:2.316-centos7-latest
ports:
- containerPort: 8080
protocol: TCP
env:
- name: JAVA_OPTS
value: -Xmx512m -Xms512m
resources:
limits:
cpu: 2048m
memory: 4Gi
requests:
cpu: 2048m
memory: 4Gi
volumeMounts:
- name: data
mountPath: /var/jenkins_home
- name: docker
mountPath: /run/docker.sock
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
service.yaml
service.yaml
kind: Service
apiVersion: v1
metadata:
name: jenkins
namespace: infra
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
selector:
app: jenkins
ingress.yaml
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: infra
spec:
rules:
- host: jenkins.hy.com
http:
paths:
- path: /
backend:
serviceName: jenkins
servicePort: 80
执行
[root@hy-201 ~]# kubectl apply -f http://k8s.hy.com/kubernetes/yaml/jenkins/service.yaml
service/jenkins created
[root@hy-201 ~]# kubectl apply -f http://k8s.hy.com/kubernetes/yaml/jenkins/ingress.yaml
ingress.extensions/jenkins created
[root@hy-201 ~]# kubectl apply -f http://k8s.hy.com/kubernetes/yaml/jenkins/deployment.yaml
查看logs
[root@hy-201 ~]# kubectl logs -f jenkins-799776766d-qsl8d -n infra
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-18 08:36:27.273+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @2101ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-10-18 08:36:27.627+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2021-10-18 08:36:38.710+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-10-18 08:36:38.823+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.12+7
2021-10-18 08:36:39.271+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-10-18 08:36:39.339+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-10-18 08:36:39.339+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-10-18 08:36:39.340+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-10-18 08:36:40.050+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-18 08:36:40.367+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@59901c4d{Jenkins v2.316,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-10-18 08:36:40.420+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@5af3a0f{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-10-18 08:36:40.421+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @15254ms
2021-10-18 08:36:40.424+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-10-18 08:36:40.782+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-10-18 08:36:40.855+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/var/jenkins_home/war/WEB-INF/lib/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
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
2021-10-18 08:36:42.789+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-10-18 08:36:42.796+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-10-18 08:36:42.825+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-10-18 08:36:43.660+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-10-18 08:36:43.661+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-10-18 08:36:43.661+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-10-18 08:36:43.662+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-10-18 08:36:43.689+0000 [id=46] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-10-18 08:36:43.736+0000 [id=46] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-10-18 08:36:45.126+0000 [id=33] 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:
f0d26899065448de99cee611b6222da4
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
web登录查看
jenkins.hy.com
替换成国内的源
##在目录中找到 default.json文件进行低缓
[root@hy-205 updates]# pwd
/data/k8s_data/jenkins-volumes/jenkins_home/updates
##替换成国内的信息
[root@hy-205 updates]# sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
[root@hy-205 updates]# sed -i 's/http:\/\/updates.jenkis-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
[root@hy-205 updates]# pwd
/data/k8s_data/jenkins-volumes/jenkins_home/updates
[root@hy-205 updates]#
##在plugmanager/advanced/最下面替换掉
https://updates.jenkins.io/update-center.json
##更新为清华源
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json