k8s部署jenkins
//
docker-hub镜像地址 (opens new window)
# 优化Jenkins基础镜像
- 拉取镜像,准备配置文件
docker pull jenkins/jenkins:2.325 #拉起github docker镜像
curl -fsSL get.docker.com -o get-docker.sh
cp /root/.ssh/id_rsa /root/.docker/config.json ./ #看个人需求
1
2
3
2
3
- 创建dockerfile
FROM jenkins/jenkins:2.325
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 " StricHostKeyChecking no" >> /etc/ssh/ssh_config && \
/get-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- 构建镜像(网络会比较慢,可能失败)
docker build -t harbor.yfklife.cn/devops/jenkins:v2.325 .
docker push harbor.yfklife.cn/devops/jenkins:v2.325
1
2
2
# k8s部署jenkins.yml
- 使用默认的nfs存储挂载
#每个计算节点都安装nfs,因为是使用的deployment
yum install -y nfs-utils rpcbind
#创建数据存储目录
mkdir -p /data/k8s_share/jenkins
#nfs配置
[root@hdss14-200 jenkins]# cat /etc/exports
/data/k8s_share/jenkins 192.168.14.0/24(rw,no_root_squash)
#启动,先启动rpcbind再启动nfs
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind nfs
systemctl status rpcbind nfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 创建拉取docker私有仓库密钥
kubectl create secret docker-registry harbor --docker-server=harbor.yfklife.cn --docker-username=admin --docker-password=yfk123456 -n devops
- 配置Service
mkdir /opt/application/jenkins && cd /opt/application/jenkins
vi service-jenkins.yml
apiVersion: v1
kind: Service
metadata:
name: jenkins
namespace: devops
labels:
app: jenkins
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
spec:
selector:
app: jenkins
ports:
- name: jenkins
port: 80
targetPort: 8080
- name: jenkins-agent
port: 50000
targetPort: 50000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- 配置Deployment
vi deployment.yml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: devops
labels:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
name: jenkins
template:
metadata:
labels:
app: jenkins
name: jenkins
spec:
volumes:
- name: data
nfs:
server: hdss14-200 #短域名,nfs地址
path: /data/k8s_share/jenkins
- name: docker
hostPath:
path: /run/docker.sock
type: ''
containers:
- name: jenkins
image: harbor.yfklife.cn/devops/jenkins:v2.325
#image: harbor.yfklife.cn/devops/jenkins:v2.190.3
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
protocol: TCP
ports:
- containerPort: 50000
protocol: TCP
env:
- name: JAVA_OPTS
value: -Xmx512m -Xms512m
volumeMounts:
- name: data
mountPath: /var/jenkins_home
- name: docker
mountPath: /run/docker.sock
imagePullSecrets:
- name: harbor #私有仓库密钥
securityContext:
runAsUser: 0
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 300
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 配置ingress
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: jenkins
namespace: devops
spec:
entryPoints:
- web
routes:
- match: Host(`jenkins.yfklife.cn`)
kind: Rule
services:
- kind: Service
name: jenkins
port: 80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 创建服务,配置域名解析,访问:
http://jenkins.yfklife.cn
kubectl apply -f deployment.yaml
kubectl apply -f ingress.yaml
kubectl apply -f service.yaml
1
2
3
2
3
# 关于Jenkins更多文章
# 个人存储下载地址。。。
get-docker.sh
1
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2023/11/20, 16:23:11