Cloud Computing & MSA

EKS에 Jenkins 설치

냉장고를사다줘·2019년 11월 6일·조회 40,213

1. 개요

Helm Chart를 통해 Jenkins를 설치하는 방법을 알아보려고 한다.

Jenkins 마스터를 쿠버네티스 클러스터에 별도 네임스페이스에 배포하면, 네임스페이스를 통해 Jenkins 배포에 대한 할당량을 만들 수 있고 클러스터 내 다른 배포와 논리적 구분이 가능해진다.


2. 설치

$ helm install --name my-jenkins-release stable/jenkins
NAME:   my-jenkins-release
LAST DEPLOYED: Wed Nov  6 02:45:33 2019
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                      DATA  AGE
my-jenkins-release        5     1s
my-jenkins-release-tests  1     1s

==> v1/Deployment
NAME                READY  UP-TO-DATE  AVAILABLE  AGE
my-jenkins-release  0/1    1           0          1s

==> v1/PersistentVolumeClaim
NAME                STATUS   VOLUME  CAPACITY  ACCESS MODES  STORAGECLASS  AGE
my-jenkins-release  Pending  gp2     1s        Filesystem

==> v1/Pod(related)
NAME                                 READY  STATUS   RESTARTS  AGE
my-jenkins-release-767c845d4f-cjl97  0/1    Pending  0         1s

==> v1/Role
NAME                                AGE
my-jenkins-release-schedule-agents  1s

==> v1/RoleBinding
NAME                                AGE
my-jenkins-release-schedule-agents  1s

==> v1/Secret
NAME                TYPE    DATA  AGE
my-jenkins-release  Opaque  2     1s

==> v1/Service
NAME                      TYPE          CLUSTER-IP     EXTERNAL-IP  PORT(S)         AGE
my-jenkins-release        LoadBalancer  10.100.135.10      8080:30130/TCP  1s
my-jenkins-release-agent  ClusterIP     10.100.109.0          50000/TCP       1s

==> v1/ServiceAccount
NAME                SECRETS  AGE
my-jenkins-release  1        1s


NOTES:
1. Get your 'admin' user password by running:
  printf $(kubectl get secret --namespace default my-jenkins-release -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
2. Get the Jenkins URL to visit by running these commands in the same shell:
  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        You can watch the status of by running 'kubectl get svc --namespace default -w my-jenkins-release'
  export SERVICE_IP=$(kubectl get svc --namespace default my-jenkins-release --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
  echo http://$SERVICE_IP:8080/login

3. Login with the password from step 1 and the username: admin


For more information on running Jenkins on Kubernetes, visit:
https://cloud.google.com/solutions/jenkins-on-container-engine

3. 접속

kubectl get svc 로 Jenkins의 EXTERNAL-IP를 확인하여 접속한다. 단 포트는 8080이다.

admin 계정 패스워드 확인 방법은 다음과 같다.

$ printf $(kubectl get secret --namespace default my-jenkins-release -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo

4. Docker로 Jenkins 설치 (참고)

$ sudo docker pull jenkins
Using default tag: latest
latest: Pulling from library/jenkins
55cbf04beb70: Pull complete
1607093a898c: Pull complete
9a8ea045c926: Pull complete
d4eee24d4dac: Pull complete
c58988e753d7: Pull complete
794a04897db9: Pull complete
70fcfa476f73: Pull complete
0539c80a02be: Pull complete
54fefc6dcf80: Pull complete
911bc90e47a8: Pull complete
38430d93efed: Pull complete
7e46ccda148a: Pull complete
c0cbcb5ac747: Pull complete
35ade7a86a8e: Pull complete
aa433a6a56b1: Pull complete
841c1dd38d62: Pull complete
b865dcb08714: Pull complete
5a3779030005: Pull complete
12b47c68955c: Pull complete
1322ea3e7bfd: Pull complete
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:latest
$ sudo docker images
REPOSITORY                                                         TAG                 IMAGE ID            CREATED             SIZE
jenkins                                                            latest              cd14cecfdb3a        16 months ago       696MB

본인은 docker run -d -p 8080:8080 -v $HOME/jenkins/data:/var/jenkins_home:z -t jenkins/jenkins 를 통해 Jenkins를 실행했다. 알겠지만 홈 디렉토리 아래에 jenkins/data 디렉토리가 있어야 된다.

그리고 브라우저로 8080 접근하면 화면이 뜨는데, admin 패스워드는 다음과 같이 확인할 수 있다.

  • docker exec -it <도커ID> /bin/bash 를 통해 접속
  • cat /var/jenkins_home/secrets/initialAdminPassword 하여 패스워드 확인

5. 참고

5.1. 서비스

Jenkins는 두가지 서비스를 제공한다.

  • 8080 / NodePort : 외부 사용자가 Jenkins UI에 액세스할 수 있도록 한다. 그리고 HTTP 로드 밸런서에 의해 부하 분산이 가능하다.
  • 5000 / ClusterIP : 클러스터 내부에서 Jenkins 마스터와 통신 가능하다.
---
  kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-ui
    namespace: jenkins
  spec:
    type: NodePort
    selector:
      app: master
    ports:
      - protocol: TCP
        port: 8080
        targetPort: 8080
        name: ui
---
  kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-discovery
    namespace: jenkins
  spec:
    selector:
      app: master
    ports:
      - protocol: TCP
        port: 50000
        targetPort: 50000
        name: slaves

5.2. Jenkins 배포 

Jenkins 마스터가 복제본 1개로 배포된 경우 클러스터에 단일 Jenkins 마스터가 실행된다.그리고 Jenkins 마스터 Pod가 종료되거나 실행중인 노드가 종료되면 쿠버네티스는 다른 곳에서 Pod를 다시 시작한다.

댓글 0

로그인 후 댓글을 남길 수 있습니다.

아직 댓글이 없습니다.