Jenkins란?
젠킨스는 오픈소스 지속적 통합(CI) 및 지속적 배포(CD). 도구로, 소프트웨어 개발 프로세스의 빌드, 테스트, 배포 등을 자동화하고 관리할 수 있다. 젠킨스는 다양한 플러그인과 함께 여러 언어와 프레임워크를 지원한다.
설치환경
젠킨스 설치환경 OS: Centos 7.9
Jenkins 설치하기
Kubernetes에서 Jenkins 클러스터를 설정하기 위해 대략적인 개요는 아래와 같다.
- namespace 생성
- Kubernetes 관리자 권한으로 서비스 계정 생성
- Pod가 다시 시작될 때 영구 Jenkins 데이터를 위한 로컬 영구 볼륨을 생성
- 배포 yaml을 생성하고 배포
- 서비스 yaml을 생성하고 배포
Jenkins Kubernetes 매니페스트 파일
인터넷이 되는 환경의 경우 아래의 명령어를 통해 다운받을 수 있다.
$ git clone https://github.com/scriptcamp/kubernetes-jenkins
git 명령을 찾을 수 없습니다. 시 (Centos)
→ git을 설치해준다.
yum install git
깃허브에서 해당 매니페스트 파일을 받아보면 아래와 같이 구성되어 있다.
각 쿠버 구성요소에 대한 yaml 파일 확인 가능

Kubernetes Jenkins 배포
1. namespace 생성
$ kubectl create namespace jenkins

2. serviceAccount.yaml 파일
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: jenkins-admin
rules:
- apiGroups: [""]
resources: ["*"]
verbs: ["*"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins-admin
namespace: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: jenkins-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: jenkins-admin
subjects:
- kind: ServiceAccount
name: jenkins-admin
namespace: jenkins
- namespace 부분은 생성한 네임스페이스에 맞게 수정해준다.
- 'serviceAccount.yaml'은 'jenkins-admin' ClusterRole, 'jenkins-admin' ServiceAccount를 생성하고 'clusterRole'을 서비스 계정에 바인딩합니다.
- 'jenkins-admin' 클러스터 역할에는 클러스터 구성 요소를 관리할 수 있는 모든 권한이 있습니다. 개별 리소스 작업을 지정하여 액세스를 제한할 수도 있습니다.
$ kubectl apply -f serviceAccount.yaml
3. ‘volume.yaml’을 생성하고 다음 영구 볼륨 매니페스트를 복사
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv-volume
labels:
type: local
spec:
storageClassName: local-storage
claimRef:
name: jenkins-pv-claim
namespace: jenkins
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
local:
path: /mnt
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- k8s-node1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pv-claim
namespace: jenkins
spec:
storageClassName: local-storage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- 볼드로 강조한
k8s-node1
부분은 설치하고자 하는 노드의 호스트명을 넣어줘야한다.
- 마찬가지로 namespace 부분의
jenkins
도 각자 만든 namespace에 맞게 설정
볼륨의 경우 데모 목적으로 '로컬' 스토리지 클래스를 사용합니다. 즉, '/mnt' 위치 아래의 특정 노드에 'PerciousVolume' 볼륨을 생성합니다.
'로컬' 스토리지 클래스에는 노드 선택기가 필요하므로 Jenkins Pod가 특정 노드에서 예약되도록 하려면 작업자 노드 이름을 올바르게 지정해야 합니다.
포드가 삭제되거나 다시 시작되면 데이터가 노드 볼륨에 유지됩니다. 그러나 노드가 삭제되면 모든 데이터가 손실됩니다.
이상적으로는 클라우드 제공업체에서 사용 가능한 스토리지 클래스를 사용하거나 클러스터 관리자가 노드 장애 시 데이터를 유지하기 위해 제공한 스토리지 클래스를 사용하는 영구 볼륨을 사용해야 합니다.
이후 볼륨 생성
$ kubectl create -f volume.yaml
4. ‘deployment.yaml’ 배포
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-server
template:
metadata:
labels:
app: jenkins-server
spec:
securityContext:
fsGroup: 1000
runAsUser: 1000
serviceAccountName: jenkins-admin
containers:
- name: jenkins
image: jenkins/jenkins:lts
resources:
limits:
memory: "2Gi"
cpu: "1000m"
requests:
memory: "500Mi"
cpu: "500m"
ports:
- name: httpport
containerPort: 8080
- name: jnlpport
containerPort: 50000
livenessProbe:
httpGet:
path: "/login"
port: 8080
initialDelaySeconds: 90
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: "/login"
port: 8080
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- name: jenkins-data
mountPath: /var/jenkins_home
volumes:
- name: jenkins-data
persistentVolumeClaim:
claimName: jenkins-pv-claim
5. 통신을 위한 Service 설정
apiVersion: v1
kind: Service
metadata:
name: jenkins-service
namespace: jenkins
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: /
prometheus.io/port: '8080'
spec:
selector:
app: jenkins-server
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 32000
NodePort를 통해 32000번으로 예시를 들었습니다.
아래 명령어를 입력하여 service를 생성해줍니다.
http://<<node-ip>:32000 으로 접속할 수 있습니다.
Web 접속 확인
http://<<node-ip>:32000
아래처럼 jenkins 페이지가 확인됩니다.

추후 설정은 다른 게시물로 작성하겠습니다.
Share article