安装

docker

1
2
3
4
docker container run -p 18080:8080 -p 50000:50000 --name jenkins111 -d jenkins/jenkins:2.164.2-alpine
docker container exec -it jenkins111 /bin/bash
docker container stop jenkins111
docker container rm jenkins111
1
2
3
4
5
6
7
mkdir data
cat > data/log.properties <<EOF
handlers=java.util.logging.ConsoleHandler
jenkins.level=FINEST
java.util.logging.ConsoleHandler.level=FINEST
EOF
docker run --name jenkins667 -p 18080:8080 -p 50000:50000 --env JAVA_OPTS="-Djava.util.logging.config.file=/var/jenkins_home/log.properties" -v `pwd`/data:/var/jenkins_home jenkins/jenkins:lts

k8s

 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
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  namespace: default
  labels:
    k8s-app: jenkins
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: jenkins
        k8s-app: jenkins
    spec:
      #securityContext:
      #  fsGroup: 1000
      #  runAsNonRoot: true        
      containers:
      - name: jenkins
        image: jenkins/jenkins:2.176.1-alpine
        ports:
          - containerPort: 8080
          - containerPort: 50000
        #securityContext:
        #  allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: default
  labels:
    k8s-app: jenkins
    kubernetes.io/cluster-service: "true"
spec:
  type: NodePort
  selector:
   k8s-app: jenkins
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30015

登录

1
2
3
# 获取admin默认密码
# cat /var/jenkins_home/secrets/initialAdminPassword
kubectl exec -it $(kubectl get pod -l k8s-app=jenkins -o jsonpath={.items[0].metadata.name}) -- /bin/sh -c "cat /var/jenkins_home/secrets/initialAdminPassword"

参考