EKS CI/CD 구성 프로젝트_2

duckiee·2023년 3월 21일
0
post-thumbnail

이번 포스트는 Jenkins를 EKS에 배포하는 작업을 포스팅 합니다.

Jenkins pod에서 사용할 데이터가 지속적으로 보관하기 위해 EBS PV를 동적프로비저닝 하기로 한다.

1. PVC, StorageClass 준비하기

Jenkins 데이터를 EBS에 저장하기 위해 PV가 필요하다
메니패스트 파일을 사용하여 PVC, StorageClass를 구성하고, Jenkins 서비스에 적용할 ServiceAccount를 생성하기로 한다.

서비스 구성에 필요한 매니패스트는 아래 깃허브 레포지토리에서 확인 가능하다.
깃허브 링크 : https://github.com/Duckie1/mini-project/tree/main/management/ci/jenkins/settings

jenkins 환경은 별도의 네임스페이스를 지정해서 구축할 예정이다.
jenkins에 필요한 Ingress, Service, Pod 등은 helm 차트를 통해 구축하기로 한다.
우선 아래와 같이 jenkins 네임 스페이스와 PV 환경을 매니페스트로 생성했다.

#jenkins 네임스페이스에서 jenkins 서비스 구축
$ kubectl create ns jenkins

#ServiceAccount jenins 생성
kubectl apply -f sa.yaml -n jenkins

#StorageClass gp2 생성
$ kubectl apply -f sc.yaml -n jenkins

#PVC jenkins-pvc 생성
$ kubectl apply -f pvc.yaml -n jenkins
  • sa.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
  namespace: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: jenkins
rules:
- apiGroups:
  - '*'
  resources:
  - statefulsets
  - services
  - replicationcontrollers
  - replicasets
  - podtemplates
  - podsecuritypolicies
  - pods
  - pods/log
  - pods/exec
  - podpreset
  - poddisruptionbudget
  - persistentvolumes
  - persistentvolumeclaims
  - jobs
  - endpoints
  - deployments
  - deployments/scale
  - daemonsets
  - cronjobs
  - configmaps
  - namespaces
  - events
  - secrets
  verbs:
  - create
  - get
  - watch
  - delete
  - list
  - patch
  - update
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
  - list
  - watch
  - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: jenkins
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: jenkins
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:serviceaccounts:jenkins
  • sc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: gp2
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  fsType: ext4 
  • pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-pvc
  namespace: jenkins
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gp2
  resources:
    requests:
      storage: 20Gi
  • 결과 화면

2. Helm 차트 사용하여 Jenkins 설치

jenkinsci 레포지토리를 추가하여 jenkins 패키지를 설치한다.
패키지 설치 시 values.yaml 파일을 사용하며, 예제 파일은 아래 깃허브에서 확인 가능하다.
values.yaml 파일 경로

values.yaml 내용 중에서 확인 해야할 부분은 아래와 같다.

  • ingress 관련 내용

  • persistence 관련 내용

#Jenkins Helm Repo 등록
$ helm repo add jenkinsci https://charts.jenkins.io

#Helm Repo내에서Jenkins Helm Chart검색(존재확인)
$ helm search repo jenkinsci

#Jenkins Helm Chart 배포
$ helm install jenkins -n jenkins -f values.yaml jenkinsci/jenkins

Helm 설치 후 jenkins 서비스가 아래와 같이 배포된 것을 확인할 수 있다.

  • jenkins 접속화면

jenkins 설정 중 설치한 플러그인은 아래와 같다.

Docker Commons
Amazon Web Services SDK
Amazon Web Services SDK
CloudBees AWS Credentials
GitHub API
GitHub
GitHub Integration
Kubernetes CLI
SSH
GitHub Branch Source
SSH Build Agents
Docker API
Docker
Amazon Web Services SDK
Amazon ECR
Git
Pipeline: GitHub Groovy Libraries
Docker Pipeline
Javadoc
Maven Integration
docker-build-step
Docker API
Build Pipeline
Pipeline Utility Steps
AWS Global Configuration
Pipeline: GitHub
SSH Agent
Delivery Pipeline
GitHub Organization Folder
GitHub Authentication
Kubernetes Credentials Provider
SSH Build Agents
CloudBees Docker Build and Publish
Docker Slaves
Publish Over SSH Pending
Kubernetes :: Pipeline :: DevOps Steps
SSH Pipeline Steps
Amazon Web Services SDK :: SQS
Amazon Web Services SDK :: SNS
Amazon Web Services SDK :: CloudFormation
Amazon Web Services SDK :: Elastic Beanstalk
Amazon Web Services SDK :: ECS
Amazon Web Services SDK :: IAM
Amazon Web Services SDK :: EFS
Amazon Web Services SDK :: SSM
Amazon Web Services SDK :: Logs
Amazon Web Services SDK :: CodeBuild
Amazon Web Services SDK :: All

profile
DevOps로 진화하기

0개의 댓글