BlueXIII's Blog

热爱技术,持续学习

0%

JenkinsOnK8S配置

节点亲和性

1
2
kubectl get nodes --show-labels
kubectl label nodes worker-s001 node-role.kubernetes.io/worker=ci

构建所需基础镜像

1
2
3
busybox:1.36.0
java:8u111-jre-alpine
openjdk:8-jre-slim-buster

自定义容器

  1. 编辑kubesphere-devops-system命名空间下的名为jenkins-casc-config的configmap,
  2. 重启名为devops-jenkins-xxx的deployment
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    - name: "dubhe"
    namespace: "kubesphere-devops-worker"
    label: "dubhe"
    nodeUsageMode: "EXCLUSIVE"
    idleMinutes: 0
    containers:
    - name: "maven"
    image: "kubesphere/builder-maven:v3.2.0-podman"
    command: "cat"
    args: ""
    ttyEnabled: true
    privileged: true
    resourceRequestCpu: "100m"
    resourceLimitCpu: "4000m"
    resourceRequestMemory: "100Mi"
    resourceLimitMemory: "8192Mi"
    - name: "nodejs"
    image: "kubesphere/builder-nodejs:v3.2.0-podman"
    command: "cat"
    args: ""
    ttyEnabled: true
    privileged: true
    resourceRequestCpu: "100m"
    resourceLimitCpu: "4000m"
    resourceRequestMemory: "100Mi"
    resourceLimitMemory: "8192Mi"
    - name: "jnlp"
    image: "jenkins/inbound-agent:4.10-2"
    args: "^${computer.jnlpmac} ^${computer.name}"
    resourceRequestCpu: "50m"
    resourceLimitCpu: "500m"
    resourceRequestMemory: "400Mi"
    resourceLimitMemory: "1536Mi"
    workspaceVolume:
    emptyDirWorkspaceVolume:
    memory: false
    volumes:
    - hostPathVolume:
    hostPath: "/run/k3s/containerd/containerd.sock"
    mountPath: "/run/containerd/containerd.sock"
    - hostPathVolume:
    hostPath: "/var/data/jenkins_maven_cache"
    mountPath: "/root/.m2"
    - hostPathVolume:
    hostPath: "/var/data/jenkins_sonar_cache"
    mountPath: "/root/.sonar/cache"
    - hostPathVolume:
    hostPath: "/var/data/jenkins_nodejs_yarn_cache"
    mountPath: "/root/.yarn"
    - hostPathVolume:
    hostPath: "/var/data/jenkins_nodejs_npm_cache"
    mountPath: "/root/.npm"
    yaml: |
    spec:
    hostAliases:
    - ip: "10.193.35.21"
    hostnames:
    - "harbor.dubhe"
    affinity:
    nodeAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 1
    preference:
    matchExpressions:
    - key: node-role.kubernetes.io/worker
    operator: In
    values:
    - ci
    tolerations:
    - key: "node.kubernetes.io/ci"
    operator: "Exists"
    effect: "NoSchedule"
    - key: "node.kubernetes.io/ci"
    operator: "Exists"
    effect: "PreferNoSchedule"
    containers:
    - name: "maven"
    resources:
    requests:
    ephemeral-storage: "1Gi"
    limits:
    ephemeral-storage: "10Gi"
    volumeMounts:
    - name: config-volume
    mountPath: /opt/apache-maven-3.5.3/conf/settings.xml
    subPath: settings.xml
    - name: "nodejs"
    resources:
    requests:
    ephemeral-storage: "1Gi"
    limits:
    ephemeral-storage: "10Gi"
    volumes:
    - name: config-volume
    configMap:
    name: ks-devops-agent
    items:
    - key: MavenSetting
    path: settings.xml
    securityContext:
    fsGroup: 1000

自定义maven settings.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jitpack.io,!elasticsearch-releases,!dtstack-github,!nexus-public,!elastic.co</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>