들어가며

현재 제가 운영하는 EKS 환경 구성도입니다. 구성도에서 보셔야 할 부분은 Jenkins 서버, Lambda, ECR 정도가 되겠습니다.

Jenkins 서버가 Private 서브넷에 위치해 있고 Codecommit과 Jenkins 서버의 연동을 담당하는 Lambda 서비스도 주의깊게 봐주시면 좋겠습니다.


Quasar 인프라 구성도 
설명 
보안셜정 
• Bastion* 통한 시비 관리 
Bastion 서버에서 EKS Cluster 관리 
• SG 실정하여 베스편 0仆ce이서만 
웹사이트 접근 가능 
Lambda 구성 
• Lambda /Jenkins 시비 통신 필요 
• Private Subnet에 구성 
AWS 
FKS Gr며鬱 
12월 
(텀)

Jenkins?

Jenkins는 소프트웨어 개발 시 지속적으로 통합 서비스를 제공하는 CI (Continuous Integraion) 툴입니다.

개발자들이 가장 많이 사용하는 오픈소스이며, 무수히 많은 자동화 기능을 가지고 있지만 이번에는 정말 간단한 Build 정도만 

함께 알아보도록 하겠습니다.

자세한 내용은 아래를 참고 부탁드립니다.

 

[1] https://www.jenkins.io/doc/book/

 

Jenkins 서버 구성하기

 

Jenkins 서버는 EC2 구성하였습니다스펙은 아래와 같습니다.

  • OS: Amazon Linux 2
  • Type: t3.medium
  • EBS Size : 20 GiB

 

Jenkins 서버를 EC2 위에 올리기 위해서는 Type이 최소 t3.small 스펙을 가지고 있어야 합니다. 저는 넉넉하게 t3.medium으로 구성하였습니다. 또, Jenkins 서버에서 ECR을 접근하기 위해서 ECRFullAccess IAM 권한 부여도 필요합니다. 이는 뒷부분에서 다시 다루도록 하겠습니다.

 

Jenkins 설치

 

#!/bin/bash 

os_type=$(cat /etc/*-release | uniq | head -1

if [ "${os_type}" == "NAME=\"Amazon Linux\"" ];

then sudo amazon-linux-extras install -y epel

else

check_jdk=$(rpm -qa | grep jdk | head -1)

if [ -n "$check_jdk" ];

then sudo yum remove -y $check_jdk

fi

fi

 

check_expect=$(rpm -qa | grep expect)

if [ -z "$check_expect" ];

then sudo yum install -y expect

fi

 

id=jenkins

pw=jenkins1!

 

sudo userdel $id

sudo adduser $id

expect << EOF

spawn sudo passwd $id

 

expect "New password:" 

send "$pw\r";

 

expect "Retype new password:" 

send "$pw\r";

 

expect eof

EOF

 

num=$(sudo grep -n "## Allow root" /etc/sudoers | cut -d: -f1 | head -1)

num=$((num+1))

data=$(sudo cat /etc/sudoers | sed -n ${num}p)

data2=$(echo ${data} | sed -e "s/root.*/${id}\tALL=(ALL)\tNOPASSWD: ALL/g") sudo sed -i "${num}s/${data}/${data}\n${data2}/g" /etc/sudoers sudo sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config

sudo service sshd restart

 

sudo rm /etc/localtime

sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

date

 

sudo yum install -y python3

sudo python3 -m pip install --upgrade pip

sudo python3 -m pip install awscli

sudo yum install -y git

sudo yum install -y java-1.8.0-openjdk-devel.x86_64 rpm -qa java*jdk-devel

javac -version

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo

sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key

sudo yum install -y jenkins

sudo chkconfig jenkins on

sudo service jenkins start

sudo systemctl enable jenkins

 

위의 스크립트를 생성하여 설치 해 줍니다. 아래 명령어로 초기 비밀번호 값을 기억해 두시기 바랍니다.

 

$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

 

Jenkins 접속하기

 

설치한 Jenkins 서버는 Private 서브넷에 위치해서 곧바로 웹 페이지를 붙을 수는 없습니다.

ALB를 붙이면 외부에서 접근이 가능하나, 저는 조금의 돈이라도 아끼기 위해 Bastion 서버를 터널링 하여 Jenkins 페이지를 접속합니다.

 

이 부분은 선택사항이나, 저 같은 경우에는 Jenkins 페이지에 자주 들어가지 않기에 아래와 같이 터널링합니다.

 

$ ssh -i "keypair.pem" -L 8080:[jenkins-server-ip]:8080 ec2-user@[bastion-server-public-ip]

 

Jenkins 추가 설정

 

Getting Started 
Unlock Jenkins 
To ensure Jenkins is securely set up by the administrator, a password has been written to 
the log (not sure where to find it?) and this file on the server: 
/var/1ib/jenkins/secrets/initia1AdminPassword 
Please copy the password from either location and paste it below. 
Administrator password 
Continue

 

초기 password 를 넣어 접속한 뒤 Install suggested plugins 를 선택 해 default plugin 을 설치 해 줍니다.

 

Getting Started 
Getting Started 
Folders 
Timestamper 
Pipeline 
Git 
LDAP 
Jenkins 2.298 
OWASP Markup 
Formatter 
Workspace Cleanup 
GitHub Branch Source 
SSH Build Agents 
Email Extension 
Build Timeout 
Ant 
Pipeline: GitHub Groovy 
Libraries 
Matrix Authorization 
Strategy 
Mailer 
Credentials Binding 
Gradle 
Pipeline: Stage View 
PAM Authentication 
OWASP Markup Formatter 
Token Macro 
SSH Credent ials 
Credentials Binding 
Timestamoer 
Script Security 
Font Awesome API 
Bootstrap 4 API 
Snakeyaml API 
Jackson 2 API 
Bootstrap 5 API 
reaui red dependency

 

 

Getting Started 
Create First Admin User 
sanghyeon.park 
Jenkins 2.298 
Skip and continue as admin 
Save and Continue

계정명과 암호 이름 이메일 주소를 기입한 후에 url 까지 생성한 뒤에 접속합니다.

참고로 계정은 영어만 가능하며 대쉬 혹은 언더바만 사용 가능합니다.


Jenkins 
Dashboard 
Item 
Jenkins 
My Views 
Lockable Resources 
New View 
CH71 
O 
JenkinsOil ..2*1 742 ch. 
This page is where your Jenkins jobs will be displayed. To get started, you can set up distributed 
builds or start building a software project. 
Start building your software project 
Create a job 
Set up a distributed build 
Set up an agent 
Configure a cloud 
Learn more about distributed builds 
LHS 
2

 

이제 Jenkins 구성을 완료했으니 Jenkins에 연동할 서비스들을 다음 내용에서 하나하나 씩 알아보겠습니다.

 

감사합니다.